Smooths an image using a mode filter
Smooths an image by applying a mode filter using a moving window. The value of the center pixel in the window is replaced by the mode of the other pixels within the window, subject to user-specified conditions. Certain pixel values may be weighted when the mode is determined. Also, the user may specify a smoothing threshold; the pixel value is replaced by the mode only if the mode frequency is greater than the threshold.
- IN
- Input image. It must be a single-band, BYTE image.
- OUT
- Output image. The output image created by applying a mode filter to the input image. It is always a BYTE image.
- WINDOW(3,3)
- Window specification. Specifies the number of lines and the number of samples in the sliding window (filter cell). Both values must be odd integers from 3 to 15. Defaults to (3,3).
- SMTHRVAL(0)
- Smoothing threshold value. Sample values will be smoothed only if the window mode frequency is larger than SMTHRVAL. Defaults to 0.
- CLASSNUM(--)
- Class Numbers. An array of classes (pixel values, from 0 to 255) that the user wishes to emphasize by applying weights. Default indicates that all classes are processed with a weight of one.
- WEIGHTS(--)
- Weight values. A real array containing weights corresponding to the classes specified by CLASSNUM. Default indicates that all classes are processed with a weight of one.
- MASKVAL(--)
- Mask values. An array of classes (pixel values, from 0 to 255) that are not smoothed regardless of surrounding pixel values or specified threshold. Default indicates no classes are specified.
The input image TEST.DAT is smoothed using the default window size and is output to TEST.OUT.
The input image TEST.DAT is smoothed with the default window. The sample counts for classes 100 and 200 are weighted by 2.0 and 4.0, respectively. Also, sample values are smoothed only if the frequency of the window mode after weighting is greater than 3. Sample values of 128 and 200 are not smoothed.
The input image TEST.DAT is smoothed using a 5 x 5 window and is output to TEST.OUT.
The mode filter is applied to all samples except those on the edge of the image. No sample values on the edge are changed. Since the filter window must be completely contained within the input image area, the edge with unfiltered samples has a width equal to (m-1)/2 or (n-1)/2, where (m,n) is the size of the filter. That is, the width of the left and right edges is (m-1)/2 and the top and bottom edges is (n-1)/2. The value for each sample not on the edge of the image is replaced by the mode of sample values in the filter cell surrounding it, subject to the user-defined weights and smoothing threshold.
Consider the m x n neighborhood of a nonedge sample, P, in the input image. Let the number of occurrences of the ith class (i.e., pixel value) in the neighborhood be f . If the input image value at P is not i one of the values specified in MASKVAL then the mode of w f , i i i=0,...,255 is found, where w = 1 unless the class i appears in i CLASSNUM. In that case, w is the corresponding element in WEIGHTS. i If the mode occurs at j (i.e., w f >w f for all i), and w f > SMTHRVAL j j i i j j then the sample value at P is set to j. Otherwise, the sample value at P remains unchanged. If more than one j satisfies the above conditions, the smallest such value is assigned to P.For example, if the value 100 has a weight of 5 defined by the CLASSNUM and WEIGHTS arrays, each occurrence of a sample value of 100 in the window counts as five occurrences in the mode calculation. If SMTHRVAL has been defined as 4, the center sample value is replaced by the mode only if the frequency of the mode is greater than 4. When several sample values share the highest frequency in the cell, the lowest value is used as the mode.
Respecify image of type BYTE.
Respecify single band image.
Use a smaller window.
Use a smaller window.
Respecify equal number of weights and classes.