PixInsight LE Tutorial
Vignetting and Sky Gradient Correction:
The DynamicBackgroundExtraction Process in PixInsight LE 1.0.2

Tutorial by Juan Conejero (PTeam)

:: PixInsight Home Page

0. Introduction

1. The DynamicBackgroundExtraction (DBE) Process in PixInsight

2. A Simple DBE Example
2.1 Selecting The DBE Operation Mode
2.2 Basic Global DBE Parameters
2.3 Defining a Set of DBE Samples
2.3.1 Automatic Generation of Samples on a Rectangular Grid
2.3.2 Setting the Global Tolerance Parameter
2.3.3 Refining the Set of DBE Samples
2.4 Generation of a Synthetic Background Model
2.5 Applying the Background Model
2.6 Final Result

3. Advanced DBE Parameters
3.1 Symmetrical DBE Samples
3.1.1 Axial Symmetry
3.1.2 Horizontal, Vertical and Diagonal Symmetries
3.2 Fixed DBE Samples
3.3 Controlling 2-D Surface Spline Generation
3.3.1 Smoothing Global DBE Parameter
3.3.2 Continuity Order Global DBE Parameter



0. Introduction

Uneven illumination and color form a major problem in astrophotography. On one hand, vignetting is inherent to all flat-field optical instruments, due to a fundamental geometrical property of those systems: the effective aperture of the objective is inversely proportional to the radial distance measured on the focal plane with respect to the center of the field of view (FOV).

Vignetting can be easily understood if we look at the diagram on Figure 1. D0 and F0 are, respectively, the nominal aperture and focal length of the depicted optical system; these quantities are strictly valid for a point at the center of the focal plane. At angular distance j, the corresponding effective aperture Dj is smaller than D0. This is because the aperture is seen as an elongated ellipse from the projected distance hj on the focal plane. Furthermore, the effective focal length Fj is larger than F0. So we have Fj/Dj > F0/D0, and the neat result is that the optical system gets slower as the angular distance from the center of the FOV grows: illumination on the focal plane follows a symmetrical, nonuniform distribution, decreasing from its center, and showing prominent fallouts at the corners of a rectangular field. Vignetting is worse in fast f-ratio, wide-field systems.


This content can be seen only via the Flash Player .

Figure 1— Formation of vignetting on a flat-field optical system, neglecting the effect of distortion.

Of course any obstacle to incident light, interposed between the aperture and the focal plane, adds up to the vignetting problem. Such obstacles are almost inevitable to some degree, especially in wide-field instruments: T-rings, adaptors, mirror cells, lens supports, undersized secondary mirrors, correctors and baffles, etc.

Vignetting has been traditionally a problem more associated to film astrophotography. However, due to the increasing use of large-sized CCD and CMOS sensors, vignetting is becoming a common issue also in many fields of digital astrophotography.

Figure 2 — This is a raw scan image of a 45-minutes shot on Kodak Royal Gold 400 through a Vivitar 210 mm lens at f/5.6, showing a typical example of vignetting on long-exposure astrophotography under good conditions from rural skies. Image taken by the author on September 1999.


Figure 3 — On this graphic mean sample values v have been represented for the red, green and blue channels of the raw scan shown on Fig. 2, measured for free sky areas on a diagonal of the image in the 8-bit range (0-255). Abscissae d are distances in millimetres from the center of the original negative.

But vignetting is not the only, nor the hardest to fight uneven illumination problem that the astrophotographer has to suffer: light pollution is by far the worst of his/her nightmares. When imaging from urban or suburban locations (and even from many rural ones, unfortunately), we have to work knowing that the sky background will never be truly neutral nor uniformly illuminated and colored in our raw images, especially at low and intermediate heights above the horizon, and varying wildly as a function of local conditions of transparency. This is what we know as sky gradients. What makes the gradients problem a really bad one is the fact that gradients are neither symmetrical nor predictable. In general, we have no way to generate a suitable correction image to compensate for gradients, and the only practical solutions can be found through specific image processing techniques.

[Mouse over: Synthethic background model generated and subtracted in PixInsight LE]

Figure 4 — An example of severe light pollution gradients merged with vignetting. Image by Carlos Milovic, corresponding to a series of lens test shots.

