Simulation

I wrote the following Matlab implementation of the algorithms we have discussed so far

  • doGrayWorld.m
    This Matlab function takes in a tiff image, and scales its red, green and blue components to make the gray world assumption hold.

  • doPerfectReflector.m
    This exploits the perfect reflector assumption to correct the incoming tiff image. It locates the specular color by finding the pixel with the greatest (R+G+B) value.

  • doHybrid.m
    Initial test-runs convinced me that the gray world assumption algorithm tends to overcorrect its images (bright regions become too bluish) whereas the perfect reflector assumption algorithm tends to undercorrect (the yellowish cast remains although specularities appear white). This led me to develop the following hybrid color-balancing algorithm which uses as its scale factors a linear combination of the factors derived from the gray world assumption, and the same factors derived from the perfect reflector assumption. The weights given to each set of factors depends on each pixel's (R+G+B) as shown in the graph below. This combination of weights ensures that the specularities in the image will be rendered white, and that the darker regions of the image are properly balanced using the gray world assumption.
  • Figure 1: Choosing a linear combination between two sets of factors

     

    Comparison of Results

    I ran all three scripts on four different test images. The images that you see in-lined with the rest of this page are jpeg-compressed, resized versions of the originals. To download the original tiff files, click on the image labels.

  • lily.tif
  • This picture, taken from Bryan Peterson's Understanding Exposure was photographed using the Sony digital camera. Compared to the original picture in the book, the camera's rendition is quite yellowish and somewhat desaturated.

    Original image

    Corrected with gray world assumption

    Corrected with perfect reflector assumption

    Corrected with hybrid scheme

    This simulation illustrates the danger of applying the gray world assumption blindly without first checking to see if there is enough color variation in the original image for this assumption to hold. In this case, there is so little blue in the original image that trying to equalize the blue average with the reds and greens results in an image that unacceptably dark. Since digital cameras do not encounter this problem in general, cameras that use the gray world assumption probably survey the color distribution of the raw image to decide if the assumption will hold or not before applying any color-balancing.

    The perfect reflector assumption seems to do little for this image because the bright spots along the glossy stalks are almost white.

    The hybrid color-balancing scheme suffers from the same problem as the gray world assumption algorithm of trying to boost non-existent blue shades in the original image. However, the mixing with the perfect reflector scale factors makes the effect less severe.

     

  • intense.tif
  • I found this poorly color-balanced image lying around in the class directories and decided to use it as a test image. The original image has a very strong greenish-yellow cast.

    Original image

    Corrected with gray world assumption

    Corrected with perfect reflector assumption

    Corrected with hybrid scheme

    Once again, the gray world assumption fares poorly because of the lack of blue in the subject. As a result, it forces the subject to take on an unnatural blue cast. The perfect reflector seems to have little effect on the image because the brightest region, which is the reflection of the fluorescent lighting on the glass, is practically saturated out at white. The hybrid scheme, in my opinion, gives the best results in this case. The yellow cast is gone, and the wall now appears white. However, in removing the yellow from the image, the algorithm has the awful side effect of desaturating the yellow from the subject's shirt as well.

     

  • tulips.tif
  • This is another picture we took from Bryan Peterson's Understanding Exposure using the Sony digital camera. The original image used here has a severe magenta cast.

    Original image

    Corrected with gray world assumption

    Corrected with perfect reflector assumption

    Corrected with hybrid scheme

    The image corrected using the gray world assumption no longer has the magenta cast. However the algorithm overcorrects at the brighter regions of the image, causing the sky to appear unacceptably greenish. It also suppresses the reds of the tulips to such as large degree that the tulips appear brownish and dull.

    Using the perfect reflector assumption, we manage to remove the some of the magenta from the sky; the clouds in the image now look white. Nevertheless the magenta cast still pervades much of the rest of the image.

    Again, the hybrid scheme produces the most decent results. The sky is a pretty blue, and the green stalks, overwhelmed by magenta in the original image, now appear distinctly green. The algorithm, unfortunately, performs disappointingly at bringing out the red tones of the tulips. It inherits this defect from the gray world assumption algorithm.

     

    Comments

  • The gray world assumption seems to push the colors in an image from one extreme to another. However I believe that this algorithm can still be used to good effect if the camera takes into consideration the color distribution of the original image and adjusts its scale factors accordingly. For instance, the camera should multiply its scale factors by a number between 1/(original scale factor) and 1 depending on range of colors in the original image before using them to color-balance. If there is little color variation, use 1/(original scale factor) * (original scale factor) = 1 as a scale factor, which is to say, do not attempt to color-balance the image.
  • The perfect reflector assumption does not work well in practice because the camera often renders the brightness parts of the image white due to its limited contrast range. However, I would expect this technique to give good results under relatively dim light conditions where the color of subject's specularities can be accurately captured by the camera's CCD sensors.
  • The hybrid scheme seems to give good results on the whole, but its behavior seems somewhat unpredictable.
  • back