When taking pictures, it sometimes happens that colors are not rendered correctly. For instance, a white object came become bluish or yellowish in the picture. In order to correct render the colors in the scene we are capturing, white balance is performed. “White balancing” is the process of setting the supposedly white portion of the image as white. In this activity, we performed white balancing using two methods: by 1) the Reference White Algorithm and 2) the Gray World Algorithm.
In the Reference White Algorithm, the red (R), green (G), and blue (B) pixel values of the image are divided by the R, G, B values of the the “white” portion respectively. Values greater than 1.0 are set to 1.0. Shown below is a picture of several objects of different colors; it was taken inside the classroom, with a camera setting of “incandescent”. After it is the “white balanced” picture using the Reference White Algorithm.
Before:
After:

The white balancing was able to remove the “blue cast” in the image. (Note: The paper is now white!)
The second method is the Gray World Algorithm. In this method, the R, G, and B values of the image are each divided by the average of the R, G, and B values, respectively. Again, if the values are greater than 1.0, they are clipped to 1.0. Using the same unbalanced image, the before and after shots using the Gray World Algorithm are shown below:
Before:
After:
For Gray World, the “blue cast” was again removed! On closer inspection, I noticed that the Reference White Algorithm did a better job because the paper is whiter and the other colors less dark.
Here is another example. The same scene (same objects, still inside the classroom with the same light source) has been captured with a camera setting of “cloudy.” The Before and After shots for both algorithms are shown below:
Before:

After (using the Reference White Algorithm):

After (using the Gray World Algorithm):

The “yellow cast” has been removed from the 2 “After” images; however, using the Reference White algorithm is better. The paper is “whiter” as compared to that of the Gray World balanced image, which is a bit bluer. The “After” picture from the RW algorithm produced the closest rendition of the original colors of the objects.
For the next part of the activity, objects of the same hue were captured in a single image using the “wrong setting” and then white balanced. The image has several leaves of different colors; it was pictured outdoors so the illumination is daylight, but the setting was “incandescent.” The Before and After images are shown below.
Before:

After (using the Reference White Algorithm):

After (using the Gray World Algorithm):

Visually, the RW balanced image seems to have better green hues and the Gray World image has a bit of a reddish and bluish tinge.
Overall, the Reference White Algorithm seems to give a more balanced image, color-wise.
I give myself a grade of 10 for this activity because I was able to perform white balancing using the 2 algorithms.
Thank you, Aiyin and Beth for taking the pictures, Mark Leo for obtaining the leaves, and Rica and Benj for the tip re: clipping the values to 1.0.
————————-
The following was my code for this activity:
im=imread(‘i-cloudy.jpg’);
w=imread(‘i-cloudy-white.jpg’);
Rw=mean(w(:,:,1));
Gw=mean(w(:,:,2));
Bw=mean(w(:,:,3));
//Reference White
imw(:,:,1)=im(:,:,1)/Rw;
imw(:,:,2)=im(:,:,2)/Gw;
imw(:,:,3)=im(:,:,3)/Bw;
Mw=max(max(max(imw)));
newimw=imw./Mw;
//im(find(im>=1)) = 1
imwrite(newimw,’i-cloudy-rw.jpg’);
//Gray-world
Rwg=mean(im(:,:,1));
Gwg=mean(im(:,:,2));
Bwg=mean(im(:,:,3));
ig(:,:,1)=im(:,:,1)/Rwg;
ig(:,:,2)=im(:,:,2)/Gwg;
ig(:,:,3)=im(:,:,3)/Bwg;
Mg=max(max(max(ig)));
newimg=ig./Mg;
//im(find(im>=1)) = 1
imwrite(newimg,’i-cloudy-gw.jpg’);