Next: Interpolation operators, Previous: Stacking operators, Up: Arithmetic operators [Contents][Index]

Image filtering is commonly used for smoothing: every pixel value in the output image is created by applying a certain statistic to the pixels in its vicinity.

`filter-mean`

Apply mean filtering (or moving average) on the input dataset. During mean filtering, each pixel (data element) is replaced by the mean value of all its surrounding pixels (excluding blank values). The number of surrounding pixels in each dimension (to calculate the mean) is determined through the earlier operands that have been pushed onto the stack prior to the input dataset. The number of necessary operands is determined by the dimensions of the input dataset (first popped operand). The order of the dimensions on the command-line is the order in FITS format. Here is one example:

$ astarithmetic 5 4 image.fits filter-mean

In this example, each pixel is replaced by the mean of a 5 by 4 box around it. The box is 5 pixels along the first FITS dimension (horizontal when viewed in ds9) and 4 pixels along the second FITS dimension (vertical).

Each pixel will be placed in the center of the box that the mean is calculated on. If the given width along a dimension is even, then the center is assumed to be between the pixels (not in the center of a pixel). When the pixel is close to the edge, the pixels of the box that fall outside the image are ignored. Therefore, on the edge, less points will be used in calculating the mean.

The final effect of mean filtering is to smooth the input image, it is essentially a convolution with a kernel that has identical values for all its pixels (is flat), see Convolution process.

Note that blank pixels will also be affected by this operator: if there are any non-blank elements in the box surrounding a blank pixel, in the filtered image, it will have the mean of the non-blank elements, therefore it will not be blank any more. If blank elements are important for your analysis, you can use the

`isblank`

with the`where`

operator to set them back to blank after filtering.`filter-median`

Apply median filtering on the input dataset. This is very similar to

`filter-mean`

, except that instead of the mean value of the box pixels, the median value is used to replace a pixel value. For more on how to use this operator, please see`filter-mean`

.The median is less susceptible to outliers compared to the mean. As a result, after median filtering, the pixel values will be more discontinuous than mean filtering.

`filter-sigclip-mean`

Apply a \(\sigma\)-clipped mean filtering onto the input dataset. This is very similar to

`filter-mean`

, except that all outliers (identified by the \(\sigma\)-clipping algorithm) have been removed, see Sigma clipping for more on the basics of this algorithm. As described there, two extra input parameters are necessary for \(\sigma\)-clipping: the multiple of \(\sigma\) and the termination criteria.`filter-sigclip-mean`

therefore needs to pop two other operands from the stack after the dimensions of the box.for example, the line below uses the same box size as the example of

`filter-mean`

. However, all elements in the box that are iteratively beyond \(3\sigma\) of the distribution’s median are removed from the final calculation of the mean until the change in \(\sigma\) is less than \(0.2\).$ astarithmetic 3 0.2 5 4 image.fits filter-sigclip-mean

The median (which needs a sorted dataset) is necessary for \(\sigma\)-clipping, therefore

`filter-sigclip-mean`

can be significantly slower than`filter-mean`

. However, if there are strong outliers in the dataset that you want to ignore (for example, emission lines on a spectrum when finding the continuum), this is a much better solution.`filter-sigclip-median`

Apply a \(\sigma\)-clipped median filtering onto the input dataset. This operator and its necessary operands are almost identical to

`filter-sigclip-mean`

, except that after \(\sigma\)-clipping, the median value (which is less affected by outliers than the mean) is added back to the stack.

JavaScript license information

GNU Astronomy Utilities 0.19 manual, October 2022.