Grainy Background Suppression

A common problem of contrast-stretched astrophotos is the uneven background caused by the graininess of the film. Some film scanners seem to emphasize graininess more than others (see Philip Perkins' comparison between Photo CD and a Polaroid Sprintscan). Applying a Gaussian blurring filter smoothes out the grainy structure, but also turns pinpoint star images into fuzzy disks. A modified Gaussian blur, where pixels belonging to bright stars are not included in the convolution, produces an even background while preserving the crisp star images.

How does it work?

The filter function is defined by a matrix, such as the 3×3 matrix shown below. Imagine that we place this matrix like a mask on the image such that each matrix cell corresponds to a pixel. We multiply each matrix cell entry by the corresponding pixel intensity and add the results. Finally we divide this number by the sum of all elements in the filter matrix (this normalization ensures that the overall image brightness does not change). The result is the new value for the pixel at the center of the mask. The mask is shifted by one pixel and the whole process is repeated. (In mathematical terms, we have just done a convolution.)

26
34
150
31
28
29
32
30
35
   Ä   
1
1
1
1
2
1
1
1
1
    =    
26
34
150
31
42
29
32
30
35

Convolution of an image (left) with a filter matrix (center).

If all matrix elements are equal, we have simply taken the average of the central pixel and its eight neighbors. However, we could also give the central pixel a greater weight, as in the matrix shown here. For a Gaussian filter, the matrix elements become smaller with increasing distance r from the center, according to the function

f(r) = e-ln2 (r/r0)2
The parameter r0 determines the width of the Gaussian distribution and hence the amount of blurring.

Now let us take a closer look at the example. Most of the pixel values are close to 30, which is the average background. However, the pixel in the upper right corner has a value of 150, indicating a star. Because of this bright pixel, the result of the convolution for the central pixel is 42, much higher than the background. Thus, in the blurred image the star starts to bleed into the background. The remedy is simple: in our convolution we reject all pixels where the intensity differs from that of the central pixel by more than a cut-off value, e. g. 30. In this case, the convolution would look like this:

26
34
150
31
28
29
32
30
35
   Ä   
1
1
1
1
2
1
1
1
1
    =    
26
34
150
31
30
29
32
30
35
Modified Gaussian convolution of an image (left) with a filter matrix (center).

The central pixel assumes a value of 30, which is much closer to the average background.

As an example, the figure below shows the Antares/Rho Ophiuchi region in Scorpius, recorded on Kodak PJM-2 with a 28 mm f/4 wide angle lens and scanned onto Photo CD. In the left image, the graininess is clearly visible. After the modified Gaussian blur, most of the graininess has been removed, while the stars have not been blurred.

bgsmooth.jpg
Figure 1: Antares/Rho Ophiuchi region: original image (top left) and smoothed images. Top right: radius 5, cut-off 255 (this is the same as a conventional Gaussian blur); bottom left: radius 5, cut-off 20; bottom right: radius 5, cut-off 40.

Downloading the software

For those who would like to experiment with this technique, I am providing the C source code as well as Linux-ELF and MSDOS binaries. The MSDOS binary should run in the DOS box of Windows 3.1 or Windows 95.

Note: The current version is 1.1. The MSDOS port of the original 1.0 version was affected by a bug in the GNU Pascal compiler. The present version based on completely rewritten C code does not suffer from this bug. I suggest you upgrade as soon as possible.

The archive been split into a binary and a source package. You will need the sources only if you intend to recompile bgsmooth on your own platform.

Download binaries (ZIP Archive, 350 kB)
Download sources (ZIP Archive, 1200 kB)

28 Nov. 1998
Axel Mellinger


File translated from TEX by TTH, version 1.58.