Metadata-Version: 2.1
Name: lut-estimator
Version: 0.1.0
Summary: Estimate a 3D LUT from before/after image pairs and apply it to target images.
Author: haruk
License: MIT License
        
        Copyright (c) 2025 kinkin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy >=1.24
Requires-Dist: opencv-python >=4.8
Requires-Dist: scipy >=1.10
Provides-Extra: dev
Requires-Dist: pytest >=8.0 ; extra == 'dev'
Requires-Dist: pre-commit >=3.7 ; extra == 'dev'

# LUT Estimator

![License](https://img.shields.io/badge/license-MIT-green.svg)
![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)

Estimate a 3D LUT from a pair of images and apply that look to another image. The project is packaged as a small Python library with a CLI, so it is easier to reuse in scripts, experiments, and OSS workflows.

Japanese documentation is available in `README.ja.md`.

Example images are included in the repository under `img/` and in the generated sample output files.

## Features

- Estimates a 3D LUT from before/after image pairs using a two-stage interpolation strategy.
- Applies LUTs with trilinear interpolation to reduce banding artifacts.
- Supports optional Gaussian blur before estimation to stabilize noisy inputs.
- Exports the estimated LUT as a standard `.cube` file.
- Provides both a Python API and a command-line interface.

## Installation

Clone the repository and install it in editable mode:

```bash
python -m pip install -e .[dev]
```

If you only need runtime dependencies:

```bash
python -m pip install -e .
```

## Quick Start

Run the CLI with a before/after pair and a target image:

```bash
lut-estimator \
  --before img/base.JPG \
  --after img/apply_lut.JPG \
  --target img/base.JPG \
  --output estimated_result.jpg \
  --lut-size 33 \
  --sample-rate 0.02 \
  --blur-ksize 0
```

This writes:

- The transformed image to `estimated_result.jpg`
- A companion LUT file to `estimated_result.cube` unless `--no-cube` is passed

You can also keep using the legacy script entrypoint:

```bash
python lut_tool.py --before img/base.JPG --after img/apply_lut.JPG --target img/base.JPG
```

## Python API

```python
from lut_estimator import estimate_and_apply_lut

estimate_and_apply_lut(
    before_image_path="img/base.JPG",
    after_image_path="img/apply_lut.JPG",
    target_image_path="img/base.JPG",
    output_image_path="estimated_result.jpg",
    lut_size=33,
    sample_rate=0.02,
    blur_ksize=0,
    save_cube=True,
    seed=42,
)
```

## Parameters

- `lut_size`: LUT grid resolution. Larger values are more accurate but slower.
- `sample_rate`: Fraction of pixels used for LUT estimation.
- `blur_ksize`: Odd Gaussian kernel size used before estimation. Set `0` to disable blur.
- `seed`: Optional random seed for reproducible sampling.

## Development

Run tests with:

```bash
pytest
```

Install hooks for local formatting and basic checks:

```bash
pre-commit install
```

## Project Structure

```text
src/lut_estimator/
  core.py      Core LUT estimation and application logic
  cli.py       Command-line interface
tests/
  test_core.py Minimal regression tests
lut_tool.py    Backward-compatible entrypoint
```

## Notes

- Input images are expected to be aligned before/after pairs.
- If the before/after images have different sizes, both are resized to the smaller common resolution for estimation.
- The current estimator assumes an RGB-to-RGB global color transform rather than localized edits.

## License

Released under the MIT License.

## Community

- Contribution guide: [CONTRIBUTING.md](CONTRIBUTING.md)
- Code of conduct: [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
- Release notes: [CHANGELOG.md](CHANGELOG.md)

## Publishing

Build distributions:

```bash
python -m build
```

Validate package metadata:

```bash
python -m twine check dist/*
```
