color-correction


Namecolor-correction JSON
Version 0.0.1rc2 PyPI version JSON
download
home_pageNone
Summaryhelp to do color correction on images based on color checker card classic 24 patch.
upload_time2025-02-09 16:40:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords color consistency color correction color-consistency color-correction computer vision vision
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            
<div align="center">
<!-- image logo -->
<img src="assets/logo-v1.png" alt="Color Correction Logo" width="150"/>

# Color Correction

<br>

[![version](https://badge.fury.io/py/color-correction.svg)](https://badge.fury.io/py/color-correction)
[![downloads](https://img.shields.io/pypi/dm/color-correction)](https://pypistats.org/packages/color-correction)
[![python-version](https://img.shields.io/pypi/pyversions/color-correction)](https://badge.fury.io/py/color-correction)
[![Try color-correction using - Google Colab](https://img.shields.io/badge/Try_color--correction_using-Google_Colab-blue?logo=googlecolab)](https://colab.research.google.com/drive/146SXHHihMmGLzaTSwdBXncVr3SU_I-Dm?usp=sharing)
[![read - docs](https://img.shields.io/badge/read-docs-blue?logo=materialformkdocs)](https://agfianf.github.io/color-correction/)

</div>

> _Package formerly published as [`color-correction-asdfghjkl`](https://pypi.org/project/color-correction-asdfghjkl/) on PyPI. The name has been simplified for better accessibility and professional recognition._

This package is designed to perform color correction on images using the Color Checker Classic 24 Patch card. It provides a robust solution for ensuring accurate color representation in your images.

## 📦 Installation

```bash
pip install color-correction
```

## 🏋️‍♀️ How it works
![How it works](assets/color-correction-how-it-works.png)


## ⚡ How to use

```python
from color_correction import ColorCorrection

# Step 1: Define the path to the input image
image_path = "asset/images/cc-19.png"

# Step 2: Load the input image
input_image = cv2.imread(image_path)

# Step 3: Initialize the color correction model with specified parameters
color_corrector = ColorCorrection(
    detection_model="yolov8",
    detection_conf_th=0.25,
    correction_model="polynomial", # "least_squares", "affine_reg", "linear_reg"
    degree=3,  # for polynomial correction model
    use_gpu=True,
)

# Step 4: Extract color patches from the input image
# you can set reference patches from another image (image has color checker card)
# or use the default D50
# color_corrector.set_reference_patches(image=None, debug=True)
color_corrector.set_input_patches(image=input_image, debug=True)
color_corrector.fit()
corrected_image = color_corrector.predict(
    input_image=input_image,
    debug=True,
    debug_output_dir="zzz",
)

# Step 5: Evaluate the color correction results
eval_result = color_corrector.calc_color_diff_patches()
print(eval_result)
```

<details>
<summary>Sample Evaluation Output</summary>

```json
{
    "initial": {
        "min": 2.254003059526461,
        "max": 13.461066402633447,
        "mean": 8.3072755187654,
        "std": 3.123962754767539,
    },
    "corrected": {
        "min": 0.30910031798755183,
        "max": 5.422311999126372,
        "mean": 1.4965478752947827,
        "std": 1.2915738724958112,
    },
    "delta": {
        "min": 1.9449027415389093,
        "max": 8.038754403507074,
        "mean": 6.810727643470616,
        "std": 1.8323888822717276,
    },
}
```
</details>

<details>
<summary>Sample Output Debug Image</summary>

![Sample Output](assets/sample-output-debug.jpg)

</details>

## 🔎 Reporting
```python
import cv2

from color_correction import ColorCorrectionAnalyzer

# input_image_path = "assets/cc-19.png"
input_image_path = "assets/cc-1.jpg"

report = ColorCorrectionAnalyzer(
    list_correction_methods=[
        ("least_squares", {}),
        ("linear_reg", {}),
        ("affine_reg", {}),
        ("polynomial", {"degree": 2}),
        ("polynomial", {"degree": 3}),
        # ("polynomial", {"degree": 4}),
        # ("polynomial", {"degree": 5}),
    ],
    list_detection_methods=[
        ("yolov8", {"detection_conf_th": 0.25}),
    ],
)
report.run(
    input_image=cv2.imread(input_image_path),
    reference_image=None,
    output_dir="report-output",
)
```
<details>
<summary>Sample Report Output</summary>

![Sample Benchmark Output](assets/sample-benchmark.png)
</details>

## 📈 Benefits
- **Consistency**: Ensure uniform color correction across multiple images.
- **Accuracy**: Leverage the color correction matrix for precise color adjustments.
- **Flexibility**: Adaptable for various image sets with different color profiles.


## 🤸 TODO
- [ ] Add Loggers
- [ ] Add detection MCC:CCheckerDetector from opencv
- [ ] Add Segmentation Color Checker using YOLOv11 ONNX
- [ ] Improve validation preprocessing (e.g., auto-match-orientation CC)
- [ ] Add more analysis and evaluation metrics (Still thinking...)

<!-- write reference -->

## 📚 References
- [Color Checker Classic 24 Patch Card](https://www.xrite.com/categories/calibration-profiling/colorchecker-classic)
- [Color Correction Tool ML](https://github.com/collinswakholi/ML_ColorCorrection_tool/tree/Pip_package)
- [Colour Science Python](https://www.colour-science.org/colour-checker-detection/)
- [Fast and Robust Multiple ColorChecker Detection ()](https://github.com/pedrodiamel/colorchecker-detection)
- [Automatic color correction with OpenCV and Python (PyImageSearch)](https://pyimagesearch.com/2021/02/15/automatic-color-correction-with-opencv-and-python/)
- [ONNX-YOLOv8-Object-Detection](https://github.com/ibaiGorordo/ONNX-YOLOv8-Object-Detection)
- [yolov8-triton](https://github.com/omarabid59/yolov8-triton/tree/main)
- [Streamlined Data Science Development: Organizing, Developing and Documenting Your Code](https://medium.com/henkel-data-and-analytics/streamlined-data-science-development-organizing-developing-and-documenting-your-code-bfd69e3ef4fb)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "color-correction",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "magfianf <muhammadagfian96@gmail.com>",
    "keywords": "color consistency, color correction, color-consistency, color-correction, computer vision, vision",
    "author": null,
    "author_email": "magfianf <muhammadagfian96@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ef/d2/350cf589783b9c311d1a7d495d3e44a46ec83aa21e75e3fb881e7332b1f4/color_correction-0.0.1rc2.tar.gz",
    "platform": null,
    "description": "\n<div align=\"center\">\n<!-- image logo -->\n<img src=\"assets/logo-v1.png\" alt=\"Color Correction Logo\" width=\"150\"/>\n\n# Color Correction\n\n<br>\n\n[![version](https://badge.fury.io/py/color-correction.svg)](https://badge.fury.io/py/color-correction)\n[![downloads](https://img.shields.io/pypi/dm/color-correction)](https://pypistats.org/packages/color-correction)\n[![python-version](https://img.shields.io/pypi/pyversions/color-correction)](https://badge.fury.io/py/color-correction)\n[![Try color-correction using - Google Colab](https://img.shields.io/badge/Try_color--correction_using-Google_Colab-blue?logo=googlecolab)](https://colab.research.google.com/drive/146SXHHihMmGLzaTSwdBXncVr3SU_I-Dm?usp=sharing)\n[![read - docs](https://img.shields.io/badge/read-docs-blue?logo=materialformkdocs)](https://agfianf.github.io/color-correction/)\n\n</div>\n\n> _Package formerly published as [`color-correction-asdfghjkl`](https://pypi.org/project/color-correction-asdfghjkl/) on PyPI. The name has been simplified for better accessibility and professional recognition._\n\nThis package is designed to perform color correction on images using the Color Checker Classic 24 Patch card. It provides a robust solution for ensuring accurate color representation in your images.\n\n## \ud83d\udce6 Installation\n\n```bash\npip install color-correction\n```\n\n## \ud83c\udfcb\ufe0f\u200d\u2640\ufe0f How it works\n![How it works](assets/color-correction-how-it-works.png)\n\n\n## \u26a1 How to use\n\n```python\nfrom color_correction import ColorCorrection\n\n# Step 1: Define the path to the input image\nimage_path = \"asset/images/cc-19.png\"\n\n# Step 2: Load the input image\ninput_image = cv2.imread(image_path)\n\n# Step 3: Initialize the color correction model with specified parameters\ncolor_corrector = ColorCorrection(\n    detection_model=\"yolov8\",\n    detection_conf_th=0.25,\n    correction_model=\"polynomial\", # \"least_squares\", \"affine_reg\", \"linear_reg\"\n    degree=3,  # for polynomial correction model\n    use_gpu=True,\n)\n\n# Step 4: Extract color patches from the input image\n# you can set reference patches from another image (image has color checker card)\n# or use the default D50\n# color_corrector.set_reference_patches(image=None, debug=True)\ncolor_corrector.set_input_patches(image=input_image, debug=True)\ncolor_corrector.fit()\ncorrected_image = color_corrector.predict(\n    input_image=input_image,\n    debug=True,\n    debug_output_dir=\"zzz\",\n)\n\n# Step 5: Evaluate the color correction results\neval_result = color_corrector.calc_color_diff_patches()\nprint(eval_result)\n```\n\n<details>\n<summary>Sample Evaluation Output</summary>\n\n```json\n{\n    \"initial\": {\n        \"min\": 2.254003059526461,\n        \"max\": 13.461066402633447,\n        \"mean\": 8.3072755187654,\n        \"std\": 3.123962754767539,\n    },\n    \"corrected\": {\n        \"min\": 0.30910031798755183,\n        \"max\": 5.422311999126372,\n        \"mean\": 1.4965478752947827,\n        \"std\": 1.2915738724958112,\n    },\n    \"delta\": {\n        \"min\": 1.9449027415389093,\n        \"max\": 8.038754403507074,\n        \"mean\": 6.810727643470616,\n        \"std\": 1.8323888822717276,\n    },\n}\n```\n</details>\n\n<details>\n<summary>Sample Output Debug Image</summary>\n\n![Sample Output](assets/sample-output-debug.jpg)\n\n</details>\n\n## \ud83d\udd0e Reporting\n```python\nimport cv2\n\nfrom color_correction import ColorCorrectionAnalyzer\n\n# input_image_path = \"assets/cc-19.png\"\ninput_image_path = \"assets/cc-1.jpg\"\n\nreport = ColorCorrectionAnalyzer(\n    list_correction_methods=[\n        (\"least_squares\", {}),\n        (\"linear_reg\", {}),\n        (\"affine_reg\", {}),\n        (\"polynomial\", {\"degree\": 2}),\n        (\"polynomial\", {\"degree\": 3}),\n        # (\"polynomial\", {\"degree\": 4}),\n        # (\"polynomial\", {\"degree\": 5}),\n    ],\n    list_detection_methods=[\n        (\"yolov8\", {\"detection_conf_th\": 0.25}),\n    ],\n)\nreport.run(\n    input_image=cv2.imread(input_image_path),\n    reference_image=None,\n    output_dir=\"report-output\",\n)\n```\n<details>\n<summary>Sample Report Output</summary>\n\n![Sample Benchmark Output](assets/sample-benchmark.png)\n</details>\n\n## \ud83d\udcc8 Benefits\n- **Consistency**: Ensure uniform color correction across multiple images.\n- **Accuracy**: Leverage the color correction matrix for precise color adjustments.\n- **Flexibility**: Adaptable for various image sets with different color profiles.\n\n\n## \ud83e\udd38 TODO\n- [ ] Add Loggers\n- [ ] Add detection MCC:CCheckerDetector from opencv\n- [ ] Add Segmentation Color Checker using YOLOv11 ONNX\n- [ ] Improve validation preprocessing (e.g., auto-match-orientation CC)\n- [ ] Add more analysis and evaluation metrics (Still thinking...)\n\n<!-- write reference -->\n\n## \ud83d\udcda References\n- [Color Checker Classic 24 Patch Card](https://www.xrite.com/categories/calibration-profiling/colorchecker-classic)\n- [Color Correction Tool ML](https://github.com/collinswakholi/ML_ColorCorrection_tool/tree/Pip_package)\n- [Colour Science Python](https://www.colour-science.org/colour-checker-detection/)\n- [Fast and Robust Multiple ColorChecker Detection ()](https://github.com/pedrodiamel/colorchecker-detection)\n- [Automatic color correction with OpenCV and Python (PyImageSearch)](https://pyimagesearch.com/2021/02/15/automatic-color-correction-with-opencv-and-python/)\n- [ONNX-YOLOv8-Object-Detection](https://github.com/ibaiGorordo/ONNX-YOLOv8-Object-Detection)\n- [yolov8-triton](https://github.com/omarabid59/yolov8-triton/tree/main)\n- [Streamlined Data Science Development: Organizing, Developing and Documenting Your Code](https://medium.com/henkel-data-and-analytics/streamlined-data-science-development-organizing-developing-and-documenting-your-code-bfd69e3ef4fb)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "help to do color correction on images based on color checker card classic 24 patch.",
    "version": "0.0.1rc2",
    "project_urls": {
        "Homepage": "https://github.com/agfianf/color-correction",
        "Issues": "https://github.com/agfianf/color-correction/issues",
        "Repository": "https://github.com/agfianf/color-correction"
    },
    "split_keywords": [
        "color consistency",
        " color correction",
        " color-consistency",
        " color-correction",
        " computer vision",
        " vision"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "98918f47af1927d60ee3d835e8801d853b67ce2ca16eb1bb700063d25df8ebbc",
                "md5": "d142e06de228ecc28c143610d01652f5",
                "sha256": "9f6bb0c41ca37348f556f3188c9d461394a3985256e5505c10a3ce971f778e7c"
            },
            "downloads": -1,
            "filename": "color_correction-0.0.1rc2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d142e06de228ecc28c143610d01652f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 47427,
            "upload_time": "2025-02-09T16:40:06",
            "upload_time_iso_8601": "2025-02-09T16:40:06.935363Z",
            "url": "https://files.pythonhosted.org/packages/98/91/8f47af1927d60ee3d835e8801d853b67ce2ca16eb1bb700063d25df8ebbc/color_correction-0.0.1rc2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "efd2350cf589783b9c311d1a7d495d3e44a46ec83aa21e75e3fb881e7332b1f4",
                "md5": "54adfda2bfe0efb1e7a791a0f30d554a",
                "sha256": "b51ed66fc95d8b3bcbe4cdd24b7b8cc706c1a5d7d2425f7d16c5ad999c54b48e"
            },
            "downloads": -1,
            "filename": "color_correction-0.0.1rc2.tar.gz",
            "has_sig": false,
            "md5_digest": "54adfda2bfe0efb1e7a791a0f30d554a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5209165,
            "upload_time": "2025-02-09T16:40:09",
            "upload_time_iso_8601": "2025-02-09T16:40:09.046480Z",
            "url": "https://files.pythonhosted.org/packages/ef/d2/350cf589783b9c311d1a7d495d3e44a46ec83aa21e75e3fb881e7332b1f4/color_correction-0.0.1rc2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-09 16:40:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "agfianf",
    "github_project": "color-correction",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "color-correction"
}
        
Elapsed time: 2.56001s