SMOOTH Function
Smooths an array with a boxcar average of a specified width.
Usage
result = SMOOTH(array, width)
Input Parameters
array—The array to be smoothed. The array can be of any number of dimensions.
note | Use the Intleave keyword to specify interleaving for 2D and 3D arrays. |
width—The width of the smoothing window. Should be an odd number, smaller than the smallest dimension. (If width is even, width + 1 is used instead.)
Returned Value
result—A copy of array smoothed with a boxcar average of the specified width. It has the same type and dimensions as array.
Keywords
Edge—A scalar string indicating how edge effects are handled. (Default: 'copy') Valid strings are:
'zero'—Sets the border of the output image to zero.
'copy'—Copies the border of the input image to the output image. (Default)
Intleave—A scalar string indicating the type of interleaving:
'signal'—Indicates that a mxn array is to be treated as n signals of length m; each signal is smoothed independently.
'image'—Indicates that a mxnxp array is to be treated as p mxn images; each image is smoothed independently.
Discussion
SMOOTH supports input arrays composed of multiple images as well as input arrays composed of multiple signals. The Intleave keyword is used to indicate that the input array is a multi-signal or multi-image array. When the Intleave keyword is used, each signal or image in the array is operated on separately and an array of the individual results is returned.
The default behavior for SMOOTH is to operate on the input array as a single piece of data.
SMOOTH is used to selectively average the elements in an array within a moving window of a given width. The result smooths out spikes or rapid transitions in the data and is usually called a boxcar average. The window is a box that traverses the input array, element by element. As the window moves through the array, all values within the window are averaged. The average value is then placed at the center of the window in the output array, while the original array is kept intact.
Conceptually, the algorithm used by SMOOTH is shown below for the 1D case (n is the number of elements in A and w is the width of the smoothing window, and w/2 is to be interpreted as the greatest integer less than or equal to w/2).
When w/2 ≤ i ≤ n–1–w/2, then:
Otherwise, Ri = Ai.
The 2D case of an n0xn1 array is handled similarly:
when w/2 ≤ ik ≤ nk–1–w/2 (k=0,1), then:
otherwise:
The extension of these equations to higher dimensional arrays is obvious.
note | Rather than explicitly summing over the entire window each time the window is moved, the sum over each new window is computed as the sum over the old window plus the sum over the leading edge of the new window minus the sum over the trailing edge of the old window. This method is computationally efficient, but due to numerical roundoff it may give slightly different results than the explicit method. Double precision input virtually eliminates these differences. |
Sample Usage
Typical uses for the SMOOTH function include:
To remove ripples, spikes, or high frequency noise from a signal or image.
To blur an image or set of data such that only the general trends in the data can be seen (and are thereby highlighted).
To
isolate the lower spatial frequency components in an image. By subtracting a blurred image from the original image, only the higher spatial frequency components are left. (This is sometimes referred to as unsharp masking.)
To soften sharp transitions from one color to another in a color table. This helps reduce the banding or contouring artifact evident in color tables with rapid color changes.
Example
Figure 16-10: Smoothed Image shows what a mandrill image looks like before and after applying the SMOOTH function. For this example, a value of 7 was used for the
width parameter.
See Also
For more information, see the section Image Smoothing in Chapter 6 of the PV‑WAVE User’s Guide.