The CUPID:FINDBACK Algorithm
Note, a modified form of this algorithm is currently available on an experimental basis.
The following images illustrate how the CUPID:FINDBACK command works using 1-dimensional data (the algorithm is basically the same in 2 or 3 dimensions). The box size in this example is 41 pixels.
First, each pixel is replaced by the minimum value in a box centred on the pixel. The size of this box is specified by the user, and specifies the size of the smallest features which are to remain in the final background estimate. The following image shows the original data (white) and the result of this minimum filter (red).
Next, each pixel in this filtered data is replaced by the maximum value in a box centred on the pixel. The same box size is used as in the first step. This results in the following blue curve.
Next, each pixel in this filtered data is replaced by the mean value in a box centred on the pixel. The same box size is used as in the first two steps. This results in the following green curve.
For good measure, here are all three stages shown together.
The result of this 3-stage filtering is an estimate of the lower envelope of the data on the specified scale size. However, in areas of noise, this lower envelope tends to hug the lower end of the negative noise spikes. To get round this a correction is made to the above green curve which results in the final curve passing through the middle of the noise in noise-dominated areas. This correction is made by first getting the residuals between the green curve and the original data. Any pixels which have a residual more than three times the noise level in the data are set bad. This gets rid of everything but the background pixels. The Remaining background pixels are smoothed using a mean filter, and the bad pixels replaced by extrapolation from the good pixels. This correction is then added onto the green curve, to get the cyan curve in the following plot, which is the final background estimate.