Home  Index of Lectures  Next >>  PDF Version of this Page 
Noise suppressionwww.kovalevsky.de, last update: October 26, 2011 
Let me know what you think  
The simplest averaging filter The fast averaging filter The fast Gaussian filter Sigma filter: the most efficient one Comparison of different filters 
The unweighted averaging filter calculates the mean gray value in a gliding square window of W*W pixels.
The higher the window size W the stronger is the suppression of noise: the filter decreases the noise
by the factor W. For the sake of symmetry W usually is an odd integer: 3, 5, 7, 9, 11 etc. The window
coordinates (x+xx, y+yy) vary symmetrically around the current pixel (x, y):
The window lies at any image border partially outside of the image. In this case, the computation looses its natural
symmetry because only pixels inside the image can be averaged. A reasonable way to solve the border problem
is to take control of the coordinates (x+xx, y+yy) whether they point out of the image. In this case the summation of
the gray values must be suspended and the divisor nS should not to be incremented.
The simplest slow version of the algorithm has four nested forloops:
int nS, sum; for ( int y=0; y < image0.Height; y++ ) //======================== { for ( int x=0; x < image0.Width; x++ ) //===================== { nS=sum=0; for ( int yy=W/2; yy <= W/2; yy++ ) //=============== { if ( y+yy >= 0 && y+yy < image0.Height ) for ( int xx=W/2; xx <= W/2; xx++ )//========== { if ( x+xx >= 0 && x+xx < image0.Width ) { sum+=image0.GetPixel( x+xx, y+yy ); nS++; } } //====== end for (int xx... ================== } //======== end for (int yy... ==================== image1.SetPixel( x, y, (sum+nS/2)/nS);//+nS/2 for rounding } //============ end for (int x... =========================== } //============== end for (int y... =============================
where x, y are the indices of both image0 and image1 and xx,yy the indices of the pixels in the
averaging window.
Then computation of each sum in the innermost forloop needs W*W additions and W*W accesses to the
image per one pixel,
which is quite time consuming.
The fast averaging filter solves the same problem, but it is much faster. The fast filter blurs the image as the simple filter does.
Therefore its main
application area is shading correction rather than noise suppression. The best filter for Gaussian noise suppression is the sigma
filter described below.
Using the following basic idea, it is possible to reduce the number of operations per pixel from W*W to
≈4:
The filter first calculates and saves the sum of the gray values in each column of W pixels, while the middle pixel of each
column lies in the current row of the image. The filter then directly calculates the sum over the window having its central pixel at
the beginning of a row, i.e. by adding up the sums saved in the columns. Then the window moves one pixel along the row, and the
filter calculates the sum for the next location by adding the value of the column at the right border of the window and by
subtracting the value of the column at the left border. It is necessary to check, whether the column to be added or subtracted is
in the image. If it is not, the corresponding addition or subtraction must be skipped.
Applying a similar procedure to sum up the columns, the average number of additions/subtractions per pixel is reduced to
≈2+2=4.
When proceeding to the next row of the image, the filter updates the values of the columns by adding the gray value below the lower
end and subtracting the gray value at the upper end of each column. Also in this case it is necessary to check, whether the gray
value to be added or subtracted is in the image. As soon as the sum of the gray values in a window is calculated, the filter divides (with rounding) the sum by the number of pixels in the intersection of the window with the image and saves the result in the corresponding pixel of the output image. 
The fast Gaussian filterThe simple averaging filter produces a smoothed image, in which some rectangular shapes not present in the original image may be
seen. These shapes arrive since the averaging filter transforms each light pixel to a homogeneously light rectangle of the size of
the filter window. As soon as a pixel has an "outstanding" gray value, which differs from the values of adjacent pixels by
a great amount, the rectangle becomes visible. This is an unwanted distortion. It can be avoided when using the Gaussian filter that
multiplies the gray values to be added by values which decay with the distance from the centre of the window according to the Gauss
law.
The values of the Gauss law are floats less than 1. They can be calculated in advance and saved in a twodimensional array. Then the
gray values must be multiplied by these values and the sum of the products must be calculated. This procedure needs
