![]() |
OpenCV
Open Source Computer Vision
|
The purpose of color correction is to adjust the color response of input and output devices to a known state. The device being calibrated is sometimes called the calibration source; the color space used as the standard is sometimes called the calibration target. Color calibration has been used in many industries, such as television production, games, photography, engineering, chemistry, medicine, etc. Due to the manufacturing process of the input and output equipment, the channel response has nonlinear distortion. In order to correct the picture output of the equipment, it is nessary to calibrate the captured color and the actual color.
Classes | |
class | cv::ccm::ColorCorrectionModel |
Core class of ccm model. More... | |
enum cv::ccm::CCM_TYPE |
#include <opencv2/mcc/ccm.hpp>
Enum of the possible types of ccm.
Enumerator | |
---|---|
CCM_3x3 Python: cv.ccm.CCM_3x3 | The CCM with the shape |
CCM_4x3 Python: cv.ccm.CCM_4x3 | The CCM with the shape |
enum cv::ccm::COLOR_SPACE |
#include <opencv2/mcc/ccm.hpp>
Enumerator | |
---|---|
COLOR_SPACE_sRGB Python: cv.ccm.COLOR_SPACE_sRGB | https://en.wikipedia.org/wiki/SRGB , RGB color space |
COLOR_SPACE_sRGBL Python: cv.ccm.COLOR_SPACE_sRGBL | https://en.wikipedia.org/wiki/SRGB , linear RGB color space |
COLOR_SPACE_AdobeRGB Python: cv.ccm.COLOR_SPACE_AdobeRGB | https://en.wikipedia.org/wiki/Adobe_RGB_color_space , RGB color space |
COLOR_SPACE_AdobeRGBL Python: cv.ccm.COLOR_SPACE_AdobeRGBL | https://en.wikipedia.org/wiki/Adobe_RGB_color_space , linear RGB color space |
COLOR_SPACE_WideGamutRGB Python: cv.ccm.COLOR_SPACE_WideGamutRGB | https://en.wikipedia.org/wiki/Wide-gamut_RGB_color_space , RGB color space |
COLOR_SPACE_WideGamutRGBL Python: cv.ccm.COLOR_SPACE_WideGamutRGBL | https://en.wikipedia.org/wiki/Wide-gamut_RGB_color_space , linear RGB color space |
COLOR_SPACE_ProPhotoRGB Python: cv.ccm.COLOR_SPACE_ProPhotoRGB | https://en.wikipedia.org/wiki/ProPhoto_RGB_color_space , RGB color space |
COLOR_SPACE_ProPhotoRGBL Python: cv.ccm.COLOR_SPACE_ProPhotoRGBL | https://en.wikipedia.org/wiki/ProPhoto_RGB_color_space , linear RGB color space |
COLOR_SPACE_DCI_P3_RGB Python: cv.ccm.COLOR_SPACE_DCI_P3_RGB | https://en.wikipedia.org/wiki/DCI-P3 , RGB color space |
COLOR_SPACE_DCI_P3_RGBL Python: cv.ccm.COLOR_SPACE_DCI_P3_RGBL | https://en.wikipedia.org/wiki/DCI-P3 , linear RGB color space |
COLOR_SPACE_AppleRGB Python: cv.ccm.COLOR_SPACE_AppleRGB | https://en.wikipedia.org/wiki/RGB_color_space , RGB color space |
COLOR_SPACE_AppleRGBL Python: cv.ccm.COLOR_SPACE_AppleRGBL | https://en.wikipedia.org/wiki/RGB_color_space , linear RGB color space |
COLOR_SPACE_REC_709_RGB Python: cv.ccm.COLOR_SPACE_REC_709_RGB | https://en.wikipedia.org/wiki/Rec._709 , RGB color space |
COLOR_SPACE_REC_709_RGBL Python: cv.ccm.COLOR_SPACE_REC_709_RGBL | https://en.wikipedia.org/wiki/Rec._709 , linear RGB color space |
COLOR_SPACE_REC_2020_RGB Python: cv.ccm.COLOR_SPACE_REC_2020_RGB | https://en.wikipedia.org/wiki/Rec._2020 , RGB color space |
COLOR_SPACE_REC_2020_RGBL Python: cv.ccm.COLOR_SPACE_REC_2020_RGBL | https://en.wikipedia.org/wiki/Rec._2020 , linear RGB color space |
COLOR_SPACE_XYZ_D65_2 Python: cv.ccm.COLOR_SPACE_XYZ_D65_2 | https://en.wikipedia.org/wiki/CIE_1931_color_space , non-RGB color space |
COLOR_SPACE_XYZ_D65_10 Python: cv.ccm.COLOR_SPACE_XYZ_D65_10 | non-RGB color space |
COLOR_SPACE_XYZ_D50_2 Python: cv.ccm.COLOR_SPACE_XYZ_D50_2 | non-RGB color space |
COLOR_SPACE_XYZ_D50_10 Python: cv.ccm.COLOR_SPACE_XYZ_D50_10 | non-RGB color space |
COLOR_SPACE_XYZ_A_2 Python: cv.ccm.COLOR_SPACE_XYZ_A_2 | non-RGB color space |
COLOR_SPACE_XYZ_A_10 Python: cv.ccm.COLOR_SPACE_XYZ_A_10 | non-RGB color space |
COLOR_SPACE_XYZ_D55_2 Python: cv.ccm.COLOR_SPACE_XYZ_D55_2 | non-RGB color space |
COLOR_SPACE_XYZ_D55_10 Python: cv.ccm.COLOR_SPACE_XYZ_D55_10 | non-RGB color space |
COLOR_SPACE_XYZ_D75_2 Python: cv.ccm.COLOR_SPACE_XYZ_D75_2 | non-RGB color space |
COLOR_SPACE_XYZ_D75_10 Python: cv.ccm.COLOR_SPACE_XYZ_D75_10 | non-RGB color space |
COLOR_SPACE_XYZ_E_2 Python: cv.ccm.COLOR_SPACE_XYZ_E_2 | non-RGB color space |
COLOR_SPACE_XYZ_E_10 Python: cv.ccm.COLOR_SPACE_XYZ_E_10 | non-RGB color space |
COLOR_SPACE_Lab_D65_2 Python: cv.ccm.COLOR_SPACE_Lab_D65_2 | https://en.wikipedia.org/wiki/CIELAB_color_space , non-RGB color space |
COLOR_SPACE_Lab_D65_10 Python: cv.ccm.COLOR_SPACE_Lab_D65_10 | non-RGB color space |
COLOR_SPACE_Lab_D50_2 Python: cv.ccm.COLOR_SPACE_Lab_D50_2 | non-RGB color space |
COLOR_SPACE_Lab_D50_10 Python: cv.ccm.COLOR_SPACE_Lab_D50_10 | non-RGB color space |
COLOR_SPACE_Lab_A_2 Python: cv.ccm.COLOR_SPACE_Lab_A_2 | non-RGB color space |
COLOR_SPACE_Lab_A_10 Python: cv.ccm.COLOR_SPACE_Lab_A_10 | non-RGB color space |
COLOR_SPACE_Lab_D55_2 Python: cv.ccm.COLOR_SPACE_Lab_D55_2 | non-RGB color space |
COLOR_SPACE_Lab_D55_10 Python: cv.ccm.COLOR_SPACE_Lab_D55_10 | non-RGB color space |
COLOR_SPACE_Lab_D75_2 Python: cv.ccm.COLOR_SPACE_Lab_D75_2 | non-RGB color space |
COLOR_SPACE_Lab_D75_10 Python: cv.ccm.COLOR_SPACE_Lab_D75_10 | non-RGB color space |
COLOR_SPACE_Lab_E_2 Python: cv.ccm.COLOR_SPACE_Lab_E_2 | non-RGB color space |
COLOR_SPACE_Lab_E_10 Python: cv.ccm.COLOR_SPACE_Lab_E_10 | non-RGB color space |
enum cv::ccm::CONST_COLOR |
#include <opencv2/mcc/ccm.hpp>
Macbeth and Vinyl ColorChecker with 2deg D50.
#include <opencv2/mcc/ccm.hpp>
Enum of possible functions to calculate the distance between colors.
See https://en.wikipedia.org/wiki/Color_difference for details
#include <opencv2/mcc/ccm.hpp>
Enum of the possible types of initial method.
enum cv::ccm::LINEAR_TYPE |
#include <opencv2/mcc/ccm.hpp>
Linearization transformation type.
The first step in color correction is to linearize the detected colors. Because the input color space has not been calibrated, we usually use some empirical methods to linearize. There are several common linearization methods. The first is identical transformation, the second is gamma correction, and the third is polynomial fitting.
Linearization is generally an elementwise function. The mathematical symbols are as follows:
No change is made during the Identical transformation linearization, usually because the tristimulus values of the input RGB image is already proportional to the luminance. For example, if the input measurement data is in RAW format, the measurement data is already linear, so no linearization is required.
The identity transformation formula is as follows:
Gamma correction is a means of performing nonlinearity in RGB space, see the Color Space documentation for details. In the linearization part, the value of
The formula for gamma correction linearization is as follows:
Polynomial fitting uses polynomials to linearize. Provided the polynomial is:
Then:
In practice,
There are many variants of polynomial fitting, the difference lies in the way of generating
Use three polynomials,
The polynomial is generated by minimizing the residual sum of squares between the detected data and the linearized reference data. Take the R-channel as an example:
It's equivalent to finding the least square regression for below equations:
With a polynomial, the above equations becomes:
It can be expressed as a system of linear equations:
When the number of reference colors is not less than the degree of the polynomial, the linear system has a least-squares solution:
Once we get the polynomial coefficients, we can get the polynomial r.
This method of finding polynomial coefficients can be implemented by numpy.polyfit in numpy, expressed here as:
Note that, in general, the polynomial that we want to obtain is guaranteed to monotonically increase in the interval [0,1] , but this means that nonlinear method is needed to generate the polynomials(see [4] for detail). This would greatly increases the complexity of the program. Considering that the monotonicity does not affect the correct operation of the color correction program, polyfit is still used to implement the program.
Parameters for other channels can also be derived in a similar way.
In this method[2], single polynomial is used for all channels. The polynomial is still a polyfit result from the detected colors to the linear reference colors. However, only the gray of the reference colors can participate in the calculation.
Since the detected colors corresponding to the gray of reference colors is not necessarily gray, it needs to be grayed. Grayscale refers to the Y channel of the XYZ color space. The color space of the detected data is not determined and cannot be converted into the XYZ space. Therefore, the sRGB formula is used to approximate[5].
Then the polynomial parameters can be obtained by using the polyfit.
After
For gamma correction formula, we take the logarithm:
It can be seen that there is a linear relationship between
Because
For fitting channels respectively, we have:
Note that the parameter of
Therefore:
For grayscale polynomials, there are also:
and: