color correction of camera output

6 views (last 30 days)
huseyin kara
huseyin kara on 4 Jul 2012
i have an image that taken from manually controlled color options camera. it has some error about colors. i tried to fix them by taking 3 different pixel of the image and took also these 3 pixels real values in terms of rgb values. and i get a 3x3 matrix to correct the hole image. it is basicly working. i get some good result but i have to correct totally. how can i fix the images color. output of my image
after my process
how can i fix these errors
  7 Comments
Kevin Claytor
Kevin Claytor on 4 Jul 2012
1) Dude, it's been an hour, chill out. 2) Are you using the image acquisition toolbox to get the images? I know there's a property where you can change the HSB / RGB values of the camera. After you initalize the camera you can go to get(vid) to see all the properties. Something in there will allow you to adjust the color. Use preview(vid) to see how it looks.
huseyin kara
huseyin kara on 4 Jul 2012
with imaqtool command, the image acquisition toolbox was opened and i get first image start acquisition command. i mean 11.png is product of image acquisition toolbox. my aim is that there are camera settings in image acquisition toolbox and i canceled the auto white balanced or other auto option. and the whole options are controlled manually. and i took an image from this camera and try to correct the color of it

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 4 Jul 2012
Edited: Image Analyst on 4 Jul 2012
I have color correction code (as everyone might expect). It's robust and versatile but it's almost 1000 lines long. Basically it looks like you're trying to do RGB-to-RGB color correction using a "linear single channel" model with no offset. I know the ICC color profiles use that model but it is very primitive and professional color correction software uses better models. I guess you'd also agree since you say your result is not good enough. This primitive model could be fine in some situations, but for more accuracy you might want to add a constant term to your model, and possibly higher order terms and cross channel terms. So to add a constant term to your model, your matrix in your least squares model would be
1 R1 G1 B1
1 R2 G2 B2
1 R3 G3 B3
...
1 RN GN BN
You could even go to higher order like quadratic and include cross terms like R*G to get better correction. N should be more than 3 points like you use. You should have around 20-30 points (actual pixel colors) in the image to train your model, and the "desired" values for each of those actual pixel colors. Have you considered using the X-rite Color Checker Chart? It's an industry standard for color correction. I usually use a linear cross channel correction if I just expect things like intensity changes but sometimes use a quadratic cross channel model if I think there might be a change in the color temperature of the lighting. If you go higher, like cubic, then you'll get better correction at the training colors but for all other colors the corrected colors tend to blow up and go haywire, just like any higher order fitting that you're familiar with. A linear cross channel model would look like:
1 R1 G1 B1 R1*G1 R1*B1 G1*B1
1 R2 G2 B2 R2*G2 R2*B2 G2*B2
1 R3 G3 B3 R3*G3 R3*B3 G2*B3
...
1 RN GN BN RN*GN RN*BN GN*BN
Of course you'd have one regression for each color, plugging in the actual reds and the desired reds, the actual greens and the desired green, and the actual blues and the desired blues. So you get three sets of coefficients out alpha, beta, and gamma. To get your corrected red color for some arbitrary test pixel you'd do
correctedRed = alpha(1) + alpha(2)*Rtest + alpha(3)*Gtest + alpha(4)*Btest + alpha(5)*Rtest*Gtest + alpha(6)*Rtest*Btest + alpha(7)*Gtest*Btest
Disclaimer - I think that's right but I didn't consult my code. Anyway, then you do the same with beta to get the corrected green and with the gamma to get the corrected blue:
correctedGreen = beta(1) + beta(2)*Rtest + beta(3)*Gtest + beta(4)*Btest + beta(5)*Rtest*Gtest + beta(6)*Rtest*Btest + beta(7)*Gtest*Btest
correctedBlue = gamma(1) + gamma(2)*Rtest + gamma(3)*Gtest + gamma(4)*Btest + gamma(5)*Rtest*Gtest + gamma(6)*Rtest*Btest + gamma(7)*Gtest*Btest
  2 Comments
huseyin kara
huseyin kara on 5 Jul 2012
Edited: Walter Roberson on 9 Jul 2012
your last suggestion gives me nothing because
A=[Rtest Gtest Btest]
[correctedRed correctedGreen correctedBlue]=[Rtest Gtest Btest Rtest*Gtest Rtest*Btest Gtest*Btest]*[alpha(1);alpha(2);alpha(3);alpha(4);alpha(5);alpha(6);alpha(7)];
i know the first 2 matrix.
first one C matrix
second one A matrix so,
C=A*[alpha()]
[alpha()]=inv(A'*A)*A'*C;
but inv(A'*A) is infinite because det(A'*A)=0 then i try this
C=[240 240 240; 225 113 0; 13 27 94];
R1=96; R2=181; R3=19;
G1=225; G2=162; G3=63;
B1=220; B2=57; B3=132;
A=[1 R1 G1 B1 R1*G1 R1*B1 G1*B1;
1 R2 G2 B2 R2*G2 R2*B2 G2*B2;
1 R3 G3 B3 R3*G3 R3*B3 G3*B3;];
AA=transpose(A);
T=(inv(AA*A)*AA)*C;
G1=[ones(m*n,1), D, r.*g, r.*b, g.*b];
M=double(G1)*double(T);
then min(M) and max(M) is out of 255 too much such as 500 and -300 so,
M1=(M(:,1)+307).*(250/900);
M2=(M(:,2)+247).*(250/643);
M3=(M(:,3)+206).*(250/544);
result colors are not match the real objects
result is not good again however better than 3 pixel.
source image
result image
some colors are not match such as 2 colorful piece of paper.
how can i improve this method?
also i will try the other methods you suggest.
huseyin kara
huseyin kara on 9 Jul 2012
in your suggestions, my main problem after i run these codes is i get a correction matrix like for 3 pixels but more pixel. when i applied this matrix to the image which i tried to fix, the result values of pixels are too much and too small for rgb colors such as -70 and 700. after i tried to get 0-255 values by addition and divided this -70 and 700 values, the colors were not expected.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!