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:
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. $$
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
Access to parameter description
For an introduction:
- section Image Segmentation
- section Binarization
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. $$
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 outputBinaryImage.
// Function prototype
std::shared_ptr< iolink::ImageView > thresholding( std::shared_ptr< iolink::ImageView > inputImage, iolink::Vector2d thresholdRange, std::shared_ptr< iolink::ImageView > outputBinaryImage = nullptr );
This function returns outputBinaryImage.
// Function prototype. thresholding(input_image: idt.ImageType, threshold_range: Union[Iterable[int], Iterable[float]] = [128, 255], output_binary_image: idt.ImageType = None) -> idt.ImageType
This function returns outputBinaryImage.
// Function prototype. public static IOLink.ImageView Thresholding( IOLink.ImageView inputImage, double[] thresholdRange = null, IOLink.ImageView outputBinaryImage = null );
Class Syntax
Parameters
Parameter Name | Description | Type | Supported Values | Default Value | |
---|---|---|---|---|---|
inputImage |
The input image. | Image | Binary, Label, Grayscale or Multispectral | nullptr | |
thresholdRange |
The low and high threshold levels. | Vector2d | Any value | {128.f, 255.f} | |
outputBinaryImage |
The output binary image. Its dimensions are forced to the same values as the input. | Image | nullptr |
Parameter Name | Description | Type | Supported Values | Default Value | |
---|---|---|---|---|---|
input_image |
The input image. | image | Binary, Label, Grayscale or Multispectral | None | |
threshold_range |
The low and high threshold levels. | vector2d | Any value | [128, 255] | |
output_binary_image |
The output binary image. Its dimensions are forced to the same values as the input. | image | None |
Parameter Name | Description | Type | Supported Values | Default Value | |
---|---|---|---|---|---|
inputImage |
The input image. | Image | Binary, Label, Grayscale or Multispectral | null | |
thresholdRange |
The low and high threshold levels. | Vector2d | Any value | {128f, 255f} | |
outputBinaryImage |
The output binary image. Its dimensions are forced to the same values as the input. | Image | null |
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() );