Color Balancing an Image Using a

Macbeth Color Chart

HDR Shop allows you to alter the pixel values in one image using the reference values in a different image. In this tutorial we will illustrate this process by balancing an image into sRGB color space using a standard 'Gretag Macbeth Color Checker' chart. A Macbeth chart is a non-reflective arrangement of 24 colored squares chosen to represent commonly photographed subject types such as skin and blue sky.

Below is our test scene taken under indoor illumination and through a light green filter (left). On the right is the same scene with a Macbeth chart. To balance to a Macbeth chart, you need to have an image of the chart under the same illumination conditions that you wish to correct for.

First, we need to sample what colors those 24 squares are in our scene. To do this, select a rectangular area containing the colored area of the chart (you may need to rotate/rectify the images first in HDR Shop to get the chart edges roughly parallel to the selection rectangle):

Now choose 'Image->Info->Sample Grid' from the menu. In the dialog that appears, enter the grid dimensions (24) and the number of samples (horizontally & vertically) to be taken from the center of each grid square. 10 samples in width and height will cause the 10 x 10 square in the grid square center to be used as the samples. The default 5 x 5 is usually enough for a well/uniformly lit scene. The mean value for each set of grid square samples is computed and output as an image with one pixel for each grid square with the value of the mean of the samples within the input grid:

Next, create a reference Macbeth chart in a color space into which the scene will be transformed. Select 'Create->Macbeth Chart...' from the menu and choose 'sRGB' from the 'color space' drop-down box. This creates a 6 x 4 pixel representation of a Macbeth chart in the sRGB color space:

Now we need to compute the 3 x 3 matrix which maps color values in our sampled scene chart to our reference chart. Choose 'Image->Pixels->Compute Color Matrix...' from the menu. Select the sampled scene chart as the 'source image' and the reference chart as the 'target image' and click 'OK':

HDR Shop computes the transformation by creating a system of linear equations from each pixel channel. This system is then solved by finding the pseudo-inverse using SVD. the resulting 3 x 3 matrix is presented as a dialog. From here the matrix or constituent parts can be copied to the text buffer:

All we need to do now is to use the computed color matrix to transform the original scene images. Make sure to first deselect the rectangle around the Macbeth chart in the original image before applying the color balance. Select 'Image->Pixels->Apply Color Matrix...' from the menu. Paste the computed color matrix into the dialog and click 'OK'. The image colors are now transformed into sRGB color space and should now look a lot more 'natural'. You can now also apply the balance to any other images without the Macbeth chart:

Note that the 'Compute Color Matrix...' function can be used to compute changes between any pair of images (provided they are the same size) so the color transformation between images with the same content, but different illumination can be obtained. Also note that the new framework allowing an operation to be applied to any or all of the currently open windows (see the 'View->Apply to...' menu items) means that operations such as color balancing can be performed within HDR Shop without the need to write a script or repeat the operation for each image.