Metadata-Version: 2.5
Name: ColorCorrectionPipeline
Version: 3.1.0
Summary: A step-wise, color correction pipeline for digital images combining flat-field correction, gamma correction, white-balance, and color-correction
Project-URL: Homepage, https://github.com/collinswakholi/ColorCorrectionPackage
Project-URL: Repository, https://github.com/collinswakholi/ColorCorrectionPackage
Project-URL: Bug Tracker, https://github.com/collinswakholi/ColorCorrectionPackage/issues
Project-URL: Documentation, https://github.com/collinswakholi/ColorCorrectionPackage
Author: Collins Wakholi, Devin A. Rippner
License: MIT for source code; bundled detector models declare AGPL-3.0. See included model notices.
License-File: ColorCorrectionPipeline/detection/models/LICENSE-AGPL-3.0.txt
License-File: ColorCorrectionPipeline/detection/models/UPSTREAM-NOTICE.md
License-File: LICENSE
Keywords: color-correction,computer-vision,flat-field,gamma-correction,image-processing,photography,scientific-imaging,white-balance
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
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: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Requires-Dist: colour-science>=0.4.0
Requires-Dist: matplotlib>=3.4.0
Requires-Dist: numba>=0.61; python_version >= '3.10' and ((sys_platform == 'win32' and (platform_machine == 'AMD64' or platform_machine == 'ARM64')) or (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or (sys_platform == 'darwin' and platform_machine == 'arm64'))
Requires-Dist: numpy>=1.21.0
Requires-Dist: onnxruntime-ep-webgpu>=0.4; python_version >= '3.11' and ((sys_platform == 'win32' and (platform_machine == 'AMD64' or platform_machine == 'ARM64')) or (sys_platform == 'linux' and (platform_machine == 'x86_64' or platform_machine == 'aarch64')) or (sys_platform == 'darwin' and platform_machine == 'arm64'))
Requires-Dist: onnxruntime>=1.16; python_version < '3.11'
Requires-Dist: onnxruntime>=1.31; python_version >= '3.11'
Requires-Dist: opencv-contrib-python>=4.5.0
Requires-Dist: pandas>=1.3.0
Requires-Dist: pillow>=9.2
Requires-Dist: scikit-learn>=1.0.0
Requires-Dist: scipy>=1.7.0
Requires-Dist: tifffile>=2021.11.2
Requires-Dist: torch>=1.10.0
Provides-Extra: dev
Requires-Dist: black>=23.0; extra == 'dev'
Requires-Dist: hypothesis>=6.0; extra == 'dev'
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx-rtd-theme>=1.0; extra == 'docs'
Requires-Dist: sphinx>=5.0; extra == 'docs'
Provides-Extra: performance
Requires-Dist: numba>=0.55.0; extra == 'performance'
Provides-Extra: tiff
Requires-Dist: imagecodecs>=2021.11.20; extra == 'tiff'
Description-Content-Type: text/markdown

# ColorCorrectionPipeline

Calibrate a camera setup from one photo of a color chart (a **ColorChecker Classic 24**,
**SpyderCHECKR 24** or **ColorChecker Digital SG**),
then apply that calibration to every image taken under the same conditions.

The pipeline corrects, in order: uneven lighting (**flat-field correction**,
from an optional photo of a white target), tone (**gamma**), color cast
(**white balance**), and remaining color error (**color correction**).

## Install

```shell
pip install ColorCorrectionPipeline
```

Python 3.8–3.14 on Windows, Linux and macOS. On Python 3.10+ for Windows, Linux
and Apple-silicon Macs this also installs Numba, which makes fitting and
correcting **10–20× faster** with identical results. On Python 3.8/3.9 or an
Intel Mac, add it with `pip install "ColorCorrectionPipeline[performance]"`.
To read compressed 16-bit TIFFs, add `[tiff]`. Chart detection uses a GPU when
one is available and falls back to the CPU on its own.

## Quick start

You need a photo of the chart and, optionally, a photo of a plain white target
taken with the same lighting and camera position.

```python
from ColorCorrectionPipeline import calibrate, correct

cal = calibrate("chart.jpg", white="white.jpg", save_to="calibration.ccpb")
print("Chart error after correction (mean Delta E00):", cal.delta_e)

image = correct("scene.jpg", cal)                 # RGB float array, values 0–1
image = correct("scene.jpg", "calibration.ccpb")  # later, from the saved file
```

- Leave out `white=` if you have no white photo; flat-field correction is then skipped.
- `calibrate` raises `CalibrationError` if a stage fails, for example when no chart is found.
- The `.ccpb` file is a portable calibration you can share and reload safely.

To save the result as an image file:

```python
from ColorCorrectionPipeline.io import write_image_data

write_image_data("scene_corrected.png", image, dtype="uint8", allow_precision_loss=True)
```

## Which chart?

The detector recognises three charts and picks the matching reference values for you:

| Chart | Patches | Status |
| --- | --- | --- |
| ColorChecker Classic 24 (and the Passport's Classic face) | 24 | Fully supported |
| SpyderCHECKR 24 | 24 | New: verified on synthetic charts, not yet on real photos |
| ColorChecker Digital SG | 140 | New: verified on synthetic charts, not yet on real photos |

`calibrate()` uses whichever chart is in the photo (a Classic wins if there are
several). To choose one, pass `chart_type="spyder"` or `"digital-sg"`.

If you measured your own chart, use its values instead of the built-in ones:

```python
from ColorCorrectionPipeline import Config, ReferenceProfile, calibrate

reference = ReferenceProfile.from_csv("my_chart.csv", chart="classic")  # Lab D50 by default
cal = calibrate("chart.jpg", white="white.jpg", config=Config(reference=reference))
```

Values can be Lab, XYZ or sRGB, under any standard white, in row- or column-major
order or labelled by cell. See [chart reference values](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/configuration.md#chart-reference-values).

## Correct many images

```python
from ColorCorrectionPipeline import ColorCorrection

pipeline = ColorCorrection().load_bundle("calibration.ccpb")
results = pipeline.predict_images(["a.jpg", "b.jpg", "c.jpg"], stages="final")
corrected = [r["CC"] for r in results]            # same order as the input
```

`stages="final"` returns only the finished image, which is faster than keeping
every intermediate stage. See [batch processing](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/batch-and-reporting.md)
for progress callbacks, worker counts and writing results to disk.

## Configure

The defaults suit most photographs. To change the color model, pass a preset name:

```python
cal = calibrate("chart.jpg", white="white.jpg", model="rpcc3")
```

| Preset | Use when |
| --- | --- |
| `rpcc2` (default) | General use. Robust to exposure changes. |
| `rpcc3` | A well-exposed chart and you want a closer fit. |
| `ccm` (or `3x3`) | You want a simple 3×3 matrix. |
| `pls` | Many correlated features. |
| `high-precision` | Your scenes are 16-bit or float. |

For anything else, such as turning stages off, flat-field options, neural-network
or PLS models, CPU-only detection, build a
`Config`:

```python
from ColorCorrectionPipeline import Config, calibrate

config = Config.from_preset("rpcc2", steps={"ffc": {"apply": {"domain": "linear"}}})
cal = calibrate("chart.jpg", white="white.jpg", config=config)
```

The **[configuration guide](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/configuration.md)**
has a recipe for each common task and a table of every setting with its default.

## Try it on the sample photos

The package ships a sample chart, white target and scene:

```shell
python -m ColorCorrectionPipeline.examples.quickstart --output demo
python -m ColorCorrectionPipeline.examples.apply_bundle --bundle demo/calibration.ccpb --image my_photo.jpg --output replay
```

The first command calibrates and writes `demo/calibration.ccpb`, a corrected
image and the metrics. The second applies that calibration to your own photo.

## Upgrading from 2.x

3.0 removed the old fitting recipes (`legacy-v1`, `reproducible-v1`, API-1
configuration dictionaries, MCC detection and `key_functions`). Requesting one
raises an error that names its replacement. Calibrations saved by 2.x still load
and give the same output. See [migrating to 3.0](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/migration-3.md),
or pin `ColorCorrectionPipeline==2.3.0` to keep the old recipes.

## Documentation

- [Configuration guide](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/configuration.md): recipes and every setting.
- [Batch processing](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/batch-and-reporting.md): many images, progress, reports.
- [Calibration bundles](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/calibration-bundles.md): the `.ccpb` format.
- [Reading and saving images](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/image-io-policies.md): bit depth, color profiles, TIFF and PNG export.
- [Chart detection](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/chart-detection.md) and [GPU selection](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/gpu-detection.md).
- [Logging](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/logging.md): enable progress messages with `logging.basicConfig(level=logging.INFO)`.
- [Fully customizable example](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/ColorCorrectionPipeline/examples/customizable.py): settings in a JSON file, several scenes, TIFF export.

A desktop app with the same workflow is available as
[ColorCorrect Studio](https://github.com/collinswakholi/ColorCorrectionPackage_UI).

## Development

```shell
pip install -e ".[dev,performance]"
pytest tests
black --check ColorCorrectionPipeline tests scripts
ruff check ColorCorrectionPipeline tests scripts
mypy ColorCorrectionPipeline
```

See [architecture](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/docs/architecture.md)
for how the code is organized.

## License and citation

The Python code is [MIT licensed](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/LICENSE).
The bundled chart-detection models are AGPL-3.0; see their
[notices](https://github.com/collinswakholi/ColorCorrectionPackage/blob/main/ColorCorrectionPipeline/detection/models/UPSTREAM-NOTICE.md).

If you use this package in research, please cite:

> Wakholi, C., Hardigan, M. A., Lee, J., Lukas, S. B., Feldman, M. J., Altendorf,
> K. R., Neyhart, J. L., & Rippner, D. A. (2026). A systematic color correction
> pipeline for controlled-environment imaging. *The Plant Phenome Journal*, 9(1),
> e70067. [doi:10.1002/ppj2.70067](https://doi.org/10.1002/ppj2.70067)

Thanks to Devin A. Rippner for technical guidance, ORISE for fellowship support,
and USDA-ARS for research support. [Report an issue](https://github.com/collinswakholi/ColorCorrectionPackage/issues).
