Site logo,

Background correction


 The problem

Here is a simple photograph of the night sky (30s f/1.8 ISO800 CanonEOS5D 50mm lens).

Sky with varying background

The background is not black because of light pollution. Notice how the corners are darker than the centre. This occurs for at least two reasons:

Adobe Photoshop has facilities for correcting vignetting but it is unable to deal with asymmetrical effects.

How significant is all this? Using GRIP's measurement menu and selecting the straight line option we can set two points near the corners of the image. On releasing the mouse from setting the second point, up pop the measurements which include a graphical profile along the straight line between the points:

Measure varying background

The horizontal axis of this graph is distance along the line from the first point set, which in this case is near the top left corner of the image. The vertical axis is the detected level. This image has 16 bits per channel so the scale of the vertical axis is from 0 to 65535 (that is up to 216 - 1). There are four traces in the graph: one for each channel (each drawn in the appropriate colour) and a black trace which is the average of the other three.

Above the graph is a redrawn image which shows the values sampled along the line but smeared out vertically so they can be seen. Notice how bright and dark lines in the redrawn profile correspond to peaks and troughs on the graph. In particular, notice what happens when the line goes over or near a star.

Notice also that the background levels jitter up and down. That is noise, which we discuss elswhere.

If we want software to detect stars automatically, differentiating them from the background, it needs to detect pixels which are brighter than a certain level. But how do we say what that level should be when the background level is so un-flat?

 GRIP's solution

The approach used in GRIP (and other software for image analysis) is first to correct the image, so the background is flatter. Here is the result of the background correction option from GRIP's levels menu, for the image we have been studying:

Sky with flattened background

Measuring the diagonal now shows that the background is much flatter and we can envisage setting a level just above the background such that pixels brighter than that level can be deemed to belong to stars.

Measure flattened background

 The method

GRIP's code for background correction can be found in the class ImProcess, in the static method correctBackground (BufferedImage im). The steps are as follows.

  1. Divide the image up into 16 x 16 rectangular cells, by dividing the image width and height by 16.
  2. In each cell, for each channel, build the frequency histogram and find its mode (ie, the level which has the greatest frequency). This is taken to be the background level for this cell and channel.
  3. Redraw the image. For each pixel determine how far it is from the centres of the cell in which it lies and neighbouring cells. For each channel, interpolate the histogram modes between cells, for this pixel position. Subtract 7/8 of the interpolated mode from the pixel value for this channel. Draw the result.

The interpolation formula is very similar to that described for pixel interpolation except that here we interpolate between the centres of cells rather than the centres of pixels.

The factor of 7/8 when subtracting the mode is so that the background is not lost from the bottom of the profile, so we can still estimate noise. This a configuration option for GRIP, so it can be changed in the configuration dialogue.

Next page