Click or drag to resize
Accord.NET (logo)

IterativeThreshold Class

Iterative threshold search and binarization.
Inheritance Hierarchy
SystemObject
  Accord.Imaging.FiltersBaseInPlacePartialFilter
    Accord.Imaging.FiltersThreshold
      Accord.Imaging.FiltersIterativeThreshold

Namespace:  Accord.Imaging.Filters
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
public class IterativeThreshold : Threshold
Request Example View Source

The IterativeThreshold type exposes the following members.

Constructors
  NameDescription
Public methodIterativeThreshold
Initializes a new instance of the IterativeThreshold class.
Public methodIterativeThreshold(Int32)
Initializes a new instance of the IterativeThreshold class.
Public methodIterativeThreshold(Int32, Int32)
Initializes a new instance of the IterativeThreshold class.
Top
Properties
  NameDescription
Public propertyFormatTranslations
Format translations dictionary.
(Inherited from Threshold.)
Public propertyMinimumError
Minimum error, value when iterative threshold search is stopped.
Public propertyThresholdValue
Threshold value.
(Inherited from Threshold.)
Top
Methods
  NameDescription
Public methodApply(Bitmap)
Apply filter to an image.
(Inherited from BaseInPlacePartialFilter.)
Public methodApply(BitmapData)
Apply filter to an image.
(Inherited from BaseInPlacePartialFilter.)
Public methodApply(UnmanagedImage)
Apply filter to an image in unmanaged memory.
(Inherited from BaseInPlacePartialFilter.)
Public methodApply(UnmanagedImage, UnmanagedImage)
Apply filter to an image in unmanaged memory.
(Inherited from BaseInPlacePartialFilter.)
Public methodApplyInPlace(Bitmap)
Apply filter to an image.
(Inherited from BaseInPlacePartialFilter.)
Public methodApplyInPlace(BitmapData)
Apply filter to an image.
(Inherited from BaseInPlacePartialFilter.)
Public methodApplyInPlace(UnmanagedImage)
Apply filter to an unmanaged image.
(Inherited from BaseInPlacePartialFilter.)
Public methodApplyInPlace(Bitmap, Rectangle)
Apply filter to an image or its part.
(Inherited from BaseInPlacePartialFilter.)
Public methodApplyInPlace(BitmapData, Rectangle)
Apply filter to an image or its part.
(Inherited from BaseInPlacePartialFilter.)
Public methodApplyInPlace(UnmanagedImage, Rectangle)
Apply filter to an unmanaged image or its part.
(Inherited from BaseInPlacePartialFilter.)
Public methodCalculateThreshold(Bitmap, Rectangle)
Calculate binarization threshold for the given image.
Public methodCalculateThreshold(BitmapData, Rectangle)
Calculate binarization threshold for the given image.
Public methodCalculateThreshold(UnmanagedImage, Rectangle)
Calculate binarization threshold for the given image.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodProcessFilter
Process the filter on the specified image.
(Overrides ThresholdProcessFilter(UnmanagedImage, Rectangle).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields
  NameDescription
Protected fieldthreshold
Threshold value.
(Inherited from Threshold.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

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.

Note Note
Since the filter can be applied as to 8 bpp and to 16 bpp images, the initial value of 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):

See Also