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 the outputBinaryImage and outputMeasurement output parameters.
// Output structure.
struct AutoThresholdingDarkOutput
{
    std::shared_ptr< iolink::ImageView > outputBinaryImage;
    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 = NULL,
                      AutoThresholdingMsr::Ptr outputMeasurement = NULL );
This function returns a tuple containing the output_binary_image and output_measurement output parameters.
// Function prototype.
auto_thresholding_dark( input_gray_image,
                        range_mode = AutoThresholdingDark.RangeMode.MIN_MAX,
                        intensity_input_range = [0, 255],
                        threshold_criterion = AutoThresholdingDark.ThresholdCriterion.ENTROPY,
                        output_binary_image = None,
                        output_measurement = None )
This function returns a AutoThresholdingDarkOutput structure containing the outputBinaryImage and outputMeasurement output parameters.
/// Output structure of the AutoThresholdingDark function.
public struct AutoThresholdingDarkOutput
{
    public IOLink.ImageView outputBinaryImage;
    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

Class Name AutoThresholdingDark

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

Object Examples

std::shared_ptr< iolink::ImageView > 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( 
print("threshold: ", 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

std::shared_ptr< iolink::ImageView > 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: ", 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 )  );