ImageDev

AutoThresholdingValue

Computes a threshold value partitioning automatically a gray level image into two classes.

Access to parameter description

For an introduction: This algorithm computes an automatic threshold on a grayscale image; that is, separates the input image histogram in two classes of pixels from an input range $[I_1, I_2]$. Each class can be either considered as background or foreground depending on the acquisition device and the nature of the scene.

Four methods of classification are available to determine $C_0$ and $C_1$: Entropy, Factorisation, Moments, and Isodata. These methods are detailed in the AutoThresholdingBright documentation.
The computed threshold is returned in the AutoThresholdingMsr object. See also

Function Syntax

This function returns outputMeasurement.
// Function prototype
AutoThresholdingMsr::Ptr autoThresholdingValue( std::shared_ptr< iolink::ImageView > inputGrayImage, AutoThresholdingValue::RangeMode rangeMode, iolink::Vector2d intensityInputRange, AutoThresholdingValue::ThresholdCriterion thresholdCriterion, AutoThresholdingMsr::Ptr outputMeasurement = nullptr );
This function returns outputMeasurement.
// Function prototype.
auto_thresholding_value(input_gray_image: idt.ImageType,
                        range_mode: AutoThresholdingValue.RangeMode = AutoThresholdingValue.RangeMode.MIN_MAX,
                        intensity_input_range: Union[Iterable[int], Iterable[float]] = [0, 255],
                        threshold_criterion: AutoThresholdingValue.ThresholdCriterion = AutoThresholdingValue.ThresholdCriterion.ENTROPY,
                        output_measurement: Union[Any, None] = None) -> AutoThresholdingMsr