Is this one a useful image? Can we salvage this apparent disaster to obtain a reasonably good astrophoto? Place the mouse over the image to get an answer.



1. The DynamicBackgroundExtraction (DBE) Process in PixInsight

The DynamicBackgroundExtraction process, DBE among friends, has been included in PixInsight LE 1.0.2 and later. DBE is a highly interactive system to build synthetic models of the sky background in deep-sky images.

The idea behind DBE is in fact quite simple: read pixel values from a set of conveniently distributed samples over the image, then build a two-dimensional function to fit them. Such a 2-D function can be used to interpolate a new image, which will be a synthetic model of the sky as it has been recorded in the image. If the original set of samples was carefully defined to extract true sky background values, avoiding pixels from stellar and nonstellar objects, then in general the generated model will be very precise. DBE includes many interface resources and features that have been specifically designed to help the user in the task of defining background samples accurately.

Once a good background model has been obtained, it can be applied to the original image to remove all vignetting and gradient patterns. The resulting image will show a flat illumination profile and a uniform background chromatic balance over the entire field. The operations required to apply a background model vary depending on the imaging media used and the specific problems being corrected. CCD sensors are linear, so uneven illumination correction of a CCD image should be accomplished by dividing the image by its background model. Film, on the other hand, is wildly nonlinear, which makes dividing impossible. A good approximation for film can be subtracting a background model. A more precise procedure for film, based on linearized division, has been described by Carlos Milovic.


2. A Simple DBE Example

A good image to build a first DBE example is this shot of central Auriga, obtained under excellent rural sky conditions with 6.5-7.0 limiting naked-eye magnitude. It is a single 50-minutes, manually-guided shot, taken on Kodak Royal Gold 400 on October 2000 by the author of this tutorial. A Vivitar Series 1 210 mm f/3.5 lens was used stopped down to f/5.6.

The image above is a plain raw scan at 2700 dpi. It shows moderate vignetting and a slight gradient due to differential atmospheric absorption, and perhaps a bit of residual light pollution. This image is a quite simple case. We'll demonstrate how a nearly trivial usage of the DBE process in PixInsight LE can solve all vignetting and gradient problems for this image to yield a perfectly flat result, which will then be further processed with standard noise reduction, contrast and color saturation enhancement techniques.


2.1 Selecting the DBE Operation Mode

The first thing that must be done to start a DBE session is selecting the DBE operation mode. This is possible through the Image > Mode main menu item, through the Image View > Mode context menu (right-click on an image), or by clicking the corresponding tool button (). This last way is shown on the figure below.

As happens with all dynamic processes in PixInsight, DBE cannot be executed on previews. This means that you must have an image view selected to start DBE; otherwise the corresponding tool button and menu options will be disabled.

To begin working with DBE, click on an image. This will select the image as the target for background modelization and will generate a first DBE sample on it:

The Dynamic Background Extraction auxiliary window includes a set of controls to define every aspect of the DBE process. These controls are divided into two tabbed pages: one for parameters of the currently selected DBE sample, and another page with parameters defining the global behavior of DBE and the generation of background models.


2.2 Basic Global DBE Parameters

Before going on defining DBE samples over the image, a number of global DBE parameters must be established to adapt DBE to some particular characteristics, mainly image dimensions and distribution of background pixel values. Below you can see the Global page of the DBE window with the default set of global parameters loaded.

We'll review the basic parameters first, since it is important that you know what each parameter is intended for. Then we'll define the appropriate values for the image of this example, and we'll show you how to decide in each case, step by step. You'll see that working with DBE is easy since it does a lot of critical work for you.

