Iterative threshold search and binarization.

The algorithm works in the following way: select any start threshold; compute average value of Background (µB) and Object (µO) values: 1) all pixels with a value that is below threshold, belong to the Background values; 2) all pixels greater or equal threshold, belong to the Object values. calculate new thresghold: (µB + µO) / 2; if |oldThreshold - newThreshold| is less than a given manimum allowed error, then stop iteration process and create the binary image with the new threshold.

For additional information see Digital Image Processing, Gonzalez/Woods. Ch.10 page:599.

The filter accepts 8 and 16 bpp grayscale images for processing.

Since the filter can be applied as to 8 bpp and to 16 bpp images, the initial value of Threshold.ThresholdValue property should be set appropriately to the pixel format. In the case of 8 bpp images the threshold value is in the [0, 255] range, but in the case of 16 bpp images the threshold value is in the [0, 65535] range.

Sample usage:

// create filter IterativeThreshold filter = new IterativeThreshold( 2, 128 ); // apply the filter Bitmap newImage = filter.Apply( image );

Initial image:

Result image (calculated threshold is 102):

Inheritance: Threshold
コード例 #1
0
 /// <summary>
 /// Binarize image with iterative threshold filter
 /// </summary>
 /// <param name="image"></param>
 /// <param name="threshold">threshold for binarization</param>
 public static Image IterativeThreshold(this Image image, byte threshold)
 {
     IterativeThreshold thresholdFilter = new IterativeThreshold(2, threshold);
     return thresholdFilter.Apply(BitmapGrayscale(image));
 }
コード例 #2
0
ファイル: Realce.cs プロジェクト: mondedos/us_pidentrullador
        public Bitmap BinarizacionIterativa()
        {
            Atributos atr = Atributos.getInstance();

            IterativeThreshold it = new IterativeThreshold(2, (byte)atr.umbralBinarizacion);
            imagen = it.Apply(imagen);
            umbral = it.ThresholdValue;
            return imagen;
        }