How to white balance the each RGB components of an image?
130 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?
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.
More Answers (2)
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 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.