frmedian -- quantize and ring median filter a list of input images
frmedian input output rinner router
FRMEDIAN takes a list of input images input and produces a set of filtered output images output . The filter consists of a sliding circular / elliptical or annular circular / elliptical window whose size and orientation is determined by the rinner , router , ratio , and theta parameters. The center pixel in the window is replaced by the median of the pixels in the window, where the median of a sequence of numbers is defined to be the value of the (n + 1) / 2 number in the ordered sequence. Out of bounds pixel references are handled by setting the parameter boundary . The principal function of the circular / elliptical filters is to smooth an image using a circularly / elliptically symmetric filter. The principal function of the circular / elliptical ring filter is to remove objects from the image which have a scale length of rinner and replace them with an estimate of the local background value.
If zmin = hmin and zmax = hmax , FRMEDIAN converts the image pixels directly to integers. This operation may result in truncation of the pixel values if the input image is not an integer image. Otherwise the input pixel values from zmin to zmax are linearly mapped to integer values from hmin to hmax. The histogram, median, and number of pixels less than the median, are computed for the first window position. These quantities are updated as the median filter moves one position. The unmap parameter is normally set so as to restore the output pixel values to the range defined by zmin to zmax, but may be turned off if the user wishes to examine the quantized pixels. The precision of the median in integer space and pixel space is 1.0 and (zmax - zmin) / (hmax - hmin) respectively.
The zloreject and zhireject parameters may be used to reject bad data from the median filtering box. If no good data is left in a give filtering box, then the median is set to zloreject if the majority of the pixels are less than zloreject, or to zhireject if the majority of pixels are greater than zhireject.
A description of the fast median algorithm used here can be found in "Topics in Applied Physics: Two-Dimensional Digital Signal Processing II: Transforms and Median Filters", Volume 43, 1981, Springer-Verlag, edited by T.S. Huang, page 209.
The properties of the ring median filter and its application to astronomical data analysis problems is summarized in the article "A Ring Median Filter for Digital Images" (Secker, J., 1995, PASP, 107, 496-501) and reference therein.
1. Median filter a 16 bit CCD image using a circular ring filter with an inner radius of 4 pixels and a width of 1 pixel.
im> frmedian input output 4.0 5.0 hmin=-32768 hmax=32767 \ >>> zmin=-32768. zmax=32767.
2. Median filter a KPNO PDS image using a circular ring filter of outer radius 3.
im> frmedian input output 0.0 3.0 hmin=0 hmax=4095 zmin=0. zmax=4095.
3. Median filter an 8 bit image using the same filter used in example 2.
im> frmedian input output 0.0 3.0 hmin=0 hmax=255 zmin=0. zmax=255.
4. Median filter an image with real values from 0.0 to 1.0 with a precision of .003 and leave the output pixels in integer format. Use a ring filter of inner radius 5.0 and width 0.5 pixels.
im> frmedian input output 5.0 5.5 unmap- hmin=0 hmax=1000 zmin=0. \ >>> zmax=1.
5. Median filter the test image dev$pix rejecting any pixels < 5 or greater than 19935 from the medianing process using a circular filter of outer radius 5.0.
im> frmedian dev$pix output 0.0 5.0 hmin=-1 hmax=20000 zmin=-1.0 \ >>> zmax=20000 zloreject=5 zhireject=20000
It requires approximately 30 and 22 cpu seconds to median filter a 512 by 512 square integer image with a circular filter of radius 5 pixels and a ring filter of inner and outer radii of 4.0 and 5.0 pixels respectively. (SPARCStation2).
This technique is most suitable for integer data and data which has not been calibrated. For non-integer data the calculated median is an approximation only.
If the dynamic range of the data defined by hmin and hmax is large the memory requirements can become very large.
median, rmedian, fmedian