The retina-cerebral cortex (Retinex) theory holds that the world is colorless, and the world that the human eye sees is the result of the interaction of light and matter, that is to say, images that map to the human eye and the long Wave (R), medium wave (G), short Wave (B) of the light and the reflective properties of the object
Where I is the human eye to see the image,R is the reflection component of the object,L is the ambient light irradiation component,(x, y) is a two-dimensional image corresponding to the location
Based on the above principle, we can see some common enhancement algorithms of Retinex.
First, SSR (Single scale Retinex) single-scale Retinex algorithm
It calculates r by estimating L, in particular, l can be obtained by Gaussian blur and I do convolution operations, expressed as:
Where F is a Gaussian fuzzy filter, "*" means convolution operation
where σ is called Gaussian space constant (Gaussian Surround space Constant), which is the so-called scale of the algorithm, has a relatively large impact on image processing, for two-dimensional image corresponding to the position in the image, namely:
Therefore, the idea of this algorithm can be attributed to the following steps:
1. Input: Original image data I (x, y), scale (i.e. σ in Gaussian function)
2. ① calculates the image L (x, y) after the original image is blurred by the specified scale.
② calculates the value of Log[r (x, y) by using the calculation method of the log (R) =log (I)-log (L) formula
③ quantifies log[r (x, y) to a range of 0 to 255 pixels, as the final output, the quantization formula: R (x, y) = (value-min)/(max-min) * (255-0) (Note: log[r (x, y) is not required to perform the EXP function operation, but directly Quantization using Log[r (x, y)], which is the value in the above formula
The code is as follows:
(On the left is the original, the right is the SSR): (where σ= 300, that is, sigma=300in the Code)
Second, MSR (multi-scale Retinex) Multi-scale Retinex algorithm
Multi-scale Retina enhancement algorithm (MSR, Multi-scale Retinex), the most classic is 3-scale, large, medium and small, both to achieve the image dynamic range of compression, but also to maintain a good consistency of color sense. Based on the single-scale Retinex algorithm, the Multiscale Retinex algorithm is described as follows:
1, the original image needs to be the Gaussian blur of each scale, the blurred image of the Li (x, y), wherein the small Mark I represents the scale number.
2, the cumulative calculation for each scale log[r (x, y)] = log[r (x, y)] + Weight (i) * (Log[ii (x, y)]-log[li (x, y)]); where weight (i) represents the corresponding weight of each scale, requires that the sum of the weights of each scale must be 1, the classic value is equal weight.
If the scale number is 3, then: W1=W2=W3=1/3
The code is as follows:
(On the left is the original, the middle is the SSR, the right is the MSR)
Third, MSRCR (Multi-scale Retinex with Color restoration) Multi-scale Retinex algorithm with color recovery
In the previous enhancement process, the image may increase the noise, and make the image of the local details of the color distortion, can not show the true color of the object, the overall visual effect becomes worse. In view of this deficiency, MSRCR added the color recovery factor c to adjust the defect of color distortion due to the contrast enhancement in the local area of the image on the basis of MSR.
Let's look at a set of formulas:
RMSRCR (x, y) ' =G⋅RMSRCR (x, y) +b
RMSRCR (x, y) =c (x, y) rmsr (x, y)
C (x, y) =f[i ' (x, y)]=f[i (x, y)/∑i (x, y)]ci (x, y) =f[ii′ (x, y)]=f[ii (x, y) ∑j=1nij (x, y)]
F[i ' (x, y)]=βlog[αi ' (x, y)]=β{log[αi ' (x, y)]−log[∑i (x, y)]}
If it is a grayscale image, you only need to calculate once, if it is a color image, such as RGB three channels, each channel needs to be calculated as above
g = Gain Gain (General value: 5)
b denotes deviation offset (general value: 25)
I (x, y) represents an image of a channel
c indicates a color recovery factor for a channel to adjust the ratio of 3 channel colors;
F (•) A mapping function representing the color space;
β is the gain constant (general value: 46);
α is controlled nonlinear strength (general value: 125)
The MSRCR algorithm uses the color recovery factor c to adjust the proportional relationship between the 3 color channels in the original image, thus highlighting the information of the relative darker regions and achieving the defect of eliminating the color distortion of the image. After processing, the local contrast of the image is improved, the brightness is similar to the real scene, and the image is more lifelike under the people's visual perception. However, after the MSRCR algorithm processes the image, the pixel values generally appear negative. Therefore, after converting from log domain R (x, y) to Real field R (x, y), the image needs to be modified by changing the gain gain and offset offsets.
In addition: Introduce what is the simple white balance of color (simplest color Balance)
The white balance means: The brightest part of the picture is white and the darkest part is black. The rest of the section is stretched
To put it simply, the number of occurrences of each pixel value is counted on the RGB three channels respectively. Set the maximum and minimum values of 1% to 255 and 0. The remaining values are mapped to (0,255) so that the values of each value channel are evenly distributed in RGB. The result of achieving color balance
The MSRCR code is as follows:
(upper left: original, upper right: SSR, bottom left: MSR, bottom right: MSRCR)
As a technical small white, write this note when referring to a lot of blog papers, here to express thanks, at the same time, without permission, please do not reprint ....
Retinex enhancement algorithm for image processing (SSR, MSR, MSRCR)