This function returns outputMeasurement.
// Function prototype.
public static AutoThresholdingMsr
AutoThresholdingValue( IOLink.ImageView inputGrayImage,
                       AutoThresholdingValue.RangeMode rangeMode = ImageDev.AutoThresholdingValue.RangeMode.MIN_MAX,
                       double[] intensityInputRange = null,
                       AutoThresholdingValue.ThresholdCriterion thresholdCriterion = ImageDev.AutoThresholdingValue.ThresholdCriterion.ENTROPY,
                       AutoThresholdingMsr outputMeasurement = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputGrayImage
The input grayscale image Image Grayscale nullptr
input
rangeMode
The way to determine the input intensity range.
MIN_MAX The histogram is computed between the minimum and the maximum of the image.
OTHER The histogram is computed between user-defined bounds [a,b].
Enumeration MIN_MAX
input
intensityInputRange
The input intensity range [a,b] inside which the threshold is searched. This parameter is ignored if the range mode is set to MIN_MAX. Vector2d Any value {0.f, 255.f}
input
thresholdCriterion
The criterion to compute the threshold from the histogram.
ENTROPY The measurement of dispersion used in the algorithm is the entropy of the intensity distribution.
FACTORISATION The measurement of dispersion used in the algorithm is the variance of the intensity distribution (also known as the Otsu method).
MOMENTS The measurement of dispersion used in the algorithm is the moments of the intensity distribution.
ISODATA The measurement of dispersion used in the algorithm is the isodata of the intensity distribution.
Enumeration ENTROPY
output
outputMeasurement
The output measurement containing the computed threshold. AutoThresholdingMsr nullptr
Parameter Name Description Type Supported Values Default Value
input
input_gray_image
The input grayscale image image Grayscale None
input
range_mode
The way to determine the input intensity range.
MIN_MAX The histogram is computed between the minimum and the maximum of the image.
OTHER The histogram is computed between user-defined bounds [a,b].
enumeration MIN_MAX
input
intensity_input_range
The input intensity range [a,b] inside which the threshold is searched. This parameter is ignored if the range mode is set to MIN_MAX. vector2d Any value [0, 255]
input
threshold_criterion
The criterion to compute the threshold from the histogram.
ENTROPY The measurement of dispersion used in the algorithm is the entropy of the intensity distribution.
FACTORISATION The measurement of dispersion used in the algorithm is the variance of the intensity distribution (also known as the Otsu method).
MOMENTS The measurement of dispersion used in the algorithm is the moments of the intensity distribution.
ISODATA The measurement of dispersion used in the algorithm is the isodata of the intensity distribution.
enumeration ENTROPY
output
output_measurement
The output measurement containing the computed threshold. AutoThresholdingMsr None
Parameter Name Description Type Supported Values Default Value
input
inputGrayImage
The input grayscale image Image Grayscale null
input
rangeMode
The way to determine the input intensity range.
MIN_MAX The histogram is computed between the minimum and the maximum of the image.
OTHER The histogram is computed between user-defined bounds [a,b].
Enumeration MIN_MAX
input
intensityInputRange
The input intensity range [a,b] inside which the threshold is searched. This parameter is ignored if the range mode is set to MIN_MAX. Vector2d Any value {0f, 255f}
input
thresholdCriterion
The criterion to compute the threshold from the histogram.
ENTROPY The measurement of dispersion used in the algorithm is the entropy of the intensity distribution.
FACTORISATION The measurement of dispersion used in the algorithm is the variance of the intensity distribution (also known as the Otsu method).
MOMENTS The measurement of dispersion used in the algorithm is the moments of the intensity distribution.
ISODATA The measurement of dispersion used in the algorithm is the isodata of the intensity distribution.
Enumeration ENTROPY
output
outputMeasurement
The output measurement containing the computed threshold. AutoThresholdingMsr null

Object Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

AutoThresholdingValue autoThresholdingValueAlgo;
autoThresholdingValueAlgo.setInputGrayImage( polystyrene );
autoThresholdingValueAlgo.setRangeMode( AutoThresholdingValue::RangeMode::MIN_MAX );
autoThresholdingValueAlgo.setIntensityInputRange( {0, 255} );
autoThresholdingValueAlgo.setThresholdCriterion( AutoThresholdingValue::ThresholdCriterion::ENTROPY );
autoThresholdingValueAlgo.execute();

std::cout << "threshold: " << autoThresholdingValueAlgo.outputMeasurement()->threshold( 0 ) ;
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

auto_thresholding_value_algo = imagedev.AutoThresholdingValue()
auto_thresholding_value_algo.input_gray_image = polystyrene
auto_thresholding_value_algo.range_mode = imagedev.AutoThresholdingValue.MIN_MAX
auto_thresholding_value_algo.intensity_input_range = [0, 255]
auto_thresholding_value_algo.threshold_criterion = imagedev.AutoThresholdingValue.ENTROPY
auto_thresholding_value_algo.execute()

print("threshold: ", str(auto_thresholding_value_algo.output_measurement.threshold(0)))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

AutoThresholdingValue autoThresholdingValueAlgo = new AutoThresholdingValue
{
    inputGrayImage = polystyrene,
    rangeMode = AutoThresholdingValue.RangeMode.MIN_MAX,
    intensityInputRange = new double[]{0, 255},
    thresholdCriterion = AutoThresholdingValue.ThresholdCriterion.ENTROPY
};
autoThresholdingValueAlgo.Execute();

Console.WriteLine( "threshold: " + autoThresholdingValueAlgo.outputMeasurement.threshold( 0 ) );

Function Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = autoThresholdingValue( polystyrene, AutoThresholdingValue::RangeMode::MIN_MAX, {0, 255}, AutoThresholdingValue::ThresholdCriterion::ENTROPY );

std::cout << "threshold: " << result->threshold( 0 ) ;
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

result = imagedev.auto_thresholding_value(polystyrene, imagedev.AutoThresholdingValue.MIN_MAX, [0, 255], imagedev.AutoThresholdingValue.ENTROPY)

print("threshold: ", str(result.threshold(0)))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

AutoThresholdingMsr result = Processing.AutoThresholdingValue( polystyrene, AutoThresholdingValue.RangeMode.MIN_MAX, new double[]{0, 255}, AutoThresholdingValue.ThresholdCriterion.ENTROPY );

Console.WriteLine(  "threshold: " + result.threshold( 0 )  );