This paper mainly explains the process of estimating the current scene temperature in the white balance algorithm.
The principle of color temperature calculation is not complicated, but to do well, or to do a good job of every step, this requires a lot of testing, and the algorithm is constantly improved.
First, let's talk about the process briefly:
1. Take a frame of image data and divide it into MXN blocks, assuming it is 25x25, and count the basic information of each block (the number of white pixels and the mean of the component of the R/g/b channel).
2, according to the statistical values in the 1th step, find all the white blocks in the image and determine the color temperature according to the color temperature curve.
3, so far, we have come to the image of all possible color temperature, if it is a single light source, you can take the most color temperature, as the current color temperature.
For example, 25x25=625 a block, a total of 100 effective white blocks, and there are 80 white blocks representing the color temperature of 4500 or so, the current color temperature is basically 4500.
Adjust the current image according to the rgain,bgain of the 4500 color temperature, it will not be bad (many!).
Let's take a closer look at the work that needs to be done in each step:
The 1th step is to calculate the basic information for each block.
About the white pixel statistics, we know that the original image of the sensor is biased color, how to count the white dots in the block, that only set a color range, as long as in the range, it can be considered as white pixels, the range is as follows:
The usefulness of counting the number of white pixels is 1, if the white pixels in the block are too small, you can discard them. 2, if there are too many white pixels, more than every pixel, it will be discarded, because it is likely to be exposed in the area
Then the statistic to the white Pixel point r/g/b take the mean value, and get the block r/g, b/g value
At this point, we get the number of white dots and the value of r/g,b/g for each block. (please automatically correspond to the 1th part of the color temperature curve).
The second step calculates the current color temperature
This is more complicated, the nature is colorful, the scenery is thousands. The last step of the "white point" will inevitably have a mistake, more common such as yellow skin easily be mistaken for a low color temperature of white, light blue curtains, easy to be mistaken for high color temperature under the white spot, a picture of both white, also have yellow, also have blue time, is not feeling a bit complicated, Other people can continue to complement the brain.
At this point we need a certain strategy to correctly determine which is the real white.
Usually we will take the white block, calculate the distance to the curve, and then set the corresponding weight. Not much to say, the last picture we all understand.
Suppose there is such a picture, the picture is not open AWB under the premise of interception, you can see the left white place slightly green, the current color temperature is indoor incandescent, about 4000~5000k. (Please ignore the problem of color is not positive, we are discussing white balance)
The following is a white balance correction based on the previous statistical information and the measured color temperature curve.
The first thing to find is white section, such as:
The figures in the above figure indicate the detected white areas, the numbers are the same as a white section, according to the statistics (white point, rg/bg Value) to distinguish between. You can see where there is a miscalculation, such as the color card on the left side of the second block of skin color. And the right from the top. The second block is also easily judged to be low .
According to the situation of this kind of false judgment, the weights of different blocks are set based on statistic information, in order to make the area of false judgment less influence the final result.
The above figure marks the weight, which is basically determined by the number of white dots in the statistics. You can see that a piece of white in the picture is marked with a high weight. Other cases are identified with low weights. The weight of one is to see the number of white dots in the block, and the second is to see the distance from RG/BG to the color temperature curve.
Through the above two figures, we can obviously find the white area, and according to the curve to rectify, even if not through the curve correction, the white area of the r/g,b/g value toward 1, let r=g=b, also get very good white balance effect. As shown in:
At this point, the basic process of white balance is finished, there is a picture of the truth, we must look at also convenient.
Summing up: The first time to do white balance, the feeling theory is very simple, do not have any basis to understand. The actual algorithm debugging, it is horseshoes, lost thousands of miles. Always feel involuntarily on the fruitless. There is a lot of information in the middle, for example, there are many white balance algorithms based on the color temperature/grayscale world/dot detection. The actual personal feeling should combine them all, make the algorithm strong, health is what we want.
Remember the pictures of the two white T-shirts that started in the first chapter, forget it, I'll post it again:
This figure can be understood as white balance adjustment under multiple light sources. The shadow color temperature is higher than the sun color temperature, if the sun is 5000k, the shadow may be 7000k. There is a shadow, they often appear in a lens, the color of one of the color adjustment, the other side will be biased. For good overall effect, To balance the rocker, you can add some strategies in it.
Here is a < How to draw a horse, let us understand the process.
Automatic white balance (AWB) algorithm---2, color temperature calculation