FILT_NONLIN Function
Performs nonlinear filtering operations on 1D, 2D, or 3D image arrays.
Usage
result = FILT_NONLIN(image, wxdim[, wydim[, wzdim]])
Input Parameters
image—1D, 2D or 3D array containing a signal; point or signal-interleaved signals; an image; image, row or pixel-interleaved images; or a volume.
wxdim—The width of the filtering window.
wydim—(optional) The height of the filtering window. (Used for images and volumes.)
wzdim—(optional) The depth of the filtering window. (Used for volumes.)
Returned Value
result—An array containing the filtered data that is of the same size and dimensions as image, unless otherwise affected using the Edge keyword.
Keywords
Atmeanf—If set, applies an alpha-trimmed mean filter.
Chmeanf—If set, applies a contra-harmonic mean filter.
Edge—A scalar string indicating how edge effects are handled. (Default: 'zero'). Valid strings are:
*'pad'—The input image is padded before the filtering operation with the value specified using the Pad_Value keyword.
*'zero'—Sets the border of the output image to zero. (Default)
*'copy'—Copies the border of the input image to the output image.
*'reduce'—Returns a reduced-size image that is smaller than the input image by the kernel dimensions.
Filt_Type—A scalar byte indicating which nonlinear filter (listed in Table 10-2: Nonlinear Filters) to apply. This keyword may be used in place of the corresponding filter keywords (Maxf, Minf, ..., Ypmeanf). (Default: 0)
 
Nonlinear Filters
Filt_Type (scalar)
Nonlinear Filter Type
Corresponding Keyword
0 (default)
Maximum Filter (default)
Maxf
1
Minimum Filter
Minf
2
Range Filter
Rangef
3
Geometric Mean Filter
Gmeanf
4
Mode Filter
Modef
5
Rank Filter
Rankf
6
Alpha-Trimmed Mean Filter
Atmeanf
7
Contra-Harmonic Mean Filter
Chmeanf
8
Yp Mean Filter
Ypmeanf
F_Order—A scalar value that specifies the order of the filter.
 
note
The F_Order keyword is only valid for the Yp mean and contra-harmonic mean filters.
Gmeanf—If set, applies a geometric mean filter.
Intleave—A scalar string indicating the type of interleaving of 2D input signals and 3D image arrays. Valid strings and the corresponding interleaving methods are:
*'point'—The 2D input array arrangement is (px) for p  point-interleaved signals of length x.
*'signal'—The 2D input image array arrangement is (xp) for p  signal-interleaved signals of length x.
*'pixel'—The input array arrangement is (pxy) for p  pixel-interleaved images of x-by-y.
*'row'—The 3D image array arrangement is (xpy) for p  row-interleaved images of x-by-y.
*'image'—The 3D image array arrangement is (xyp) for p  image-interleaved images of x-by-y.
*'volume'—The input image array is treated as a single entity.
Maxf—If set, applies a maximum filter.
Minf—If set, applies a minimum filter.
Modef—If set, applies a mode filter.
Pad_Value—A scalar value to use for the image padding. (Default: 0)
 
 
The Pad_Value keyword is valid only when Edge = 'pad'.
Rangef—If set, applies a range filter.
Rankf—If set, applies a rank filter.
Rank_Num—Rank number of the rank filter. The value must be in the range: 0 Rank_Num < the number of elements in the filter window.
 
 
The Rank_Num keyword is required when the rank filter is specified.
Spot—This keyword specifies explicit positioning of the element number of the filter window “sweet spot.” The Spot keyword default depends on the setting of the Edge keyword as shown in Table 10-1: Edge and Spot Keywords Relationships.
Trim—Scalar integer or long value specifying the number of array values to trim from the mean calculation. The value must be in the range:
0 Trim < 1/2 (N – 1)
where N is the number of elements in the filter window.
 
