White balance, that is the so-called white balance.
White balance algorithm has many, here is recorded is the simplest practical white balance algorithm, that is the grey World law!
Gray World algorithm is based on the gray world hypothesis, which assumes that for an image with a large number of color changes, the average value of R, G, and B three components tends to be the same gray K.
The following is the specific algorithm code:
Rgb=imread (' test.jpg '); R = RGB (:,:, 1); G = RGB (:,:, 2); B = RGB (:,:, 3); Rx4 = RGB (:,:, 1); Gx4 = RGB (:,:, 2); Bx4 = RGB (:,:, 3); Rx4 just made a simple linear brightening, which can be used without reference. Rave = mean (mean (R)); gave = Mean (mean (G)); Bave = mean (mean (B)); Kave = (Rave + gave + bave)/3; R1 = (kave/rave) *r; G1 = (kave/gave) *g; B1 = (kave/bave) *b; R2 = (kave/rave) *rx4; G2 = (kave/gave) *gx4; B2 = (kave/bave) *bx4; Rgb_white = Cat (3, R1, G1, B1); Rgb_whitex4 = Cat (3, R2, G2, B2); Rgb_white_out = Uint8 (rgb_white); rgb_white_outx4 = Uint8 (rgb_whitex4);
Here is the effect of the algorithm:
Original:
After white balance:
Visible, the most primitive algorithm, the effect is good, there is a chance to add some other good algorithm.
Matlab image Processing _ Image white balance algorithm (grey World method)