MATLAB Answers

ExposureCorrection for a set of RGB images

16 views (last 30 days)
Dear Image Analyst ! my problem is the following : i have a set of images and all of them have a ColorChecker chart as you can see in the example bellow. My mission is to correct the exposure (correct the Contrast and the Brightness i guess) of every image based on one image of my choice ( the one that has perfect exposure in my opinion, in this example , it's the Reference image).
The test i need to do to check if i have good results after the correction is to compare the 6 gray patches RGB value to see if they match : for example i need to compare the white patch in the reference image with the white patch of the corrected Overexposed image, the RGB value in both patches should be equal.Same goes for the Black patch and the 4 gray ones. the patches are extracted from the correspondent images.
Cheers,Zouhair.

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 25 May 2017
First of all you need to make sure you don't have any clipping/saturation in any of your color channels. If you do, you're out of luck. Then you need to read all the chip colors and develop a transform to convert the actual colors into the standardized colors. I don't have any generic/demo code to do this even though I do it all the time. It's been on my list (to make such a demo) for a long time. In the mean time, see the directions, attached. Essentially you just need to find a model with least squares and apply that model to the bad image to "fix" it.

  4 Comments

Show 1 older comment
zouhair jimmouh
zouhair jimmouh on 8 Jun 2017
Hi Mr.Image Anlyst! i couldn't find or create a least squares model. can you give me any pseudo code i can start with, i would really appreciate your help.
Image Analyst
Image Analyst on 8 Jun 2017
I don't have any since I don't do that. I just do calibrated color analysis so I use CIELAB color space. But for that, going from RGB to XYZ and LAB (rather than to RGB), I just use
the standard least squares matrix equation:
%=====================================================================================================
function coefficients = GetTransform(standard, test, equationOrder)
try
% We're going to use a 14 coefficient cross channel cubic model.
% We'll have one row for each chip.
% [A][RGB Terms] = [Standard colors]
% dblNewPixel = a0 + a1 * r + a2 * g + a3 * b + _
% a4 * r * g + a5 * r * b + a6 * g * b + _
% a7 * r^2 + a8 * g^2 + a9 * b^2 + _
% a10 * r^2 * r + a11 * g^2 * g + a12 * b2 * b + a13 * r * g * b
numberOfChips = length(standard);
if equationOrder == 1
% 1st order equation has 4 coeffs.
A = zeros(numberOfChips, 4);
elseif equationOrder == 2
% 2nd order equation has 10 coeffs.
A = zeros(numberOfChips, 10);
else
% 3rd order equation has 14 coeffs.
A = zeros(numberOfChips, 14);
end
standardRedColors = zeros(numberOfChips, 1);
standardGreenColors = zeros(numberOfChips, 1);
standardBlueColors = zeros(numberOfChips, 1);
for chip = 1 : numberOfChips
r = test(chip).rgbValues(1); % Red value of test chip.
g = test(chip).rgbValues(2); % Green value of test chip.
b = test(chip).rgbValues(3); % Blue value of test chip.
A(chip, 1) = 1;
A(chip, 2) = r;
A(chip, 3) = g;
A(chip, 4) = b;
if equationOrder >= 2
A(chip, 5) = r * g;
A(chip, 6) = r * b;
A(chip, 7) = g * b;
A(chip, 8) = r ^ 2;
A(chip, 9) = g ^ 2;
A(chip, 10) = b ^ 2 ;
end
if equationOrder >= 3
A(chip, 11) = r ^ 3;
A(chip, 12) = g ^ 3;
A(chip, 13) = b ^ 3;
A(chip, 14) = r * g * b;
end
% Get the red, green, and blue values of the standard into a column vector.
standardRedColors(chip) = standard(chip).rgbValues(1); % Red value of standard (reference) chip.
standardGreenColors(chip) = standard(chip).rgbValues(2); % Green value of standard (reference) chip.
standardBlueColors(chip) = standard(chip).rgbValues(3); % Blue value of standard (reference) chip.
end
coefficients.Red = inv(A' * A) * A' * standardRedColors; % Will do a least square solution.
coefficients.Green = inv(A' * A) * A' * standardGreenColors; % Will do a least square solution.
coefficients.Blue = inv(A' * A) * A' * standardBlueColors; % Will do a least square solution.
catch ME
errorMessage = sprintf('Error in function GetTransform().\n\nError Message:\n%s', ME.message);
fprintf(1, '%s\n', errorMessage);
WarnUser(errorMessage);
end
return; % from GetTransform
end % of GetTransform
I know there is a better way using slash, but I wrote this a long time ago before I knew that and I've never gone back to improve it. Anyway, it works though it's real explicit rather than compact and MATLAB-ish.
zouhair jimmouh
zouhair jimmouh on 9 Jun 2017
Thank you Sir! you are a life-saver.

Sign in to comment.

More Answers (0)


Translated by