ImageDev

Thresholding

Transforms a grayscale image into a binary image where all pixels with an initial gray level value lying between two user-defined bounds are set to 1 and all others are set to 0.

Access to parameter description

For an introduction: This algorithm produces a binary image representing, in its foreground, data between two gray levels $\lambda_1$ and $\lambda_2$.
Threshold with 2 bounds is the default behavior, but a threshold with a single bound may be achieved by setting $\lambda_1$ or $\lambda_2$ to the minimum or maximum value of the input data range (for example, 0 or 255, respectively for 8-bit unsigned data).

The definition is: $$ O(n,m)=\left\{\begin{array}{ll} 1 & \mbox{if } \lambda_1 \leq I(n,m) \leq \lambda_2 \\ 0 & \mbox{if I(n,m) <} \lambda_1 \mbox{ or I(n,m)>} \lambda_2 \end{array}\right. $$
<b> Figure 1.</b> Thresholding a grayscale image
Figure 1. Thresholding a grayscale image

Note: This algorithm is dedicated to be applied on grayscale images. However, for convenience, it does not return an exception when applied on a color image. It simply processes the last color channel; for instance, the blue channel in the case of an RGB image.

See also
See related example

Function Syntax

This function returns the outputBinaryImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
thresholding( std::shared_ptr< iolink::ImageView > inputImage,
              iolink::Vector2d thresholdRange,
              std::shared_ptr< iolink::ImageView > outputBinaryImage = NULL );
This function returns the outputBinaryImage output parameter.
// Function prototype.
thresholding( input_image, threshold_range = [128, 255], output_binary_image = None )
This function returns the outputBinaryImage output parameter.
// Function prototype.
public static IOLink.ImageView
Thresholding( IOLink.ImageView inputImage,
              double[] thresholdRange = null,
              IOLink.ImageView outputBinaryImage = null );

Class Syntax

Parameters

Class Name Thresholding

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
thresholdRange
The low and high threshold levels. Vector2d Any value {128.f, 255.f}
output
outputBinaryImage
The output binary image. Its dimensions are forced to the same values as the input. Image nullptr

Object Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

Thresholding thresholdingAlgo;
thresholdingAlgo.setInputImage( foam );
thresholdingAlgo.setThresholdRange( {128.0, 255.0} );
thresholdingAlgo.execute();

std::cout << "outputBinaryImage:" << thresholdingAlgo.outputBinaryImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

thresholding_algo = imagedev.Thresholding()
thresholding_algo.input_image = foam
thresholding_algo.threshold_range = [128.0, 255.0]
thresholding_algo.execute()

print( "output_binary_image:", str( thresholding_algo.output_binary_image ) )
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

Thresholding thresholdingAlgo = new Thresholding
{
    inputImage = foam,
    thresholdRange = new double[]{128.0, 255.0}
};
thresholdingAlgo.Execute();

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

Function Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

auto result = thresholding( foam, {128.0, 255.0} );

std::cout << "outputBinaryImage:" << result->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

result = imagedev.thresholding( foam, [128.0, 255.0] )

print( "output_binary_image:", str( result ) )
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

IOLink.ImageView result = Processing.Thresholding( foam, new double[]{128.0, 255.0} );

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