ImageDev

AdaptiveThresholding2d

Performs a binarization of a grayscale image based on the mean intensity of a sliding window centered around each pixel.

Access to parameter description

Each pixel value $I$ is compared to the mean intensity $\mu(I)$ of its local window.
The corresponding pixel in the binary output depends on a threshold value, an arithmetic mode, and a comparison criterion. For example, to select pixels lower than 90% of their local mean, set the threshold parameter to 0.9, comparisonCriterion to LESS_OR_EQUAL and thresholdMode to MULTIPLICATIVE.

See also

Function Syntax

This function returns the outputBinaryImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
adaptiveThresholding2d( std::shared_ptr< iolink::ImageView > inputImage,
                        int32_t kernelRadiusX,
                        int32_t kernelRadiusY,
                        double threshold,
                        AdaptiveThresholding2d::ComparisonCriterion comparisonCriterion,
                        AdaptiveThresholding2d::ThresholdMode thresholdMode,
                        std::shared_ptr< iolink::ImageView > outputBinaryImage = NULL );
This function returns the outputBinaryImage output parameter.
// Function prototype.
adaptive_thresholding_2d( input_image,
                          kernel_radius_x = 30,
                          kernel_radius_y = 30,
                          threshold = 1,
                          comparison_criterion = AdaptiveThresholding2d.ComparisonCriterion.GREATER_OR_EQUAL,
                          threshold_mode = AdaptiveThresholding2d.ThresholdMode.MULTIPLICATIVE,
                          output_binary_image = None )
This function returns the outputBinaryImage output parameter.
// Function prototype.
public static IOLink.ImageView
AdaptiveThresholding2d( IOLink.ImageView inputImage,
                        Int32 kernelRadiusX = 30,
                        Int32 kernelRadiusY = 30,
                        double threshold = 1,
                        AdaptiveThresholding2d.ComparisonCriterion comparisonCriterion = ImageDev.AdaptiveThresholding2d.ComparisonCriterion.GREATER_OR_EQUAL,
                        AdaptiveThresholding2d.ThresholdMode thresholdMode = ImageDev.AdaptiveThresholding2d.ThresholdMode.MULTIPLICATIVE,
                        IOLink.ImageView outputBinaryImage = null );

Class Syntax

Parameters

Class Name AdaptiveThresholding2d

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Its type can be integer or float. Image Grayscale nullptr
input
kernelRadiusX
The horizontal kernel size in pixels. Int32 >=1 30
input
kernelRadiusY
The vertical kernel size in pixels. Int32 >=1 30
input
threshold
The fraction or the additive thresholding value, according to the thresholdMode parameter value. Float64 Any value 1
input
comparisonCriterion
The comparison test to perform between image and value.
GREATER_OR_EQUAL All pixels whose value is greater than or equal to the local threshold value are set to 1, others are set to 0.
LESS_OR_EQUAL All pixels whose value is less than or equal to the local threshold value are set to 1, others are set to 0.
Enumeration GREATER_OR_EQUAL
input
thresholdMode
The local thresholding mode.
MULTIPLICATIVE The local threshold is equal to mean(I) x threshold.
ADDITIVE The local threshold is equal to mean(I) + threshold.
Enumeration MULTIPLICATIVE
output
outputBinaryImage
The output binary image. Its dimensions are forced to the same values as the input. Image nullptr

Object Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

AdaptiveThresholding2d adaptiveThresholding2dAlgo;
adaptiveThresholding2dAlgo.setInputImage( polystyrene );
adaptiveThresholding2dAlgo.setKernelRadiusX( 30 );
adaptiveThresholding2dAlgo.setKernelRadiusY( 30 );
adaptiveThresholding2dAlgo.setThreshold( 1.0 );
adaptiveThresholding2dAlgo.setComparisonCriterion( AdaptiveThresholding2d::ComparisonCriterion::GREATER_OR_EQUAL );
adaptiveThresholding2dAlgo.setThresholdMode( AdaptiveThresholding2d::ThresholdMode::MULTIPLICATIVE );
adaptiveThresholding2dAlgo.execute();

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

adaptive_thresholding_2d_algo = imagedev.AdaptiveThresholding2d()
adaptive_thresholding_2d_algo.input_image = polystyrene
adaptive_thresholding_2d_algo.kernel_radius_x = 30
adaptive_thresholding_2d_algo.kernel_radius_y = 30
adaptive_thresholding_2d_algo.threshold = 1.0
adaptive_thresholding_2d_algo.comparison_criterion = imagedev.AdaptiveThresholding2d.GREATER_OR_EQUAL
adaptive_thresholding_2d_algo.threshold_mode = imagedev.AdaptiveThresholding2d.MULTIPLICATIVE
adaptive_thresholding_2d_algo.execute()

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

AdaptiveThresholding2d adaptiveThresholding2dAlgo = new AdaptiveThresholding2d
{
    inputImage = polystyrene,
    kernelRadiusX = 30,
    kernelRadiusY = 30,
    threshold = 1.0,
    comparisonCriterion = AdaptiveThresholding2d.ComparisonCriterion.GREATER_OR_EQUAL,
    thresholdMode = AdaptiveThresholding2d.ThresholdMode.MULTIPLICATIVE
};
adaptiveThresholding2dAlgo.Execute();

Console.WriteLine( "outputBinaryImage:" + adaptiveThresholding2dAlgo.outputBinaryImage.ToString() );

Function Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = adaptiveThresholding2d( polystyrene, 30, 30, 1.0, AdaptiveThresholding2d::ComparisonCriterion::GREATER_OR_EQUAL, AdaptiveThresholding2d::ThresholdMode::MULTIPLICATIVE );

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

result = imagedev.adaptive_thresholding_2d( polystyrene, 30, 30, 1.0, imagedev.AdaptiveThresholding2d.GREATER_OR_EQUAL, imagedev.AdaptiveThresholding2d.MULTIPLICATIVE )

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

IOLink.ImageView result = Processing.AdaptiveThresholding2d( polystyrene, 30, 30, 1.0, AdaptiveThresholding2d.ComparisonCriterion.GREATER_OR_EQUAL, AdaptiveThresholding2d.ThresholdMode.MULTIPLICATIVE );

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