Copyright © Fred Weinhaus My scripts are available free of charge for non-commercial (non-profit) use, ONLY. For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net. If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment. Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php Please read the Pointers For Use on my home page to properly install and customize my scripts. |
Various statistical filters primarily used to reduce noise in an image |
last modified: December 15, 2018
USAGE: statsfilt [-s statistic] [-p power] infile outfile
Option PURPOSE: To compute various localized (neighborhood) statistical filters on an image. DESCRIPTION: STATSFILT is a collection of localized (neighborhood) statistical filters most of which are used for mostly for noise reduction in an image. Note that most noise reduction filters trade noise reduction for some degree of blurring. Arguments: -h or help ..... displays help information. -s ..... statistic ..... statistic is a numerical id for the type of statistic to be calculated. A value of 1 replaces each input pixel with the simple average (or arithmetic mean) of all the pixels in the 3x3 neighborhood about that input pixel. A value of 2 replaces the input pixel with the minimum value found in the neighborhood. A value of 3 replaces the input pixel with the maximum value found in the neighborhood. A value of 4 replace the input pixel with average of the minimum and maximum values in the neighborhood. A value of 5 replaces the input pixel with simple average of all the pixels in the neighborhood, except the minimum and maximum values. Thus it is throwing out the two extreme outliers. A value of 6 replaces the input pixel with the standard deviation of all the pixels in the neighborhood. This is more of an edge operator that a noise reduction operator. A value of 7 replaces the input pixel with geometric mean of all the pixels in the neighborhood. The geometric mean is computed by taking the ln of each neigborhood pixel value, averaging these values and then taking the exp of the result. The geometric mean is used especially for noise reduction when dealing with one-sided noise that is all bright spikes (but not well at all dark spikes). A value of 8 replaces the input pixel with the harmonic mean of all the pixels in the neighborhood. The harmonic mean is computed by taking the inverse of each pixel value, averaging these results and then taking the inverse of the result. The harmonic mean is used especially for noise reduction when dealing with one-sided noise that is all bright spikes (but not well at all dark spikes). A value of 9 replaces the input pixel with the Lp mean of all the pixels in the neighborhood. The Lp mean is computed by raising each pixel value in the neighborhood to some power, averaging these results and then raising the result to the equivalent inverse power (i.e. the negative value of the power). A choice of p=0 is not allowed. Typically p is a low valued integer, i.e. 2 or -2. Note that p=1 is equivalent to the simple average (arithmetic mean) and p=-1 is equivalent to the harmonic mean. The Lp mean is used especially for noise reduction when dealing with one-sided noise that is either all bright spikes or all dark spikes. For all bright spikes, use negative p values and for all dark spikes, use positive p values. A value of 10 replaces the input pixel with the contraharmonic mean of all the pixels in the neighborhood. The contraharmonic mean is computed by taking the average of all the pixels in the neighborhood raised to the power p+1 and dividing that by the average of all the pixels in the neighborhood raised to the power p. The power p can be any integer. A choice of p=-1 is not allowed. Note that p=0 is equivalent to the simple average (arithmetic mean). The contraharmonic mean is used especially for noise reduction when dealing with one-sided noise that is either all bright spikes or all dark spikes. For all bright spikes, use negative p values and for all dark spikes, use positive p values. A value of 11 replaces each pixel in the input image with a linear distance weighted average of all pixels in the neighborhood, except the original center pixel. Weighting is measured as one minus the absolute difference between the graylevel of each neighbor and the center pixel. Thus pixels with smaller differences (i.e. values closer to that of the the center pixel) are weighted higher. A value of 12 replaces each pixel in the input image with an inverse distance weighted average of all pixels in the neighborhood, except the original center pixel. Weighting is measured as inverse of the absolute difference between the graylevel of each neighbor and the center pixel. Thus pixels with smaller differences (i.e. values closer to that of the the center pixel) are weighted higher. A value of 13 replaces each pixel in the input image with either the minimum or maximum value of all pixels in the neighborhood, whichever is closest in value to the given (center) pixel. This produces a sharpening effect on the image. A value of 14 replaces each pixel in the input image with the average of all the pixels in the neighborhood, but the center pixel. All of these statistical filters are computed within a 3x3 neighborhood only. As it is, some of the latter statistics take a very long time to compute as this script is based up the use of fx. -p ..... power ..... exponent value to use to raise the pixel value to the given power. The values may be positive or negative integers. The default is 2 WARNING: Due to the use of -fx, some of these filters are slow. On a Macintosh PowerPC G4, 1.42GHz with 512 Mbytes RAM and an image size of 128x128 pixels, it takes only a few seconds to run filters 1-10, 13 and 14, but about 20 seconds for filters 11 and 12. CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. |
Some General Statistical Filters
Original Image |
Arithmetic Mean |
Minimum |
Maximum |
Average of |
Standard Deviation |
Min or Max |
|
Filtering Of Bright and Dark Noise
Noisy Image |
Arithmetic Mean |
Arithmetic Mean |
Geometic Mean |
Harmonic Mean |
Lp Mean |
Contraharmonic Mean |
Linear Distance |
Inverse Distance |
Filtering Of Bright Only Noise
Noisy Image |
Arithmetic Mean |
Arithmetic Mean |
Geometic Mean |
Harmonic Mean |
Lp Mean |
Lp Mean |
Contraharmonic Mean |
|
Filtering Of Dark Only Noise
Noisy Image |
Arithmetic Mean |
Arithmetic Mean |
Lp Mean |
Lp Mean |
Contraharmonic Mean |
Comparison To Other Methods For Dense Bright Noise
Noisy Image |
Arithmetic Mean |
Arithmetic Mean |
Arithmetic Mean |
Arithmetic Mean |
|
Geometic Mean |
Harmonic Mean |
Lp Mean |
Lp Mean |
Contraharmonic Mean |
|
|
|||||
Median |
Median |
Median |
IM Noise Removal |
IM Noise Removal |
|
What the script does is as follows:
This is equivalent to the following IM commands for the case of
|