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:

inline formula: any channel of a color, could be inline formula or inline formula.

inline formula: inline formula channels respectively.

inline formula: grayscale;

inline formula: subscript, which represents the detected data and its linearized value, the former is the input and the latter is the output;

inline formula: 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:

block formula

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 inline formula is usually set to 2.2. You can also customize the value.

The formula for gamma correction linearization is as follows: block formula

Polynomial Fitting

Polynomial fitting uses polynomials to linearize. Provided the polynomial is: block formula Then: block formula In practice, inline formula is used to prevent overfitting.

There are many variants of polynomial fitting, the difference lies in the way of generating inline formula. 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, inline formula, to linearize each channel of the RGB color space[1-3]: block formula 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:

block formula

It’s equivalent to finding the least square regression for below equations: block formula

With a polynomial, the above equations becomes: block formula It can be expressed as a system of linear equations:

block formula

When the number of reference colors is not less than the degree of the polynomial, the linear system has a least-squares solution:

block formula

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:

block formula

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]. block formula Then the polynomial parameters can be obtained by using the polyfit. block formula After inline formula is obtained, linearization can be performed.

Logarithmic Polynomial Fitting

For gamma correction formula, we take the logarithm: block formula It can be seen that there is a linear relationship between inline formula and inline formula. It can be considered that the formula is an approximation of a polynomial relationship, that is, there exists a polynomial inline formula, which makes[2]: block formula

Because inline formula, the channel whose component is 0 is directly mapped to 0 in the formula above.

For fitting channels respectively, we have: block formula Note that the parameter of inline formula cannot be 0. Therefore, we need to delete the channels whose values are 0 from inline formula and inline formula, inline formula and inline formula, inline formula and inline formula.

Therefore:

block formula

For grayscale polynomials, there are also: block formula and: block formula

Variants

LINEARIZATION_IDENTITY

no change is made

LINEARIZATION_GAMMA

gamma correction; Need assign a value to gamma simultaneously

LINEARIZATION_COLORPOLYFIT

polynomial fitting channels respectively; Need assign a value to deg simultaneously

LINEARIZATION_COLORLOGPOLYFIT

logarithmic polynomial fitting channels respectively; Need assign a value to deg simultaneously

LINEARIZATION_GRAYPOLYFIT

grayscale polynomial fitting; Need assign a value to deg and dst_whites simultaneously

LINEARIZATION_GRAYLOGPOLYFIT

grayscale Logarithmic polynomial fitting; Need assign a value to deg and dst_whites simultaneously

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.