Smooths a two-dimensional data array using a weighted median filter
A threshold for replacement of a value by the median can be set. If the absolute value of the difference between the actual value and the median is less than the threshold, the replacement will not occur. The array boundary is dealt by either pixel replication or a reflection about the edge pixels of the array.
The WMF can be repeated iteratively a specified number of times, or it can be left to iterate continuously until convergence is achieved and no further changes are made to the data. In the latter case a damping algorithm is used if the number of iterations exceeds some critical value, which prevents the result oscillating between two solutions (which can sometimes happen). When damping is switched on data values are replaced not by the median value, but by a value midway between the original and the median.
Bad pixels are not included in the calculation of the median. There is a defined threshold which specifies minimum-allowable median position as a fraction of the median position when there are no bad pixels. For neighbourhoods with too many bad pixels, and so the median position is too small, the resulting output pixel is bad.
"Replication"
–- The values at the edge of the data array are replicated into
the padded area. For example, with STEP=2
one corner of the original and
padded arrays would appear as follows:
corner of original array: $\begin{array}{ccccc}\hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 3\hfill & \hfill 3\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 4\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 5\hfill \end{array}$ corresponding corner of padded array: $\begin{array}{ccccccc}\hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 3\hfill & \hfill 3\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 4\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 5\hfill \end{array}$
"Reflection"
–- The values near the edge of the data array are reflected about
the array’s edge pixels. For example, with STEP=2
one corner of the
original and padded arrays would appear as follows:
corner of original array: $\begin{array}{ccccc}\hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 3\hfill & \hfill 3\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 4\hfill \\ \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 5\hfill \end{array}$ corresponding corner of padded array: $\begin{array}{ccccccc}\hfill 3\hfill & \hfill 2\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 3\hfill & \hfill 3\hfill \\ \hfill 2\hfill & \hfill 2\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill \\ \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill & \hfill 1\hfill \\ \hfill 2\hfill & \hfill 2\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill & \hfill 2\hfill \\ \hfill 3\hfill & \hfill 2\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 3\hfill & \hfill 3\hfill \\ \hfill 3\hfill & \hfill 2\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 4\hfill \\ \hfill 3\hfill & \hfill 2\hfill & \hfill 1\hfill & \hfill 2\hfill & \hfill 3\hfill & \hfill 4\hfill & \hfill 5\hfill \\ \hfill \hfill \end{array}$
["Replication"]
$-$1
.
It must be an odd value in the range 1 to 21. [1]
$-$1
. It
must be in the range 0 to 10. [1]
[0.0]
"Specified"
–- You specify the number of iterations at each step size in the
Parameter NUMIT.
"Continuous"
–- The filter iterates continuously until convergence is achieved and
the array is no longer changed by the filter. A damping algorithm comes into
play after MAXIT iterations, and the filter will give up altogether after MAXIT
$\times $
1.5 iterations (rounded up to the next highest integer)."Continuous"
mode is recommended only for images which are substantially smooth to
start with (such as a sky background frame from a measuring machine). Complex
images may take many iterations, and a great deal of time, to converge.
["Specified"]
"Continuous"
. It must lie in the range 1 to 30. [10]
[0.8]
$-$1
allows you to define the weighting, and 0
to 7
the predefined filters. The predefined
modes have the following weighting functions:
[0]
"Specified"
. [1]
$-$1
. It
must be in the range 0 to 10. [1]
4
, or may be filtered at a whole
series of spacings in turn by specifying a list of values, such as STEP=[4,3,2,1]
.
There is a limit of 32 values. [1]
[!]
3
), a step size of 4 pixels (STEP=4
) and a difference
threshold of 1.0 (DIFF=1.0
). It runs the filter twice (NUMIT=2
) and writes
the result to the NDF called sabc. [4,3,2,1]
). It runs the filter twice at each step size (NUMIT=2
). Note that
the filter will be run a total of eight times (number of step sizes times the
number of iterations). CONT
). Damping will begin after 6
iterations (MAXIT=6
), and the filtering will stop regardless after 10 iterations (1
$+$ INT(1.5
$\ast $ MAXIT)). Note
that the filter will run an indeterminate number of times, up to a maximum of 40 (number of
step sizes $\times $
maximum number of iterations), and may take a long time. The resultant data array are
written to the NDF called clean. 0
to 7
. A step size has to be specified too; this determines the spacing of
the elements of the weighting function. The data can be filtered at one step size only,
or using a whole series of step sizes in sequence. The weighting function has the
form:
CORNER
SIDE
CORNER
SIDE
CENTRE
SIDE
CORNER
SIDE
CORNER
The . Indicates that the weights are separated by the stepsize-minus-one zeros.
This routine correctly processes the AXIS, DATA, LABEL, TITLE, UNITS, WCS, and HISTORY components of an NDF data structure and propagates all extensions. VARIANCE is not used to weight the median filter and is not propagated. QUALITY is also lost.
Processing of bad pixels and automatic quality masking are supported.
All non-complex numeric data types can be handled.