ImageDev

AutoThresholdingDark

Computes and applies an automatic threshold on a gray level image to detect dark particles on a bright background.

Access to parameter description

For an introduction: This algorithm computes an automatic threshold on a grayscale image; that is, it separates the input image in two classes of pixels from an input range $[I_1, I_2]$. 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 a AutoThresholdingDarkOutput structure containing outputBinaryImage and outputMeasurement.
// Output structure of the autoThresholdingDark function.
struct AutoThresholdingDarkOutput
{
    /// The output binary image. Its dimensions are forced to the same values as the input.
    std::shared_ptr< iolink::ImageView > outputBinaryImage;
    /// The computed threshold value.
    AutoThresholdingMsr::Ptr outputMeasurement;
};

// Function prototype
AutoThresholdingDarkOutput autoThresholdingDark( std::shared_ptr< iolink::ImageView > inputGrayImage, AutoThresholdingDark::RangeMode rangeMode, iolink::Vector2d intensityInputRange, AutoThresholdingDark::ThresholdCriterion thresholdCriterion, std::shared_ptr< iolink::ImageView > outputBinaryImage = nullptr, AutoThresholdingMsr::Ptr outputMeasurement = nullptr );
This function returns a tuple containing output_binary_image and output_measurement.
// Function prototype.
auto_thresholding_dark(input_gray_image: idt.ImageType,
                       range_mode: AutoThresholdingDark.RangeMode = AutoThresholdingDark.RangeMode.MIN_MAX,
                       intensity_input_range: Union[Iterable[int], Iterable[float]] = [0, 255],
                       threshold_criterion: AutoThresholdingDark.ThresholdCriterion = AutoThresholdingDark.ThresholdCriterion.ENTROPY,
                       output_binary_image: idt.ImageType = None,
                       output_measurement: Union[Any, None] = None) -> Tuple[idt.ImageType, AutoThresholdingMsr]
This function returns a AutoThresholdingDarkOutput structure containing outputBinaryImage and outputMeasurement.
/// Output structure of the AutoThresholdingDark function.
public struct AutoThresholdingDarkOutput
{
    /// 
    /// The output binary image. Its dimensions are forced to the same values as the input.
    /// 
    public IOLink.ImageView outputBinaryImage;
    /// The computed threshold value.
    public AutoThresholdingMsr outputMeasurement;
};

// Function prototype.
public static AutoThresholdingDarkOutput
AutoThresholdingDark( IOLink.ImageView inputGrayImage,
                      AutoThresholdingDark.RangeMode rangeMode = ImageDev.AutoThresholdingDark.RangeMode.MIN_MAX,
                      double[] intensityInputRange = null,
                      AutoThresholdingDark.ThresholdCriterion thresholdCriterion = ImageDev.AutoThresholdingDark.ThresholdCriterion.ENTROPY,
                      IOLink.ImageView outputBinaryImage = null,
                      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 measure of dispersion used in the algorithm is the entropy of the intensity distribution.
FACTORISATION The measure of dispersion used in the algorithm is the variance of the intensity distribution (also known as Otsu method).
MOMENTS The measure of dispersion used in the algorithm is the moments of the intensity distribution.
ISODATA The measure of dispersion used in the algorithm is the isodata of the intensity distribution.
Enumeration ENTROPY
output
outputBinaryImage
The output binary image. Its dimensions are forced to the same values as the input. Image nullptr
output
outputMeasurement
The computed threshold value. 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 measure of dispersion used in the algorithm is the entropy of the intensity distribution.
FACTORISATION The measure of dispersion used in the algorithm is the variance of the intensity distribution (also known as Otsu method).
MOMENTS The measure of dispersion used in the algorithm is the moments of the intensity distribution.
ISODATA The measure of dispersion used in the algorithm is the isodata of the intensity distribution.
enumeration ENTROPY
output
output_binary_image
The output binary image. Its dimensions are forced to the same values as the input. image None
output
output_measurement
The computed threshold value. 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 measure of dispersion used in the algorithm is the entropy of the intensity distribution.
FACTORISATION The measure of dispersion used in the algorithm is the variance of the intensity distribution (also known as Otsu method).
MOMENTS The measure of dispersion used in the algorithm is the moments of the intensity distribution.
ISODATA The measure of dispersion used in the algorithm is the isodata of the intensity distribution.
Enumeration ENTROPY
output
outputBinaryImage
The output binary image. Its dimensions are forced to the same values as the input. Image null
output
outputMeasurement
The computed threshold value. AutoThresholdingMsr null

Object Examples

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

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

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

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

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

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

Console.WriteLine( "outputBinaryImage:" + autoThresholdingDarkAlgo.outputBinaryImage.ToString() );
Console.WriteLine( "threshold: " + autoThresholdingDarkAlgo.outputMeasurement.threshold( 0 ) );

Function Examples

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

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

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

result_output_binary_image, result_output_measurement = imagedev.auto_thresholding_dark(polystyrene, imagedev.AutoThresholdingDark.MIN_MAX, [0, 255], imagedev.AutoThresholdingDark.ENTROPY)

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

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

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