colorcorrectionmatrix
colorcorrectionmatrix copied to clipboard
Compute color correction matrix in python and C++
Compute Color Correction Matrix (CCM)
We compute Color Correction Matrix A. In other words, we calculate a 4x3 matrix A which approximate the following equation.
Let P be a reference color checker matrix (24 x 3) and O be a color checker
matrix to correct (24 x 3).
P = [O 1] A
Data
We have to prepare color checker patch data as csv format.
There are example data in data
directory.
-
data/colorchart_photo_strobo_linear.csv
-
data/colorchart_rendered_strobo_linear.csv
They are 24x3 matrix. The data are made by reading pixel values using Natron2
Dependency
- Python
- numpy
- matplotlib
- Pillow
- OpenEXR
- C++
- args.hxx(included in this repo)
- Eigen3
Build c++ version of computeCCM
$ cd cpp
$ mkdir build
$ cmake ../
$ make
Usage
# computeCCM.py [-h] [-g GAMMA] reference_csv source_csv output_csv
$ computeCCM.py data/colorchart_photo_strobo_linear.csv data/colorchart_rendered_strobo_linear.csv ccm.csv
This command generates optimal Color Correction Matrix as csv file (ccm.csv
)
Test
We can compare reference data and corrected data using plotChart.py
$ plotChart.py ccm.csv data/colorchart_photo_strobo_linear.csv data/colorchart_rendered_strobo_linear.csv ccm.csv chart
Each patch shows reference color and corrected color. Upper one is reference and lower one is corrected color. The numbers mean relative error.
Color Correction
Correct given image using CCM.
correctColor.py
reads jpg or png images, and
correctColorExr.py
reads exr images.
Usage
$ correctColor.py ccm.csv reference.png corrected
corrected image
Image Diff
Generate diff image between a reference image and a corrected image. We compute a difference between two images and take average of rgb for each pixels.
Usage
$ imageDiff.py photo_reference.png corrected.png
The difference is small as the color approaches blue and the difference is big as the color approaches red.
License
CCM is licensed under MIT license.
Third party licenses
References
- RGB coordinates of the Macbeth ColorChecker, Danny Pascale. June 1st, 2006 version. http://www.babelcolor.com/index_htm_files/RGB%20Coordinates%20of%20the%20Macbeth%20ColorChecker.pdf
- Color Correction Matrix http://www.imatest.com/docs/colormatrix/
- Raw-to-raw: Mapping between image sensor color responses. CVPR 2014. https://www.cv-foundation.org/openaccess/content_cvpr_2014/papers/Nguyen_Raw-to-Raw_Mapping_between_2014_CVPR_paper.pdf