If you are interested in the complete C++ code of the fast Gauss filter including border and color handling, write to kovalev@tfh-berlin.de
Sigma filter: the most efficient one
Both the averaging and the Gaussian filter blur the image. The averaging filter replaces each pixel of brightness B by a
square of WxW pixels with the brightness B/(WxW). Thus steep edges of homogeneous regions become transformed to
ramps of the width W.
The idea of the sigma-filter consists in averaging only those gray values in a window, which differ from the gray value of the
central pixel by no more than a fixed parameter "sigma". The pseudo-code:
sum=0; number=0; M=Input(X,Y);
for each pixel Input(x,y) in the window with the centre at (X,Y):
if (abs(Input(x,y)-M) < sigma) { sum+=Input(x,y); number++;}
Output(X,Y)=Round(sum/number);
This naïve solution would work, but it would be rather slow: it needs in the worst case OPP=4*W 2 operations per
pixel.
Unfortunately, it is impossible to apply in this case the method used in the fast averaging filter since the procedure is
non-linear.
The procedure can be made faster due to the use of a local histogram.
The histogram is an array, in which each element contains the number of occurrences of the corresponding gray value in the window.
The sigma filter calculates the histogram for each location of the window by means of the updating procedure:
gray values in the vertical column at the right border of the window are used to increase the corresponding values of the
histogram, while the values at the left border are used to decrease them:
OPP is the number of operations per pixel.
2*W is the number of operations necessary to actualize the histogram and 2*(2*sigma+1) is the number of operations
necessary to calculate the sum of 2*sigma+1 values of the histogram and the corresponding number of pixels.
Thus the overall OPP = 2*W+2*(2*sigma+1).
|
Comparison of different filters
The averaging and the Gaussian filter provide the most efficient suppression of the noise; however, they blur the image. The
averaging filter with the window of W=(2*h+1) pixels transforms steep edges of homogeneous regions to ramps
of the width W.
The median filter is very popular. However, it is hardly known that it damages the image in a rather bad way: a median filter with
the window of (2*h+1)*(2*h+1) pixels "bites off" a triangle of
h*(h+1)/2 pixels from each corner of a rectangular region.
![](Images/Folie10a.jpg) | | ![](Images/Folie10b.jpg) |
Original image | | Filtered by median 5x5 |
Even more: median inverts an image with alternating black and white stripes of the width h (except at the border of the
image), i.e. black becomes white and vice versa.
The sigma-filter is the best one. When the parameters h and sigma are properly chosen, the filter preserves
steep edges and does not destroy fine details of the image. The only drawback is the necessity to choose the parameters corresponding
to a particular class of images. A class is characterized by the size of fine details and by the intensity of noise. By the way,
there is a possibility, to automatically measure the intensity of noise and thus to automatically choose the value of
sigma.
Next figure shows the results of applying different filters to an image.
If you are interested in details, write to kovalev@beuth-hochschule.de
Download: Print version
|