C# Класс Accord.Imaging.Filters.IterativeThreshold

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):

Наследование: Threshold
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
CalculateThreshold ( Bitmap image, Rectangle rect ) : int

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

CalculateThreshold ( BitmapData image, Rectangle rect ) : int

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

CalculateThreshold ( UnmanagedImage image, Rectangle rect ) : int

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

IterativeThreshold ( ) : System

Initializes a new instance of the IterativeThreshold class.

IterativeThreshold ( int minError ) : System

Initializes a new instance of the IterativeThreshold class.

IterativeThreshold ( int minError, int threshold ) : System

Initializes a new instance of the IterativeThreshold class.

Защищенные методы

Метод Описание
ProcessFilter ( UnmanagedImage image, Rectangle rect ) : void

Process the filter on the specified image.

Описание методов

CalculateThreshold() публичный Метод

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

Source pixel format is not supported by the routine. It should /// 8 bpp grayscale (indexed) or 16 bpp grayscale image.
public CalculateThreshold ( Bitmap image, Rectangle rect ) : int
image System.Drawing.Bitmap Image to calculate binarization threshold for.
rect System.Drawing.Rectangle Rectangle to calculate binarization threshold for.
Результат int

CalculateThreshold() публичный Метод

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

Source pixel format is not supported by the routine. It should /// 8 bpp grayscale (indexed) or 16 bpp grayscale image.
public CalculateThreshold ( BitmapData image, Rectangle rect ) : int
image System.Drawing.Imaging.BitmapData Image to calculate binarization threshold for.
rect System.Drawing.Rectangle Rectangle to calculate binarization threshold for.
Результат int

CalculateThreshold() публичный Метод

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

Source pixel format is not supported by the routine. It should /// 8 bpp grayscale (indexed) or 16 bpp grayscale image.
public CalculateThreshold ( UnmanagedImage image, Rectangle rect ) : int
image UnmanagedImage Image to calculate binarization threshold for.
rect System.Drawing.Rectangle Rectangle to calculate binarization threshold for.
Результат int

IterativeThreshold() публичный Метод

Initializes a new instance of the IterativeThreshold class.
public IterativeThreshold ( ) : System
Результат System

IterativeThreshold() публичный Метод

Initializes a new instance of the IterativeThreshold class.
public IterativeThreshold ( int minError ) : System
minError int Minimum allowed error, that ends the iteration process.
Результат System

IterativeThreshold() публичный Метод

Initializes a new instance of the IterativeThreshold class.
public IterativeThreshold ( int minError, int threshold ) : System
minError int Minimum allowed error, that ends the iteration process.
threshold int Initial threshold value.
Результат System

ProcessFilter() защищенный Метод

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage image, Rectangle rect ) : void
image UnmanagedImage Source image data.
rect System.Drawing.Rectangle Image rectangle for processing by the filter.
Результат void