note
The Trim keyword is required when the alpha-trimmed mean filter is specified.
Ypmeanf—If set, a Yp mean filter is applied
Zero_Negatives—If set, all negative values in the result are set to zero.
Discussion
The filter type can be specified using the Filt_Type keyword, or any of the specific filter keywords. No more than one filter type can be defined at one time. The default filter type for the function is the Filt_Type keyword default of 0, meaning the maximum filter is applied.
Geometric Mean Filter
The geometric-mean filter is a nonlinear filter sometimes used for removing Gaussian distributed noise. Each pixel in the result is computed as the product of the N pixels to the N–1 power within the filter window of N elements defined by wxdim, wydim, and/or wzdim.
Maximum Filter
The maximum filter is a nonlinear filter that can be used for removing outlying low or negative values from an image. Each pixel in result is computed as the maximum of the N pixels within the filter window of N elements defined by wxdim, wydim, and/or wzdim.
Minimum Filter
The minimum filter is a nonlinear filter that can be used for removing outlying high values from an image. Each pixel in result is computed as the minimum of the N pixels within the filter window of N elements defined by wxdim, wydim, and/or wzdim.
Mode Filter
The mode filter is a nonlinear filter that can be used for noise removal. Each pixel in result is computed as the mode (the most frequent pixel value) of the N pixels within the filter window of N elements defined by wxdim, wydim, and/or wzdim.
Range Filter
The range filter is a nonlinear filter used for edge detection. Each pixel in result is computed as the range (the maximum minus the minimum) of the filter window of N elements defined by wxdim, wydim, and/or wzdim.
Rank Filter
The rank filter is a nonlinear filter that can be used for removal of impulse noise. Each pixel in result is computed as the rank of the filter window of N elements defined by wxdim, wydim, and/or wzdim. The rank is defined as the value of the pixel in the Rank_Num position when all pixels in the filtering window are arranged in ascending order. The rank filter degenerates to the MEDIAN filter when:
Alpha-Trimmed Mean Filter
The alpha-trimmed mean filter is used to remove noise from images corrupted with both Gaussian and impulse noise. The output of the alpha-trimmed mean filter is the mean of the pixels in the filter window, with a number of values, defined by Trim, excluded. First, the pixels in the filter window are arranged in ascending order according to grayscale value. The output is then calculated from:
where the filter window has N elements and Ai are the grayscale values in the window A1 A2 ... AN .
Contra-Harmonic Mean Filter
The contra-harmonic mean filter is useful for removing Gaussian noise without destroying edge features. The output is calculated from:
for each pixel, Ai in the filter window of size N.
Yp Mean Filter
The Yp mean filter is useful for removing Gaussian noise, while preserving edge features. For negative values of F_Order, the Yp mean filter removes positive outliers. For positive values of F_Order, the Yp mean filter removes negative outliers. The output of the Yp mean filter is:
Example 1
Use the Yp mean filter for removing Gaussian noise while preserving image edges.
; Read an image.
image = IMAGE_READ(!IP_Data + 'face.tif')
noise = NOISE_GEN(image('width'), image('height'), $
/Normal, High = 128, Low = 50)
; Corrupt the image with Gaussian noise.
noise_image = IPMATH(image('pixels'), '+', noise)
; Try to remove the noise using the Yp mean filter.
yp_image = FILT_NONLIN(noise_image, 3, 3, $
F_Order = 2.0, /Ypmeanf)
; Display the image.
TVSCL, yp_image
Example 2
The rank filter is the same as the median filter when the rank number is set to the filter window center. The results of this example are shown in Figure 10-4: Original Image, Figure 10-5: Corrupted Image, and Figure 10-6: Filtered Image.
; Read an image.
image = IMAGE_READ(!IP_Data + 'airplane.tif')
; Display the original image.
IMAGE_DISPLAY, image
pixels = image('pixels')
; Corrupt the image with speckle noise.
status = NOISE_IMPULSE(0.15, pixels)
image('pixels') = pixels
IMAGE_DISPLAY, image
; Remove the noise using a rank filter.
rank_image = FILT_NONLIN(image('pixels'), 3, 3, $
Rank_Num = 4, /Rankf)
; Display the image.
TVSCL, rank_image
 
Figure 10-4: Original Image
 
Figure 10-5: Corrupted Image
 
Figure 10-6: Filtered Image
See Also
In the PV‑WAVE Reference:  MEDIAN