Program: MFILTER Purpose: Apply a median (or average) filter to a (sub)set Category: CALCULATION, TRANSFER File: mfilter.c Author: M.G.R. Vogelaar Keywords: INSET= Give set, subsets: Maximum number of subsets is 2048. BOX= Give box in ..... [entire subset] OUTSET= Give output set (, subsets): Output set and subset(s) for the result. The number of output subsets is the same as the number of input sub- sets. MEDBOX= Give sizes of median box: [3,3] Sizes must be odd. A size equal to 1 means no median filter in that direction. ** AVERAGE= Use average instead of median Y/[N] By repeatedly applying this boxcar average one can emulate cubic spline smoothing (use it 4 times). More applications rapidly emulates a 2d gaussian with standard deviation = N * MEDBOX / 12. ** INCLUDE= Include central pixel in calculation? [Y]/N ** ABSOLUTE= Cutoff as absolute value? Y/[N] If ABSOLUTE=N (the default), the cutoff will be interpreted as a relative value. CUT= Cutoff for replacing the centr.pix. by the med.val.[0.0] There are two modes for the cutoff. The modes are specified in ABSOLUTE= See description. ** REPLACE= Replace blanks by local median? [Y]/N Default, a blank will be replaced by the median of the 'median' box. If REPLACE=N, a blank is NOT replaced. Description: An input set given with INSET= is filtered with a median filter and put in OUTSET=. For each pixel in BOX= the median is calculated in a l x m neighborhood where l and m are specified in MEDBOX=. There are some restrictions for the sizes in MEDBOX= 1) the sizes must be odd. 2) The size in Y direction must be smaller than the number of lines in some buffer (calculated by the program). 3) The size in X-direction cannot exceed the width of the subset. 4) The total number of pixels in the 'median' box cannot exceed the internal buffer size (calculated by the program). The median is calculated by sorting the data in the 'median' box. This can take a while for big boxes. An alternative (without sorting) is in development. You can exclude the value of the central pixel with INCLUDE=NO (default, this pixel will be included). At the edges of the frame, not all neighbor pixels can contribute to the median. If the value of a pixel differs more than CUT= from the median, its value will be replaced by the median, otherwise, it will not be changed. The cutoff can be given as an relative or absolute value: 1) ABSOLUTE=Y, the cutoff is absolute, i.e. if the difference between an image value and the local median is greater than CUT= , replace the image value by the median, else keep the image value. Expressed in statements: diff = |image value - local median| if diff > cutoff return median else return image value 2) ABSOLUTE=N (the default), the cutoff is a relative value and is in the range 0..1. The statements are: diff = | (image value - local median) / median | if diff > cutoff return median else return image value Blank pixels are replaced by the local median if REPLACE=Y (default). If REPLACE=N, blank pixels will not be replaced. Notes: Example: mfilter MFILTER Version 1.0 (May 13 1993) MFILTER INSET=HVC1 Set HVC1 has 2 axes RA from -207 to 207 DEC from -236 to 236 MFILTER BOX= BOX range for set HVC1 : RA from -207 to 207 DEC from -236 to 236 MFILTER OUTSET=hvcmed Set hvcmed has 2 axes RA from -207 to 207 DEC from -236 to 236 MFILTER MEDBOX=5 3 MFILTER CUT=0.1 ==================== MFILTER ==================== Median filter in 5 x 3 neighborhood using cutoff value: 0.100000 in relative mode Name of input set: HVC1 Name of output set: hvcmed MFILTER processed data in 14.57 sec (7.64 cpu sec) MFILTER +++ FINISHED +++ Updates: May 6, 1993: VOG, Document created. May 27, 1998: DoKester, averaging added Feb 1, 2000: JPT, Increased number of subsets.