Enum opencv::mcc::LINEAR_TYPE [−][src]
#[repr(C)]
pub enum LINEAR_TYPE {
LINEARIZATION_IDENTITY,
LINEARIZATION_GAMMA,
LINEARIZATION_COLORPOLYFIT,
LINEARIZATION_COLORLOGPOLYFIT,
LINEARIZATION_GRAYPOLYFIT,
LINEARIZATION_GRAYLOGPOLYFIT,
}
Expand description
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:
: any channel of a color, could be
or
.
:
channels respectively.
: grayscale;
: subscript, which represents the detected data and its linearized value, the former is the input and the latter is the output;
: subscript, which represents the reference data and its linearized value
Identical Transformation
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
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 is usually set to 2.2.
You can also customize the value.
The formula for gamma correction linearization is as follows:
Polynomial Fitting
Polynomial fitting uses polynomials to linearize.
Provided the polynomial is:
Then:
In practice,
is used to prevent overfitting.
There are many variants of polynomial fitting, the difference lies in the way of generating .
It is usually necessary to use linearized reference colors and corresponding detected colors to calculate the polynomial parameters.
However, not all colors can participate in the calculation. The saturation detected colors needs to be removed. See the algorithm introduction document for details.
Fitting Channels Respectively
Use three polynomials, , to linearize each channel of the RGB color space[1-3]:
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.
Grayscale Polynomial Fitting
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
is obtained, linearization can be performed.
Logarithmic Polynomial Fitting
For gamma correction formula, we take the logarithm:
It can be seen that there is a linear relationship between
and
. It can be considered that the formula is an approximation of a polynomial relationship, that is, there exists a polynomial
, which makes[2]:
Because , the channel whose component is 0 is directly mapped to 0 in the formula above.
For fitting channels respectively, we have:
Note that the parameter of
cannot be 0.
Therefore, we need to delete the channels whose values are 0 from
and
,
and
,
and
.
Therefore:
For grayscale polynomials, there are also:
and:
Variants
no change is made
gamma correction; Need assign a value to gamma simultaneously
polynomial fitting channels respectively; Need assign a value to deg simultaneously
logarithmic polynomial fitting channels respectively; Need assign a value to deg simultaneously
grayscale polynomial fitting; Need assign a value to deg and dst_whites simultaneously
grayscale Logarithmic polynomial fitting; Need assign a value to deg and dst_whites simultaneously
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for LINEAR_TYPE
impl Send for LINEAR_TYPE
impl Sync for LINEAR_TYPE
impl Unpin for LINEAR_TYPE
impl UnwindSafe for LINEAR_TYPE
Blanket Implementations
Mutably borrows from an owned value. Read more