Thursday, September 23, 2010

Activity 12 - Color Camera Processing


An array of pixels each having red, green and blue light overlaid in various proportions produces a colored digital image. The integral of the product of the spectral power distribution of the incident light source S(λ), the surface reflectance ρ(λ) and the spectral sensitivity of the camera η(λ) is the color captured per pixel by a digital color camera. If the color camera has spectral sensitivity ηR(λ), ηG(λ) , ηΒ(λ) for the red, green and blue channels respectively, then the color of the pixel is given by

Equation 1

where Ki is a balancing constant equal to the inverse of the camera output when shown a white object (ρ(λ) = 1.0). These two set of equations explain why sometimes the colors captured by a digital camera appear unsatisfactory.

Equation 2

Nowadays, colored digital cameras have increasing number of options and settings that can be set to the camera to capture the appropriate or desired conditions. One particular setting in the camera that affects the appearance or appreciation of the captured image is the White Balance Setting or WB. Different setting conditions may be applied such as sunny, cloudy, incandescent, fluorescent lamp. For beginners, most of the time, they set the WB to an automatic setting. In this activity, two popular algorithms were imposed to the images to achieve automatic white balancing.

In the White Patch Algorithm, an image is captured using an unbalanced camera and use the RGB values of a known white object divider. On the other hand, the Gray World Algorithm assumes that the average color of the world is gray. The balancing constant is determined by calculating the average red, green, and blue value of the captured image and utilize them.

Figure 1 shows an image of an ensemble of colorful objects taken under different white balanced conditions. The images were taken with an EV of -2 to ensure that the processed images will not go beyond the maximum pixel value. The two algorithms were implemented and it was observed that the White Patch Algorithm produced the more accurate and pleasing appearance of the wrongly balanced captured image. The two algorithms were also done to an image with the same hue (see Figure 2).


(a) (Left)Taken under Cloudy White Balance.
(Middle) Corrected with White Patche Algorithm.
(Right) Corrected with Gray World Algorithm.
(a) (Left)Taken under Incandescent White Balance.
(Middle) Corrected with White Patche Algorithm.
(Right) Corrected with Gray World Algorithm.
(a) (Left)Taken under SunnyWhite Balance.
(Middle) Corrected with White Patche Algorithm.
(Right) Corrected with Gray World Algorithm.
Figure 1. Ensemble of objects with different hues

(a) (Left)Taken under Cloudy White Balance.
(Middle) Corrected with White Patche Algorithm.
(Right) Corrected with Gray World Algorithm.
(b) (Left)Taken under Incandescent White Balance.
(Middle) Corrected with White Patche Algorithm.
(Right) Corrected with Gray World Algorithm.
(c) (Left)Taken under Sunny White Balance.
(Middle) Corrected with White Patche Algorithm.
(Right) Corrected with Gray World Algorithm.
Figure 2. Ensemble of objects with the same hue

Self-evaluation:
Credits:

Appendix: Source code
stacksize(100000000);

PATH = 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 12\';
name = 'EV-2_incandescent'; // automatic, cloudy, fluorescent, incandescent, sunny

I = imread(strcat([PATH,name,'.jpg'])); //wrongly balanced image

//White Patch Algorithm
Rw = I(450,850,1); //white value
Gw = I(450,850,2);
Bw = I(450,850,3);

R = I(:,:,1)/Rw;
G = I(:,:,2)/Gw;
B = I(:,:,3)/Bw;

R(find(R>1)) = 1;
G(find(G>1)) = 1;
B(find(B>1)) = 1;

I2 = [];
I2(:,:,1) = R;
I2(:,:,2) = G;
I2(:,:,3) = B;

//scf(); imshow(I2,[]);
imwrite(I2,strcat([PATH,name,'_wpa_image','.jpg']));


//Gray World Algorithm
//Rw = sum(I(:,:,1))/length(I(:,:,1));
//Gw = sum(I(:,:,2))/length(I(:,:,2));
//Bw = sum(I(:,:,3))/length(I(:,:,3));

Rw = mean(I(:,:,1));
Gw = mean(I(:,:,2));
Bw = mean(I(:,:,3));

R = I(:,:,1)/Rw;
G = I(:,:,2)/Gw;
B = I(:,:,3)/Bw;

R(find(R>1)) = 1;
G(find(G>1)) = 1;
B(find(B>1)) = 1;

I3 = [];
I3(:,:,1) = R;
I3(:,:,2) = G;
I3(:,:,3) = B;

//scf(); imshow(I3,[]);
imwrite(I3,strcat([PATH,name,'_gwa_image','.jpg']));


No comments:

Post a Comment