After previous activities of processing grayscale and binary-type images, this time, color images are handled here specifically true color images which are taken by a digital color camera using its various white balancing (WB) settings.
In a colored digital image, each pixel from it is composed of the three primary spectral colors Red (R), Green (G), and Blue (B) which are overlaid in different proportions. These RGB values are given by the following equations.
From the expressions above, rho corresponds to the spectral reflectance of a surface, S is the spectral power distribution (SPD) of a Planckian light source illuminating the surface and nu is the spectral sensitivity of a color camera in the RGB channels. Meanwhile, K is the normalizing constant or WB constant dependent from the SPD of the light source and spectral sensitivity of the camera, again different in each color channel. The wavelength lambda ranges within the visible spectrum usually from 380 nm to 780 nm.
Initially, an image which includes the three major hues RGB and a known white object is taken by a digital color camera applying its different WB settings. The digital camera used is Fujifilm Finepix with maximum image resolution of 6.3 mega pixels while the WB settings include automatic, fine, shade, fluorescent 1, fluorescent 2, fluorescent 3, and incandescent. The exposure value (EV) of the camera is set to -2 ensuring that the RGB values of each pixel do not exceed the maximum pixel value of 1.
The following set of images are the pictures taken under constant fluorescent light source illumination implementing the 7 WB settings in order of automatic, fine, shade, fluorescent 1, fluorescent 2, fluorescent 3, and incandescent from top to bottom and left to right.
As expected, each WB setting of the camera results to different color rendering of the picture. Hence, the normalizing constant K varies with each WB setting of the camera and thus producing different RGB values in pixels. Of course, the automatic WB setting generates the best rendering of the picture since it automatically selects the most appropriate K values which adjust according to the light source illumination. The fine and shade WB settings are considerably good enough for the rendering while the three fluorescent WB settings approach the blue hue as the number increases from 1 to 3.
The last one which uses incandescent WB is observed to be the most obvious incorrectly balanced image. This is then enhanced using two automatic white balancing (AWB) algorithms.
The first one is the White Patch Algorithm where a patch from a known white object of the unbalanced image is taken and its averaged RGB values are determined. This is why the picture must have a known white object. Then, the RGB color channels of the unbalanced image are divided to the corresponding averaged RGB values of the white patch. The resulting RGB arrays are finally overlaid for the white patch balanced rendering of the wrongly balanced image. Note that the final RGB arrays in saving the rendered image are made sure not to exceed the value of 1 by dividing them to their maximum value even though initially there are no RGB values greater than 1 because of the EV of -2. This is because some RGB values less than 1 are divided to the averaged RGB values from the white patch which are less than them. Therefore, not doing this makes the rendering still incorrectly white balanced.
Shown below is the white patch selected from the picture taken with incandescent WB setting.
Then the following are the original picture and its rendering using the White Patch Algorithm.
The incorrectly balanced image using the incandescent WB setting is now appropriately white balanced using the White Patch Algorithm. The quality is as good as in using the automatic WB setting of the camera.
The second AWB algorithm is called the Gray World Algorithm. Here, the average pixel values of each RGB color channel are obtained. The RGB arrays of the unbalanced image are then divided to the corresponding average RGB values. Hence, this algorithm works even the picture does not have a known white object. Again, in saving the rendered image, the values are clipped to 1 like in the White Patch Algorithm.
The original picture taken with incandescent WB setting and its rendering using the Gray World Algorithm are as follows.
The name of the Gray World Algorithm itself implies the effect when applied to an image. The average values taken from each color channel here represent the RGB values of white however these are already weighted. Hence, when the RGB arrays are divided by these average values, gray which is between white and black becomes the basis of balancing, and thus the image enters the gray world.
As another illustration of the two AWB algortihms, the picture taken with fluorescent 3 WB setting is rendered using these algorithms. First below is the white patch chosen.
The next set of images consists the original picture, its rendering using the White Patch Algorithm, and using the Gray World Algorithm.
It can be observed that the rendered picture taken with fluorescent 3 WB setting using the White Patch Algorithm is almost the same as in the rendered picture taken with the incandescent WB setting. However, the rendering using the Gray World Algorithm in this WB setting is better than in the incandescent type.
For a more conclusive observation, a picture is taken again but this time the objects have colors belonging to a primary hue. Incandescent WB setting is employed here since this is the most inappropriate WB setting for the illumination condition. Some red objects are gathered together and of course a known white object is included in the group.
The white patch selected is shown below.
The following are the original picture, its rendering using the White Patch Algorithm, and using the Gray World Algorithm.
Apparently, the White Patch Algortihm is better than the Gray World Algorithm. This is due to the fact that the picture is indeed white balanced since the average RGB values where the RGB color channels are normalized, come from a known white object. While the Gray World Algorithm just uses the average RGB values of each color channel of the unbalanced image in effect just balancing it to gray. However, the Gray World Algorithm generates good rendering if the WB setting used to take the picture blends well with the illumination condition.
Since I successfully processed some true color images taken with different WB settings of a digital color camera using the two AWB algorithms , I give myself 10/10 in this activity.
I am able to complete this activity successfully through discussions with Gary and Raffy.
Appendix
Below is the Scilab code utilized in this activity.
stacksize(4e7);
imageRGB = imread('imageRGBincan.jpg');
//scf(0);
//imshow(imageRGB);
R = imageRGB(:,:,1);
G = imageRGB(:,:,2);
B = imageRGB(:,:,3);
// White Patch Algorithm
white_patch = imread('white patch RGBincan.jpg');
Rw = sum(white_patch(:,:,1))/length(white_patch(:,:,1));
Gw = sum(white_patch(:,:,2))/length(white_patch(:,:,2));
Bw = sum(white_patch(:,:,3))/length(white_patch(:,:,3));
nR = R/Rw;
nG = G/Gw;
nB = B/Bw;
newimageRGB = [];
newimageRGB(:,:,1) = nR;
newimageRGB(:,:,2) = nG;
newimageRGB(:,:,3) = nB;
//scf(1);
//imshow(newimageRGB);
//imwrite(newimageRGB/max(newimageRGB), 'newimageRGBincan.jpg');
// Gray World Algorithm
Rgray = sum(R)/length(R);
Ggray = sum(G)/length(G);
Bgray = sum(B)/length(B);
ngrayR = R/Rgray;
ngrayG = G/Rgray;
ngrayB = B/Rgray;
newimagegrayRGB = [];
newimagegrayRGB(:,:,1) = ngrayR;
newimagegrayRGB(:,:,2) = ngrayG;
newimagegrayRGB(:,:,3) = ngrayB;
//scf(2);
//imshow(newimagegrayRGB);
//imwrite(newimagegrayRGB/max(newimagegrayRGB), 'newimagegrayRGBincan.jpg');
In a colored digital image, each pixel from it is composed of the three primary spectral colors Red (R), Green (G), and Blue (B) which are overlaid in different proportions. These RGB values are given by the following equations.
From the expressions above, rho corresponds to the spectral reflectance of a surface, S is the spectral power distribution (SPD) of a Planckian light source illuminating the surface and nu is the spectral sensitivity of a color camera in the RGB channels. Meanwhile, K is the normalizing constant or WB constant dependent from the SPD of the light source and spectral sensitivity of the camera, again different in each color channel. The wavelength lambda ranges within the visible spectrum usually from 380 nm to 780 nm.
Initially, an image which includes the three major hues RGB and a known white object is taken by a digital color camera applying its different WB settings. The digital camera used is Fujifilm Finepix with maximum image resolution of 6.3 mega pixels while the WB settings include automatic, fine, shade, fluorescent 1, fluorescent 2, fluorescent 3, and incandescent. The exposure value (EV) of the camera is set to -2 ensuring that the RGB values of each pixel do not exceed the maximum pixel value of 1.
The following set of images are the pictures taken under constant fluorescent light source illumination implementing the 7 WB settings in order of automatic, fine, shade, fluorescent 1, fluorescent 2, fluorescent 3, and incandescent from top to bottom and left to right.
As expected, each WB setting of the camera results to different color rendering of the picture. Hence, the normalizing constant K varies with each WB setting of the camera and thus producing different RGB values in pixels. Of course, the automatic WB setting generates the best rendering of the picture since it automatically selects the most appropriate K values which adjust according to the light source illumination. The fine and shade WB settings are considerably good enough for the rendering while the three fluorescent WB settings approach the blue hue as the number increases from 1 to 3.
The last one which uses incandescent WB is observed to be the most obvious incorrectly balanced image. This is then enhanced using two automatic white balancing (AWB) algorithms.
The first one is the White Patch Algorithm where a patch from a known white object of the unbalanced image is taken and its averaged RGB values are determined. This is why the picture must have a known white object. Then, the RGB color channels of the unbalanced image are divided to the corresponding averaged RGB values of the white patch. The resulting RGB arrays are finally overlaid for the white patch balanced rendering of the wrongly balanced image. Note that the final RGB arrays in saving the rendered image are made sure not to exceed the value of 1 by dividing them to their maximum value even though initially there are no RGB values greater than 1 because of the EV of -2. This is because some RGB values less than 1 are divided to the averaged RGB values from the white patch which are less than them. Therefore, not doing this makes the rendering still incorrectly white balanced.
Shown below is the white patch selected from the picture taken with incandescent WB setting.
Then the following are the original picture and its rendering using the White Patch Algorithm.
The incorrectly balanced image using the incandescent WB setting is now appropriately white balanced using the White Patch Algorithm. The quality is as good as in using the automatic WB setting of the camera.
The second AWB algorithm is called the Gray World Algorithm. Here, the average pixel values of each RGB color channel are obtained. The RGB arrays of the unbalanced image are then divided to the corresponding average RGB values. Hence, this algorithm works even the picture does not have a known white object. Again, in saving the rendered image, the values are clipped to 1 like in the White Patch Algorithm.
The original picture taken with incandescent WB setting and its rendering using the Gray World Algorithm are as follows.
The name of the Gray World Algorithm itself implies the effect when applied to an image. The average values taken from each color channel here represent the RGB values of white however these are already weighted. Hence, when the RGB arrays are divided by these average values, gray which is between white and black becomes the basis of balancing, and thus the image enters the gray world.
As another illustration of the two AWB algortihms, the picture taken with fluorescent 3 WB setting is rendered using these algorithms. First below is the white patch chosen.
The next set of images consists the original picture, its rendering using the White Patch Algorithm, and using the Gray World Algorithm.
It can be observed that the rendered picture taken with fluorescent 3 WB setting using the White Patch Algorithm is almost the same as in the rendered picture taken with the incandescent WB setting. However, the rendering using the Gray World Algorithm in this WB setting is better than in the incandescent type.
For a more conclusive observation, a picture is taken again but this time the objects have colors belonging to a primary hue. Incandescent WB setting is employed here since this is the most inappropriate WB setting for the illumination condition. Some red objects are gathered together and of course a known white object is included in the group.
The white patch selected is shown below.
The following are the original picture, its rendering using the White Patch Algorithm, and using the Gray World Algorithm.
Apparently, the White Patch Algortihm is better than the Gray World Algorithm. This is due to the fact that the picture is indeed white balanced since the average RGB values where the RGB color channels are normalized, come from a known white object. While the Gray World Algorithm just uses the average RGB values of each color channel of the unbalanced image in effect just balancing it to gray. However, the Gray World Algorithm generates good rendering if the WB setting used to take the picture blends well with the illumination condition.
Since I successfully processed some true color images taken with different WB settings of a digital color camera using the two AWB algorithms , I give myself 10/10 in this activity.
I am able to complete this activity successfully through discussions with Gary and Raffy.
Appendix
Below is the Scilab code utilized in this activity.
stacksize(4e7);
imageRGB = imread('imageRGBincan.jpg');
//scf(0);
//imshow(imageRGB);
R = imageRGB(:,:,1);
G = imageRGB(:,:,2);
B = imageRGB(:,:,3);
// White Patch Algorithm
white_patch = imread('white patch RGBincan.jpg');
Rw = sum(white_patch(:,:,1))/length(white_patch(:,:,1));
Gw = sum(white_patch(:,:,2))/length(white_patch(:,:,2));
Bw = sum(white_patch(:,:,3))/length(white_patch(:,:,3));
nR = R/Rw;
nG = G/Gw;
nB = B/Bw;
newimageRGB = [];
newimageRGB(:,:,1) = nR;
newimageRGB(:,:,2) = nG;
newimageRGB(:,:,3) = nB;
//scf(1);
//imshow(newimageRGB);
//imwrite(newimageRGB/max(newimageRGB), 'newimageRGBincan.jpg');
// Gray World Algorithm
Rgray = sum(R)/length(R);
Ggray = sum(G)/length(G);
Bgray = sum(B)/length(B);
ngrayR = R/Rgray;
ngrayG = G/Rgray;
ngrayB = B/Rgray;
newimagegrayRGB = [];
newimagegrayRGB(:,:,1) = ngrayR;
newimagegrayRGB(:,:,2) = ngrayG;
newimagegrayRGB(:,:,3) = ngrayB;
//scf(2);
//imshow(newimagegrayRGB);
//imwrite(newimagegrayRGB/max(newimagegrayRGB), 'newimagegrayRGBincan.jpg');