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
Example #1
0
        private void SetFilter()
        {
            ImageType = ImageTypes.GrayscaleBT709;
            Af.IterativeThreshold newFilter = new Af.IterativeThreshold();
            newFilter.MinimumError   = (int)Remap(minimum, 0, 10);
            newFilter.ThresholdValue = (int)Remap(threshold, 0, 255);

            imageFilter = newFilter;
        }