How to white balance the each RGB components of an image?

136 views (last 30 days)
First I uploaded an image and splitted it into RGB components..Then I want to white balance each rgb components seperately.. Is the double value of R component is supported to white balance algorithm? or the doubling of r or g or b component is possible?

Accepted Answer

Image Analyst
Image Analyst on 8 Oct 2015
You can't white balance a single color channel (that doesn't even make sense because a single channel is monochrome, not color), but if you want to make the means of each color channel the same, then you can do this
grayImage = rgb2gray(rgbImage); % Convert to gray so we can get the mean luminance.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
meanR = mean2(redChannel);
meanG = mean2(greenChannel);
meanB = mean2(blueChannel);
meanGray = mean2(grayImage);
% Make all channels have the same mean
redChannel = uint8(double(redChannel) * meanGray / meanR);
greenChannel = uint8(double(greenChannel) * meanGray / meanG);
blueChannel = uint8(double(bluedChannel) * meanGray / meanB);
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
It can get more complicated, but see if this simple way works for you and meets your needs.
Image Analyst
Image Analyst on 23 Mar 2021
Yes. Doing that to each channel (dividing by it's actual mean and multiplying by some desired mean) would make each color channel have the same mean. Of course this will change the color of the image. And the gray mean should be computed only on parts of the image that are meant to be "white" (not colored) and should not include any saturated values (values of 0 or 255 if 8 bit or 65535 if 16 bit images).

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 8 Oct 2015
No, white balance inherently requires access to all three channels, as it is necessary to estimate the color temperature.

Mahmoud Afifi
Mahmoud Afifi on 12 Aug 2019
You can apply diagonal white balance correction to raw-RGB images that are a linear representation constructed at the begining of camera rendering pipeline. If you have a rendered sRGB image (e.g., JPEG image), applying white balance in that space by scaling each color channel will not help too much in serious color cast cases. In that case you may need to use an algorithm for white balancing images in sRGB space.
Try this one:
Reference: When Color Constancy Goes Wrong: Correcting Improperly White-Balanced Images, CVPR'19.


Find more on C4ISR in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by