For this activity, I will be using the raw image (Fig. 1a) I took during the FST Week Concert at the College of Fine Arts. I felt this would be a good image to work on since there is a significant and discernible color cast due to the lighting of the venue. The photo was taken with auto white balance (which didn’t do a really good job of white balancing).
I imported the original image as uint8
. However, when performing
any manipulation, I converted it first to float64
before casting
it back to uint8
for displaying and saving purposes. Upon
examination, I realized it was futile to perform contrast stretching since the
maximum value of each channel was already 1.0
. Further reading
brought me to an article [1], where we can discard a certain percentile
from the low and high ends of the histogram
and stretch the remaining bins to fill the full range, according to
where C
refers to the channel being manipulated.
The high and low values refer to the p
th percentile of histogram values that are set as the upper and lower
thresholds, respectively. This is actually the algorithm used by GIMP’s auto
white balance. We can see from the resulting image in Fig.Â
1b that the reddish color cast has generally been
removed, and the guitarist’s skin tone looks much more realistic.
This algorithm assumes that the average color of the image is gray. The pixel values are manipulated according to [2]
where <I>
is the overall
average and C
is the
channel average. The result of this manipulation is shown in Fig.Â
1c. Note that the image is at roughly the same exposure
level as the original because we did not perform contrast stretching on this one,
but the white balance is similar to that of contrast stretching.
This method is similar to how the White Balance Eyedropper Tool in image processing programs such as Lightroom or Photoshop work. Fig. 2 shows the location where I extracted a patch that is supposed to be white (upper 12th fret marker on the guitar). The result is shown in Fig. 1d. We can see that the guitarist’s skin tone still looks realistic, and the background is now a warmer white as compared to the previous algorithms.
Figure 1: Image enhanced using different algorithms (top) and their respective histograms (bottom).
Figure 2: Extracted white patch location. The size of the bounding box has been exaggerated for easy location. The object of interest is the fret marker on the upper portion of the box.
To combine everything, [3] proposes a method that modifies the gray world and contrast-stretching algorithms and uses a weighted sum of them to perform automatic white balancing. The modified gray world algorithm is
and the modified contrast-stretching is
where C_{low}
and C_{high}
are the lower and upper
thresholds, respectively, and I_{min}
and I_{max}
are the overall maximum and
minimum pixel values, respectively. The image intensity values are scaled
according to the thresholds and not the extrema as to avoid over-stretching.
The weight is then calculated as
where \langle C_b \rangle , \langle C_r \rangle
are calculated by converting the image to YCrCb and
taking the averages of the C channels, and \sigma
are the standard deviations of the
RGB channels. The paper stated that n
was
a constant taken to be 200 and was obtained experimentally, but do not
elaborate on how exactly it was obtained. Essentially, w
is the weight of the heavy color cast.
The final image is obtained by
where CS
and GW
are the images enhanced
using the modified contrast stretching and gray world algorithms,
respectively. The result is shown in Fig. 3c
alongside the other algorithms for comparison. Because
of the heavy red color cast in the original image, the CS portion of the algorithm
is given a greater weight, so the final image looks more like the CS-corrected
image.
Figure 3: Comparison of the different auto white balance algorithms.
S. Wang, Y. Zhang, P. Deng, and F. Zhou, Fast automatic white balancing method by color histogram stretching, 4th International Congress on Signal and Image Processing, 979-983 (2011).
S. C. Tai, Y. Y. Chang, and C. P. Yeh, Automatic White Balance algorithm through the average equalization and threshold, in [2012 8th International Conference on Information Science and Digital Content Technology (ICIDT2012), vol. 3, 571-576](http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6269338&isnumber=6269316, (2012).