Default Sample Radius. Each DBE sample defines a square region of the image from which background pixels are extracted. The sample radius refers to the half size of a sample; the side of a sample square box is twice this value plus one. This global parameter is the radius value used for newly created samples. Although you can change the radius for each individual sample (you'll see this later), setting this parameter to a correct value is important, especially before generating a set of samples automatically.

Resize All. By clicking this button you resize all existing DBE samples to the default sample radius.

Auto Intervals. DBE can generate automatically a set of equally distributed samples on a rectangular grid over the image. This parameter is the number of samples that will be created horizontally, that is, the number of columns in the grid. The number of rows in the grid will be calculated so that all samples will be equally spaced in both directions.

Generate. Click this button to generate a regular distribution of samples automatically, according to the Auto Intervals parameter. Warning: previously existing samples will be erased, and this operation cannot be undone.

Symmetry Center X/Y. These coordinates refer to the center of symmetry, expressed in pixels. The center of symmetry of the set of DBE samples is used by samples that define their own symmetrical properties. For now, just don't care about this. We'll review this topic later as an advanced parameter.

Reset Centers. Each of these buttons reset the corresponding symmetry center coordinate to the physical middle of the image, that is, one half of the width or height, respectively. Use them if you move the central lines (see the figure at the top of this section) accidentally.

Tolerance. This is a crucial parameter. Tolerance refers here to a level in the normalized range from 0 to 1. Roughly speaking, pixels below tolerance will be considered as background pixels, and pixels above tolerance will be discarded from the background model. So setting a low tolerance value makes the DBE sampling procedure more restrictive. DBE tolerance must be fine-tuned for each particular image, but you'll find that it is very easy to find the correct value. This is because DBE includes an efficient algorithm to adapt the tolerance parameter to the exact distribution of pixel values within each DBE sample. In this way DBE is able to exclude small bright objects (as stars and spurious bright pixels and artifacts) from the background modelization process automatically.

Continuity Order / Smoothing. These are advanced parameters that will we reviewed at the end of this document.

Subsample Output. In general, a background model is an extremely smooth image. This means that you can use a strongly subsampled background model without any loss of accuracy. For example, here 1:2 refers to one half of the original image dimensions. The PixelMath process in PixInsight, which is the process of choice to apply background models, can handle subsampled images transparently. We recommend to work with subsampling ratios of 1:4 or 1:8. This speeds up model generation dramatically.

Sample Colors. If you have difficulties to see DBE samples plotted over the image, try choosing appropriate colors here. Many times raw images are poorly contrasted and have strong color casts, which makes sample boxes almost invisible with certain color combinations.


2.3 Defining a Set of DBE Samples


2.3.1 Automatic Generation of Samples on a Rectangular Grid

For the present example we'll make use of DBE's automatic sample generation feature.

First we must set an appropriate default radius, which will be adopted by all generated samples. The default value of ten pixels seems a bit too small for the image of this example. We prefer a higher value, say sixteen pixels. This is not a very critical parameter, but too small or too large samples might degrade DBE's performance. Our decision is based on our own experience and some common sense.

More critical is the number of samples that will be generated (Auto Intervals parameter). Too few samples yield poor background models, especially if strong local variations must be corrected. Too many samples are difficult to manage, slow down calculations, and add nothing in terms of accuracy. Again, some common sense and experience are required. Our choice has been 24 horizontal intervals.

Let's click on the Generate button to get something like this:

Note the Default sample radius and Auto intervals global parameters with values of 16 and 24, respectively.

The automatic generation of samples is useful as a starting point, since it avoids us the tedious task of creating a lot of samples manually. However, it's obvious that the distribution above must be refined, since there are many samples located over extended nonstellar objects (IC 405 and IC 410, mainly) which would lead to an incorrect background model.


2.3.2 Setting the Global Tolerance Parameter

What about the tolerance parameter? First let's see how the default value of 0.1 is performing.

The square graphic on the Current Sample tab page of the DBE window shows the distribution of background pixels that are being considered for the currently selected sample. Black points correspond to discarded (non-background) pixels. White pixels are background pixels. The selected sample is shown in red color (the default colors are being used on the figure above). It is located halfway over the bottom-left diagonal of the image.

To select a given sample, just click on it with the mouse. You can drag a sample to move it. To select a sample without moving it, press the Control key while clicking it.

On the figure above you see that very few pixels are entering the background model. This is because the tolerance parameter has been set too low. Some different values must be checked to make a well founded decision.

Figure 5— A DBE sample located halfway over one diagonal of the image, and the corresponding distribution of extracted background pixels (white) for different values of the global tolerance parameter.

0.3

0.4

0.5

0.6

On Figure 5 four values have been compared. Our goal is to collect a high number of background pixels while stars and small bright features are avoided. Tolerance values between 0.4 and 0.6 are quite appropriate. 0.6 seems a bit too high, since some dim stars are being selected as background. Our choice is 0.5.

When things become unclear, the same test should be performed for a number of samples, some near the center of the image, some near the corners, to be sure that one adopts a good compromise.


2.3.3 Refining the Set of DBE Samples

As we said before, some automatically generated samples lie on wide nonstellar objects. This must of course be always avoided. The simplest approach is just deleting those samples. The interpolating routines implemented in the DBE process are able to work even if there are significant areas of the image without defined samples; the missing values are just generated by interpolation from surrounding ones, and this usually works very well.

To delete a sample, the easiest way is to click it and press the Delete key. You may also click the Delete button on the DBE window when the sample is selected. Note that all the navigation resources of PixInsight work without problems during a DBE session: you can zoom in and out, or pan the view with menu and keyboard commands. You may also select different channels to be displayed.

Below you can see our final DBE set, after having deleted the problematic samples. Perhaps we were somewhat too conservative and erased some samples that were already located over valid sky background areas.

Instead of deleting a sample we can move it to a free sky area, if possible. We did so in the present example to avoid many blue halos around bright stars, which were introducing slightly incorrect values.

Sometimes a combination of incorrect sample sizes and positions can lead to improper background models. Below you have a detailed example of this.

Note that the selected sample encloses a bright star, which occupies almost the whole sample area. Very bright pixel values are being considered as part of the background, which will produce an incorrect model. This can be avoided very easily by either increasing the sample radius (so the relative area covered by the star is smaller), or by moving slightly the sample to a free sky region, as below.

In incoming versions of PixInsight, problems like this one will be detected and corrected automatically. For now, you must make sure that no invalid DBE sample is being included due to accidental coincidence with a bright and extended (relative to sample radius) object. This is easy by simply taking a quick survey over the image at a moderate zoom ratio.


2.4 Generation of a Synthetic Background Model

For the present example we used the default continuity order (2) and smoothing parameters (0.025). Those are advanced parameters that can be used in more difficult cases. We selected 1:4 subsampling since, as explained earlier in this document, there is generally no need to create high resolution background models because they are extremely smooth images. By generating strongly subsampled models we can save a lot of computing time.

After clicking the Generate button, this is the result:

Posterization in the image above has been originated by the 8-bit transformation required to write the screen shot as a JPEG file. DBE background models are directly generated in the native normalized 32-bit floating point range of PixInsight LE.

By default, generated background models are identified as <image>_background, where <image> is the original DBE target image identifier. This behavior, particularly the identifier suffix used, can be customized through a Global Preferences option (Edit > Preferences > Identifiers).


2.5 Applying the Background Model

A CCD image could now be flattened by straight division with the generated background model. This works because CCD sensors are linear.

But we are dealing with a film image here, so the relation between numerical pixel values and actual brightness of represented celestial objects is strongly nonlinear. A commonly used approximation to uneven illumination correction for film images consists on subtracting a background model. However, this does not give correct results since it is just a simplification of the true problem. By subtracting the background from a film image, the sky is very well corrected over the entire field, but bright objects like stars and nebulae tend to be undercorrected at the center and overcorrected at the corners of the image. This is due to varying characteristic curves of film as a function of incident light intensity.

A more rigorous procedure has been devised by PTeam member Carlos Milovic. His procedure starts by applying a linearization correction to both the image and the background model. Once all pixel values are expressed in a linear space, the image can be divided by the background, just like flat-fields are applied to CCD images. Finally, an inverse delinearization transform is applied to the corrected image, to restore its original brightness/contrast relation. The process is explained in detail in the original article by Carlos Milovic.

Having said that, we'll subtract the background. The results will not be perfect, but they will be very good in our opinion, considering the original raw image. Despite the method chosen to apply a background model, the PixelMath process must be used for this task in PixInsight.

This is the setup used in the present example. We have the original raw image, the background model, and the Pixel Math window with the subtraction procedure defined and ready to be executed.

Note the SUB operator selected in Pixel Math. The Rescale option must be selected. The PixelMath process can be directly applied to the image, or it can be tried out on a preview. The background model image will be automatically resampled by PixelMath to the appropriate sizes before operation. If you are about to try a number of PixelMath instances, consider resizing the model first, to save processing time.

Here is the result of subtracting the generated background model from our example image, by the process defined above:

Move the mouse cursor over the image to compare it with the original, uncorrected raw image. Please wait until your browser loads the images; file sizes are a bit large.


2.6 Final Result

This is our final result after noise reduction with the SCNR and SGBNR algorithms, histogram adjustments, and luminance and color saturation curves. All the processing was done in PixInsight LE 1.0.2. Again, by placing the cursor over the image you can compare it with the raw scan. Not too bad for a single film shot.


3. Advanced DBE Parameters

A number of DBE parameters and resources have been implemented to deal with especially difficult problems of uneven illumination correction. Almost all of these cases are characterized by the availability of just a few free sky background regions. Such situations are found when large parts of the image are covered by extended nonstellar objects or dense Milky Way condensations. Building accurate background models under those conditions can become an extremely complex task.


3.1 Symmetrical DBE Samples

When a DBE sample is given some symmetrical properties, it copies itself on selected locations, symmetrically distributed with respect to the current center of symmetry. The center of symmetry can be relocated by dragging the horizontal and vertical symmetry axes.


3.1.1 Axial Symmetry

The symmetrical nature of vignetting can be used to simplify the process of defining DBE samples. The axial symmetry of vignetting can be simulated by activating the corresponding option on the DBE window. When a sample has axial symmetry, its sampled background values are replicated forming a regular polygon.

The example above is a difficult case because we have almost no free sky areas. There are just a few ones at the upper-left quadrant of the image, where three samples have been defined with axial symmetry. Note the activated Axial check box on the DBE window. To show all the symmetries currently defined, activate the "Show sym" check box. To define the number of symmetrical duplicates of a sample, use the up/down control or enter the desired order of the polygon.

Above you can see the generated background model and the resulting image after model subtraction.


3.1.2 Horizontal, Vertical and Diagonal Symmetries

Each of these symmetries generates one copy of the sampled background values. Instead of trying to explain them, better look at the example below. These symmetries cannot be mixed with axial symmetry for a given DBE sample. However, different samples can have any combination of symmetries in a single DBE instance.

The H, V and D check boxes are used to activate or deactivate, respectively, the horizontal, vertical and diagonal symmetrical properties of a DBE sample. The Clear button can be used to remove all symmetrical properties at once, but only for the current sample.


3.2 Fixed DBE Samples

Sometimes one has to force specific RGB (or gray) values for some DBE samples. This happens when there are localized regions blocked by very bright stars or relatively small nonstellar objects, and one needs to make sure that such regions will not contribute to the background model. Below you have a good example of this.

A fixed DBE sample has been placed just on the NGC 2023 reflexion nebula —note the "Fixed value" check box. In this example, the values used (R=0.33, G=0.40, B=0.42) have been interpolated from the other samples around the nebula. Although it is quite unusual, there are situations where a fixed point has to be forced in this way, since for some reason DBE is unable to provide the correct values automatically. A fixed DBE sample can also have symmetrical properties.


3.3 Controlling 2-D Surface Spline Generation


3.3.1 Smoothing Global DBE Parameter

A DBE background model is generated by interpolation with a mathematical device known as two-dimensional surface spline, also called thin plate. 2-D surface splines can be interpolating surfaces or smoothing surfaces. In the first case, generated models reproduce each DBE sample at its exact location. When smoothing splines are used, generated models don't include actual DBE samples exactly, but are less sensitive to small-scale local variations. Each type has its own pros and cons. Interpolating surface splines can reproduce complex illumination profiles very accurately. Smoothing splines, on the other hand, tend to generate more uniform and smooth models, which are usually more desirable.

The Smoothing global DBE parameter has a default value of 0.025, so by default smoothing surface splines are used. This has been verified to be acceptable in most situations, but you may want to experiment with this parameter, especially in difficult cases. Setting a zero smoothing value forces DBE to use pure interpolating surface splines. Too smooth background models may be poorly adapted to illumination variations. Too adapted models, on the other hand, may introduce artifacts due to excessive dependency on small-scale local variations.


3.3.2 Continuity Order Global DBE Parameter

2-D surface splines are guaranteed to be continuously differentiable up to certain derivative order. By default this order is two. High-order splines produce surfaces more adaptable to small-scale local variations. You can experiment with this parameter, but achieving better results in this way is quite unlikely. Be aware that imposing a high derivative order for a complex surface may lead to a singular linear system matrix. If this happens, the DBE process will fail, hopefully in a controlled and "elegant" way.



:: PixInsight Home Page