ImageDev

ColorThresholding

Transforms a color image into a binary image.

Access to parameter description

For an introduction: This algorithm thresholds a color image from three thresholding ranges. The threshold parameters allow selecting the range for the RGB or HSL levels, depending on the type of image. The retained pixel are the intersection of the three selected ranges in each channel. In other words, this algorithm acts as thresholding each channel separately and applying a logical AND operator between the three results.

See also
See related example

Function Syntax

This function returns the outputBinaryImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
colorThresholding( std::shared_ptr< iolink::ImageView > inputColorImage,
                   iolink::Vector2d thresholdRangeRed,
                   iolink::Vector2d thresholdRangeGreen,
                   iolink::Vector2d thresholdRangeBlue,
                   std::shared_ptr< iolink::ImageView > outputBinaryImage = NULL );
This function returns the outputBinaryImage output parameter.
// Function prototype.
color_thresholding( input_color_image,
                    threshold_range_red = [128, 255],
                    threshold_range_green = [128, 255],
                    threshold_range_blue = [128, 255],
                    output_binary_image = None )
This function returns the outputBinaryImage output parameter.
// Function prototype.
public static IOLink.ImageView
ColorThresholding( IOLink.ImageView inputColorImage,
                   double[] thresholdRangeRed = null,
                   double[] thresholdRangeGreen = null,
                   double[] thresholdRangeBlue = null,
                   IOLink.ImageView outputBinaryImage = null );

Class Syntax

Parameters

Class Name ColorThresholding

Parameter Name Description Type Supported Values Default Value
input
inputColorImage
The input color image. Image Multispectral nullptr
input
thresholdRangeRed
The low and high thresholds for the first channel (red for an RGB image). Vector2d Any value {128.f, 255.f}
input
thresholdRangeGreen
The low and high thresholds for the second channel (green for an RGB image). Vector2d Any value {128.f, 255.f}
input
thresholdRangeBlue
The low and high thresholds for the third channel (blue for an RGB image). 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

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

ColorThresholding colorThresholdingAlgo;
colorThresholdingAlgo.setInputColorImage( ateneub );
colorThresholdingAlgo.setThresholdRangeRed( {128.0, 255.0} );
colorThresholdingAlgo.setThresholdRangeGreen( {128.0, 255.0} );
colorThresholdingAlgo.setThresholdRangeBlue( {128.0, 255.0} );
colorThresholdingAlgo.execute();

std::cout << "outputBinaryImage:" << colorThresholdingAlgo.outputBinaryImage()->toString();
ateneub = ioformat.read_image(imagedev_data.get_image_path("ateneub.jpg"))

color_thresholding_algo = imagedev.ColorThresholding()
color_thresholding_algo.input_color_image = ateneub
color_thresholding_algo.threshold_range_red = [128.0, 255.0]
color_thresholding_algo.threshold_range_green = [128.0, 255.0]
color_thresholding_algo.threshold_range_blue = [128.0, 255.0]
color_thresholding_algo.execute()

print( "output_binary_image:", str( color_thresholding_algo.output_binary_image ) );
ImageView ateneub = ViewIO.ReadImage( @"Data/images/ateneub.jpg" );

ColorThresholding colorThresholdingAlgo = new ColorThresholding
{
    inputColorImage = ateneub,
    thresholdRangeRed = new double[]{128.0, 255.0},
    thresholdRangeGreen = new double[]{128.0, 255.0},
    thresholdRangeBlue = new double[]{128.0, 255.0}
};
colorThresholdingAlgo.Execute();

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

Function Examples

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

auto result = colorThresholding( ateneub, {128.0, 255.0}, {128.0, 255.0}, {128.0, 255.0} );

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

result = imagedev.color_thresholding( ateneub, [128.0, 255.0], [128.0, 255.0], [128.0, 255.0] )

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

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

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