| Customize Help

Denoise using spatial filtering and area open and close operations

Spatial filtering and area open and close operations are effective ways to reduce noise. Spatial filtering operations determine each pixel's value based on its neighborhood values. They allow images to be separated into high-frequency and low-frequency components. There are two main types of spatial filters that can remove noise: low-pass linear filters and rank filters. Area open and close operations are efficient in removing salt-and-pepper noise in an image.

Spatial filtering and area open and close operations can reduce noise, but are not especially effective at removing mean square errors (MSE). To minimize MSE, try using MimWaveletDenoise(). For more information, see the Wavelet denoising subsection of the Transform and denoise images using wavelets section of Chapter 5: Specialized image processing. Note that to remove Gaussian noise, you can use several techniques, such as spatial filtering, wavelet denoising, or averaging a sequence of grabbed images (see the Averaging an input sequence section earlier in this chapter).

Low-pass spatial linear filters

Low-pass spatial linear filters are effective in reducing Gaussian random noise (and high-frequency systematic noise), provided that the noise frequency is not too close to the spatial frequency of significant image data. These filters replace each pixel with a weighted sum of each pixel's neighborhood. Note, these filters have the side-effect of selectively smoothing your image and removing edge information. To reduce noise while also preserving edges, you can try using MimFilterAdaptive(); for more information, see the Adaptive filters subsection of this section.

You can apply low-pass spatial linear filters using MimConvolve(). MIL provides a predefined low-pass linear filter called M_SMOOTH, which satisfies most applications (other predefined filters are also available). If you require more control over the filtering process, you can use MimConvolve() with a custom filter. For more information, see the Custom spatial filters section of Chapter 4: Advanced image processing.

Rank filters

Rank-filter operations are more suitable for removing salt-and-pepper type noise since they replace each pixel with a pixel in its neighborhood rather than a weighted sum of its neighborhood. The weighted sum generally creates a blotchy effect around each noise pixel.

You can perform a rank-filter operation using MimRank(). In most cases, it is best to use a rank that is half of the number of elements in the neighborhood. This effectively replaces each pixel with the median of the neighborhood and is therefore called a median filter. To perform a median filter, use MimRank() with M_MEDIAN. You will find that the median filter will most often suit your application needs.

For a rank filter operation that adapts to the content of the source image, while also preserving edge information, try using MimFilterAdaptive() with M_NOISE_PEAK_REMOVAL.

Adaptive filters

To remove noise while preserving edge information, use MimFilterAdaptive() with one of its adaptive filter operations. These operations adapt to the content of the source image. You can specify a bilateral filter (M_BILATERAL) or a noise peak elimination filter (M_NOISE_PEAK_REMOVAL). Both types of adaptive filters smooth an image while preserving edges as much as possible. M_BILATERAL is a nonlinear smoothing filter; M_NOISE_PEAK_REMOVAL is similar to a rank filter. Both filters adapt to the content of the source image, while allowing some attributes, such as kernel size or number of iterations, to be explicitly set for the filter operation.

Note that adaptive filters are slower than other similar operations, such as rank filters (MimRank()) and most of the filters available using MimConvolve(). If edge preservation is less important than speed for your application, try the predefined or custom filters available in MimConvolve().

The following example shows M_BILATERAL and M_NOISE_PEAK_REMOVAL adaptive filtering on an image, and also shows a Deriche smoothing filter result (using MimConvolve()) for comparison.

Area open and area close

To eliminate salt-and-pepper noise in your image, you can also perform an area open or area close operation, using MimMorphic() with M_AREA_CLOSE or M_AREA_OPEN. Area open can be used to eliminate small regions of light noise pixels, while area close can do the same to small regions of dark noise pixels.

To understand what the area open and area close operations do, it is useful to think of an image as a topographic surface with hills and valleys. The value of each pixel represents a certain height, with the lowest pixel value (the darkest pixel) representing the point of lowest elevation and the highest pixel value (the brightest pixel) representing the point of highest elevation. The area open operation clips the peaks of hills until each has a plateau with an area equal to or greater than the specified minimum area. If an area of this size never occurs, the peak will be clipped until all the pixels in the hill have the same intensity as the background pixels. The area close operation is similar to the area open operation, except the clipping of intensity levels begins at the lowest level. In this case, you can imagine the bottom of the basins being filled until they have a flat surface area equal to or greater than the specified minimum area.

To implement the area open operation, MIL analyzes the image and clips off peaks one intensity level at a time, starting at the highest pixel intensity level (255 for an 8-bit image). It locks pixels at their current value if the specified minimum area is reached. At each intensity level, the following steps are performed:

  1. Pixels with an intensity level greater than the current intensity level and that have not been previously locked are set to the current intensity level.

  2. The algorithm then considers all pixels with a value equal to or greater than the current value to be foreground pixels, and connected foreground pixels as part of the same object.

  3. The area of each object is compared to the specified minimum area. If it is greater or equal to the specified minimum area, the pixels in the object are locked at their current value for the remainder of the algorithm. The first pixels locked in any area form a plateau.

  4. If the current intensity level is 0, the operation is complete. If not, the algorithm proceeds to the next lower intensity level, and returns to step 1.

In the event that the area of an object at every pixel intensity level never equals or exceeds the specified minimum area, its pixels will eventually be clipped to the background pixel intensity level.

Also, it is possible that distinct objects at one pixel intensity level merge together at a lower pixel intensity level. This situation is illustrated in the following images, which depict a few steps in the area open operation.

As was mentioned earlier, an object is composed of connected foreground pixels. Determining which pixels are connected depends on the selected structuring element, M_3X3_RECT or M_3X3_CROSS. These are the only two structuring elements that can be used with the area open and area close operations.