Image Processing Toolbox | ![]() ![]() |
Noise Removal
Digital images are prone to a variety of types of noise. There are several ways that noise can be introduced into an image, depending on how the image is created. For example:
The toolbox provides a number of different ways to remove or reduce noise in an image. Different methods are better for different kinds of noise. The methods available include:
Also, in order to simulate the effects of some of the problems listed above, the toolbox provides the imnoise
function, which you can use to add various types of noise to an image. The examples in this section use this function.
Linear Filtering
You can use linear filtering to remove certain types of noise. Certain filters, such as averaging or Gaussian filters, are appropriate for this purpose. For example, an averaging filter is useful for removing grain noise from a photograph. Because each pixel gets set to the average of the pixels in its neighborhood, local variations caused by grain are reduced.
See Linear Filtering for more information.
Median Filtering
Median filtering is similar to using an averaging filter, in that each output pixel is set to an "average" of the pixel values in the neighborhood of the corresponding input pixel. However, with median filtering, the value of an output pixel is determined by the median of the neighborhood pixels, rather than the mean. The median is much less sensitive than the mean to extreme values (called outliers). Median filtering is therefore better able to remove these outliers without reducing the sharpness of the image.
The medfilt2
function implements median filtering. The example below compares using an averaging filter and medfilt2
to remove salt and pepper noise. This type of noise consists of random pixels being set to black or white (the extremes of the data range). In both cases the size of the neighborhood used for filtering is 3-by-3.
First, read in the image and add noise to it.
Figure 10-12: Eight.tif Before and After Adding Salt-and-Pepper Noise
Now filter the noisy image and display the results. Notice that medfilt2
does a better job of removing noise, with less blurring of edges.
K = filter2(fspecial('average',3),J)/255; L = medfilt2(J,[3 3]); figure, imshow(K) figure, imshow(L)
Figure 10-13: Noisy Version of Eight.tif Filtered with Averaging Filter (left) and Median Filter (right)
Median filtering is a specific case of order-statistic filtering, also known as rank filtering. For information about order-statistic filtering, see the reference page for the ordfilt2
function.
Adaptive Filtering
The wiener2
function applies a Wiener filter (a type of linear filter) to an image adaptively, tailoring itself to the local image variance. Where the variance is large, wiener2
performs little smoothing. Where the variance is small, wiener2
performs more smoothing.
This approach often produces better results than linear filtering. The adaptive filter is more selective than a comparable linear filter, preserving edges and other high frequency parts of an image. In addition, there are no design tasks; the wiener2
function handles all preliminary computations, and implements the filter for an input image. wiener2
, however, does require more computation time than linear filtering.
wiener2
works best when the noise is constant-power ("white") additive noise, such as Gaussian noise. The example below applies wiener2
to an image of Saturn that has had Gaussian noise added.
I = imread('saturn.tif'); J = imnoise(I,'gaussian',0,0.005); K = wiener2(J,[5 5]); imshow(J) figure, imshow(K)
Figure 10-14: Noisy Version of Saturn.tif Before and After Adaptive Filtering
For an interactive demonstration of filtering to remove noise, try running nrfiltdemo
.
![]() | Intensity Adjustment | Region-Based Processing | ![]() |