The basic idea of colour constancy algorithms is two fold: Firstly, to determine an estimation of the white point in an image, which reects the illuminant's properties (its colouration);
4.2. COLOUR CONSTANCY ALGORITHMS 43 Secondly, to compensate for the colour cast introduced by the illuminant. As a result the image will be normalised towards a more neutral representation, in a way similar to our human visual apparatus, performing a (more robust) colour constant perception. Usually, the white point also inuences the brightness and contrast in the process of the compensation, yielding a better dynamic range of the image.
Due to the focus towards a general comparison towards the viability, and an estimation of inuences on the working colour space, only two classic members of the colour constancy family have been implemented: The (White Patch) Retinex algorithm and the Grey World Assumption as outlined by Marc Ebner [1]. These algorithms have got their limitations, but they have been well known for a long time and should therefore serve as a good example. To ease comparability of the algorithm modications, we are focusing on uniformly illuminated scenes only.
These colour constancy algorithms are based on the estimation of a white point by inspecting image characteristics. The white point is used to transform the image pixels' colour tuples to a corrected representation. For the transformation we are assuming a linear relationship between the response of the sensor and the value of a pixel's colour channel. As most RGB encoded images are encoded in the sRGB colour space (strictly speaking being R0G0B0), the colour tuples are encoded with a gamma value. This encoding is performed through a nonlinear operation used to code and decode the tristimulus values. In the simplest case this can be expressed as a power-law transformation with an exponent approximation of γ ≈ 2.2. Before applying any algorithms, this transformation must be un-done to
transform theR0G0B0 to RGB.
4.2.1 White Patch Retinex
The Retinex algorithm relies on having a bright patch somewhere in the image. The idea is, that this patch reects the maximum intensity of light possible for each band. Assuming that we are dealing with approximate Lambertian reection, this will be the colour of the illuminant (interface reection in Fig. 2.6 of Sect. 2.2.1). Once a bright patch has been located, its colour value can be used for an estimate of the white point.
Practically, instead of looking for a bright patch (or white patch) one determines the maximum of each band over all pixels. Problems arise with some noisy pixels, (single) white pixels, or clipped pixels (the colour channel value of a pixel exceeds the encoding maximum, and is therefore restricted to the maximum, e. g. 255). To increase robustness a cuto value is introduced, using the value at a certain cuto percentage o the top. The colour bands are re-scaled using this white point estimation.
The listing in Fig. 4.1 outlines the basic implementation of the White Patch Retinex algorithm. First, the illuminant is estimated through determining a white point of the lightest values in each channel. In a second step, the pixel values of the image are adapted to this estimated white point. The implementation is simplied in the point, that it uses
1 number_of_pixels = pixels in image
2 estimated_illuminant = [0,0, 0.0, 0.0]
4 # Estimating the illuminant.
5 for each colour channel in [R, G, B]:
6 sorted_by_value = all colour tuples of channel sorted by value
7 cutoff_index = (1.0 - PERCENTAGE) * number_of_pixels
8 max_value = sorted_by_value[cutoff_index]
9 estimated_illuminant[channel] = max_value
11 # Transformation for estimated illuminant.
12 for each pixel in pixels of image:
13 for each colour channel in [R, G, B]:
14 pixel[channel] = pixel[channel] / estimated_illuminant[channel]
Figure 4.1: Basic implementation of the White Patch Retinex algorithm operating on RGB colours. PERCENTAGE= 0.04 for white point estimation as described by Ebner.
the estimation of a white point only, and disregards the potential computation of a black point. The reason for this is that it becomes more comparable with the implementation of the Grey World Assumption (see below), which also only works on the determination of one parameter only.
4.2.2 Grey World Assumption
According to the Grey World Assumption, most scenes are suciently complex regarding their colour distribution. Therefore, one can assume that, on average, the world is grey. An image, showing a suciently large number of dierent colours can be assumed as being grey as well.
The space average colour of the image therefore can be used to estimate the illuminant. The white point is determined by scaling the average colour with the maximum luminance. As with the White Patch Retinex implementation (Sect. 4.2.1), for the maximum determi- nation also a cuto percentage is used for robustness reasons. All colour channels (RGB) will be scaled with the corresponding channel value of the white point.
The listing in Fig.4.2outlines the basic implementation of the Grey World Assumption algorithm. First, the illuminant is estimated by the average colour of the image, and the image's pixel values are corrected by this average. In a second step, the pixel values are re-scaled by a value derived from the new maximum luminances. This is necessary as the intensities are boosted too much after correcting with the average channel values. The implementation described by Ebner [1] computes the luminance as an arithmetic mean of the three channels (R, G and B), giving particularly the red and blue channel too much weight. The weights in line 8 have been used to account for the channels' intensity contribution in the D65illuminant used in sRGB colours. This computation of the pixel's luminance seems
4.3. ALGORITHM MODIFICATIONS 45
1 number_of_pixels = pixels in image
2 average_channels = per channel mean value of all colour tuples
4 for each pixel in pixels of image:
5 for each colour channel in [R, G, B]:
6 pixel[channel] = pixel[channel] / average_channels[channel]
8 luminances = all colour tuples * [0.2125, 0.7154, 0.0721]
9 sorted_luminances = sort(luminances)
10 cutoff_index = (1.0 - PERCENTAGE) * number_of_pixels
11 max_luminance = sorted_luminances[cutoff_index]
13 for each pixel in pixels of image:
14 for each colour channel in [R, G, B]:
15 pixel[channel] = pixel[channel] / max_luminance
Figure 4.2: Basic implementation of the Grey World Assumption algorithm operating on RGB colours. PERCENTAGE= 0.02 for white point estimation as described by Ebner.
more chromatically correct, and gives better comparable results between the implementation modications discussed in this chapter.