When imaging using a detector (i.e., a camera), the amount of light detected depends on the sensitivity of the detector, the intensity of the illuminating light and reflectance properties of the object. Similarly in digital imaging, a pixel is compose of different proportions of red, green and blue values overlaid in different proportions. The equation below describes how the RGB values are obtained. It is an integral product of the reflectance spectra of the object, spectral power distribution of the light source and camera sensitivity.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4SlA0scU1PZHzlZnexvLbRZN7yPw5V1IPWc0Pg1LvkgdddIAeCTwdr7BvOeGyjSvtWQ3myX2Cmt-SFEPLiimD4Pb1RcPgle875FXWkLVHkopxjQtb4I5ANeVoITGvjM5PKdTQEHG9OIY/s400/equation1.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZHcYkYfoFyMPmA3FwPJVHU-J0Moain2JXk0eYYTQ1XQDdfXd-ANsYaaE_fxCjAha_Kngh5Q2KwEvd_JrI-j1mrrnD7iQP5o7Q9i0khfK9ajCpVZ_FFQVkJ-SCLCJr_8dNp6QLEAkdagk/s400/equation2.png)
In this activity, we're going to apply two algorithms to achieve white balancing. They are the White Patch Algorithm and Gray World Algorithm.
White Patch Algorithm
Observe from equation above that the K's are essentially the inverse of the camera output when shown with a white object. Thus white balancing here is just dividing the raw camera output by the image of the white object. This is precisely the White Patch Algorithm.
Gray World Algorithm
In the gray world algorithm, it assumes that the average color of the world is gray. Taking the average of the red, green and blue channels can then serve as white balancing constants for the red, green and blue channels respectively. For a certain channel, when you divide the pixel values by the average value of that channel, it is probable that many pixels would contain values greater than 1 (i.e., if pixel value > ave. pixel value). By normalization, (divide by the max) we can lower this value to 1. However, this has the overall effect of darkening the image. As compared to the white patch which divides each channel by the pixel value of the 'white', most probably contains the highest pixel value of the image.
In summary, the algorithm is as follows
- read the image
- obtain the constants for white balancing
- white patch algorithm - obtain a white patch in the image and average the pixel values of this patch for each channel. This will serve as the white balancing constants
- for the gray world - obtain the average of each channel and use as the white balancing constants
- note that before we do the averaging, we remove all pixels that are saturated.
- divide each channel by the corresponding white balance constants
- normalize the image by dividing the image by its maximum. Note that we avoided the use of clipping the image for in the gray algorithm, it is probable that for each channel many pixel values are greater than the average pixel value making the image look saturated when clipped.
Below are images obtained from different lighting conditions and corrected using the white patch algorithm and the gray world algorithm. It is arrange such that each column represents the white balancing used by the camera while for each row is the corresponding algorithm used. Raw means without the use of the white and gray algorithm.
The picture below was taken around 9AM in the CSRC garden. (Cloudy condition)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5btCxnJr3Zv2CXcvzsh_78jAWOZgVXrij0fOv5EgECFiR7iJkIWfNZupWRnnQcRWU1OnS8ErIdZcgL0by4f22anXPCA18De1dZGJlZd6N5SmEfDEqFsHdoBxzEf2ACLYk2qJutN09sSA/s400/GardenSumTrue.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuzDocs61NUmMECvtdPtIlRcnS-BogK9_sl25h5XPdvrsUAbCD3Eh89LJeYZusYyvaHOfI5eaxL3O5LFHJt5JSPJ22QpUYxBG6Vq7kdFDeNLmFcAc9SAUf1rPe5A-UolPSqTCeMrdWFIg/s400/GardenSumFalse.jpg)
We tried the algorithm for different lighting conditions and the results are seen below.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUENXi9K96IzVp52Fk4HJw8RwlmtN912i8OhEsASzc7icR3becjkwHoKpZ52POuNvB7Xn6mI7iOMzQLe37z4Rn-UsxNfDuu4_J2m6TKnqGbjjI1ieRIkRDAeEW_EUI6I6YvmGE79aBfXI/s400/TableSumFalse.jpg)
Another image taken inside the room (i.e., fluorescent lighting condition)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj82jrr7OG0LcHxxTCYtRSrgwdxphsowfZbpJrIdommzmCz98GlBk95BBZmdomjdzomtC3HpyS0gA0BDpBTpNi3cjEo9BH_fF0oBlFq5ba_z-LwH8UKUg09r50JQHZ6wrcyj-WZUMDLy_4/s400/InsideSumFalse.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA3jttOssqu-goGH-5BhuQALawHN09zyBmR9WI0wa495MFWPwDx7CZH_iGlT4YzoikWw6ohMIiBbL0TbgmBDGnX2O4ntTz03GKB9UI85Sn9ihT0uohMeDfOCb0iss5QRDjBDZw6Xcb3ig/s400/InsideSumTrue.jpg)
Another image inside the room of different hues of red. (fluorescent lighting conditions)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpv9ppFUKJEqyu5gqjfkHUb2AUf103HYr5BUNxOgmWnxGa8KZTSTkk2MgyTses7vGZ7thtY3FnyjHndi5W6S-9bnEw7hNjawWkahazc2iqv_N0W_8aZVp89-tzJfGjKtnbSSKCeWkHxUQ/s400/HueRedFalse.jpg)
Generally, I think that the gray world algorithm is much convenient and sometimes better compared to the white patch algorithm. Note that unless, we can obtain an algorithm for finding the white patch image in the white patch algorithm, our reconstruction would always depend on the patch that we're going to use. As compared to the gray world algorithm which makes use of averaging. The drawback of gray world algortithm is that it makes the image look darker. However, this can be remedied by using contrast enhancement, i.e., use an exponential cumulative distribution function to lighten up the image.
In this activity, I give myself a grade of 10, for obtaining the reconstructions and explaining the results
Acknowledgement
I would like to acknowledge Kaye for lending me the McDo stuff toy and Carmen for the blue notebook.
References
[1] App Physics 186 Activity 11 Manual
No comments:
Post a Comment