[Home]

Gray World Algorithm


Basic Concepts

There are many algorithms have been developed for color balancing and in this project we investigate two of them, which are Gray World and Perfect Reflector. In this section we present Gray World algorithm first and we'll analyze Perfect Reflector algorithm in the next section.

Gray World algorithm is based on the assumption that given an image with sufficient amount of color variations, the average value of the R, G, and B components of the image should average to a common gray value. This assumption is held very well: in a real world image, it is usually true that there are a lot of different color variations. The variations in color are random and independent, the average would converge to the mean value, gray, by given an enough amount of samples. Color balancing algorithms can apply this assumption by forcing it's images to have a common average gray value for it's R, G, and B components. In the case an image is taken by a digital camera under a particular lighting environment, the effect of the special lighting cast can be removed by enforcing the gray world assumption on the image. As a result of approximation, the color of the image is much closer to the original scene.

In our project, we take two hundred and fifty two sample images to evaluate this algorithm. We implement one method of Gray World Assumption enforcement: find the average values of the image's R, G, and B color components and use them to determine a common gray value for the image. Each color component is then scaled according to the amount of it's deviation from this gray value. We can obtain the scale factors by simply dividing the gray value by the appropriate average of each color component. By forcing the gray world assumption on the image again, we are in essence, removing the colored lighting to reacquire the true colors of the original. (See the 2nd reference in the list)


Experiments

Based on the basic concepts mentioned above, we implement Gray World algorithm by GrayWorldFun.m.

We do two experiments to test Gray World algorithm:

  • Experiment 1

    The first experiment takes 252 color patch images generated with background colors and target colors that evenly distribute through the whole spectrum visible to human. The goal of this experiment is to understand what are the effects of Gray World color balancing algorithm over the whole spectrum visible to human eyes, and it helps us to analyze color balancing algorithm completely. This experiment is done by GrayWorldTest1.m

  • Experiment 2

    To give an intuitive sense of the effects of color balancing algorithm to real images, we do the second experiment that tests the real image of Stanford Tower without and with a bright patch. In this experiment, the Stanford Tower image without the bright patch is the original image taken by the camera. We add a bright patch to the original image to generate the second image. Then inverse monitor gamma correction is done for both images. The process of preparing the test images is done by RealImage.m.

    Here we test the second image to compare the effects of Gray World and Perfect Reflector color balancing algorithm. We will see the reason to choose this pair of images as the test images after we introduce the basic concepts of Perfect Reflector algorithm in the next section: Perfect Reflector Algorithm. This experiment is done by GrayWorldTest2.m

    We take the following steps for the above two experiments to test Gray World algorithm:

    1. Read in the input images, and convert them to RGB if they are not.
    2. Take R, G, & B values of the input images to run the function for Gray World algorithm and get the R, G & B results.
    3. Write the results to the output images.


    Output Images

  • Experiment 1

    Output Images of Gray World Color Balancing Algorithm:




  • Experiment 2

    Stanford Tower without bright patch

    Stanford Tower with bright patch

    Original Image

    Original Image

    Inverse Gamma Corrected Image

    Inverse Gamma Corrected Image

    Gray World output

    Gray World output

    Camera Output

    Camera Output


    As we can see, since Gray World algorithm scales the R, G & B values of the input images by the average of R, G & B values relative to the average of gray value, adding a bright patch does not bring in any visible difference comparing to the output image without the bright patch.

    trek@alumni.stanford.edu
    lihui@leland.stanford.edu