Thursday, August 6, 2009

ACTIVITY 11 - Color Image Processing

Primarily, the objective of this activity is to be able to enhanced an image that is wrongly white-balanced. Images of an ensemble of colorful objects were captured using a digital camera with different white balance settings.


White Balancing Setting: Fire

White Balancing Setting: Shade

White Balancing Setting: Fluorescent-1

White Balancing Setting: Fluorescent-2

White Balancing Setting: Fluorescent-3

White Balancing Setting: Incandescent

Different white balancing settings resulted to different qualities of images. The Fire and Shade are almost the same resulting to a slightly darker image than what was taken. Fluorescent-1 settings resulted to a brownish image. Fluorescent-2 and Fluorescent-3 produced shades of blue images. The Incandescent setting produced a more bluish image. Obviously, this image is wrongly balanced.

White Patch Algorithm

Using the image captured by the camera in Incandescent setting, the White Patch algorithm was implemented. First, a patch of an white object in real world which appears differently in the image was cropped.
The RGB values of pixels belonging to this white object: Rw, Gw, and Bw was taken. And then, all pixels in the red layer, green layer and blue layer of the image was divided by their corresponding Rw, Gw and Bw. This was implemented with the code below.

image = imread('filename.jpg');
w = imread('wpatch.jpg');

rw = sum(w(:,:,1))/length(w(:,:,1));
gw = sum(w(:,:,2))/length(w(:,:,2));
bw = sum(w(:,:,3))/length(w(:,:,3));

nr = image(:,:,1)/rw;
ng = image(:,:,2)/gw;
nb = image(:,:,3)/bw;


The resulting image was then displayed as shown below.
Compared with the wrongly white balanced image, the resulting image is less brighter as the bluish color decreases. White hues that appear bluish in the wrongly balanced image now appear more white. The White Patch algorithm assumes that the maximum response of the image is caused by the white patch. Thus, by dividing each channels of the image with the constants determined from the white patch we are essentially bringing back true colors of the image.

Gray World Algorithm

The Gray World algorithm was also implemented on the image captured using Incandescent setting. For this algorithm, the R, G and B layers of the unbalanced image were averaged and let to be Rw, Gw, and Bw, respectively. Then the original R, G and B layer values were divided by their corresponding constant.

image = imread('filename.jpg');

rw = sum(image(:,:,1))/length(image(:,:,1));
gw = sum(image(:,:,2))/length(image(:,:,2));
bw = sum(image(:,:,3))/length(image(:,:,3));

nr = image(:,:,1)/rw;
ng = image(:,:,2)/gw;
nb = image(:,:,3)/bw;


The resulting image was displayed below.
The image looks old after the implementation of Gray World algorithm. The blue hues also lessen and the white hues look grayish. The Gray World algorithm assumes that the average of the colors on each channels of the image taken in normal light is gray. Using the Incandescent setting in capturing the image, we have disrupted the Gray World assumptions. We force the Gray World assumption again by dividing each channel by their average. Thus, we are reaquiring the true color of the image in real world.

Doing both algorithm with the other images will result to the same image as shown above for white patch and gray world algorithm. Implementing both algorithms is reacquiring the true colors of the image based on certain assumptions. However, it turns out that the White Patch is better than the Gray World algorithm.
------------------------------------------------------------------------------------------------------------
In this part of the activity, the white patch and gray world algorithm were implemented on an image of objects with the same hue (in this case, green).
The image above was obviously wrongly white balanced. After implementing the two algorithm as in above procedure, the resulting images were shown below.

White Patch Algorithm

Gray World Algorithm

The white patch algorithm uses the white wall at the background of the image. Clearly, the original color was reacquired using white patch algorithm. Gray world algorithm allows the removal of the bluish hue in the image. However, the image becomes slightly reddish. This is because the unbalanced image mainly composed of green hues.

For this activity, I will get 10/10. By producing images from each algorithm, I was able to understand how the white patch and gray world algorithm assumes the color of the real world. Applying these algorithm on an image captured with colored lighting (i.e. Incandescent white balancing setting ) will reacquire the true colors of the image. However, after finishing the activity, it turns out that for the images used, the White Patch algorithm assumes a better color of the real world. I acknowledged Gilbert for discussing the activity with my and for lending me pictures he captured.

1 comment: