TopHat
Detects the compact dark or bright areas of a grayscale image.
Access to parameter description
The Top-Hat transformation allows detecting the dark areas of a grayscale image, or the valleys of function $f$, using the closing function.
By changing the size of the closing and the bounds of the threshold, one may choose the width and the depth of the selected valleys.
Similarly, this algorithm allows detecting the white areas of a grayscale image, or the narrow peaks of function $f$, using an opening.
By changing the values of the size of the opening and the bounds of the threshold, it is possible to choose the width and the height of the selected peaks.
It would be impossible to obtain the same result with a simple threshold.
The Top-Hat segmentation extracts small elements and details from given images. It detects the dark or the bright areas, corresponding to the valleys or the narrow peaks.
There are two types of Top-Hat transforms:
Figure 1. Black Top-Hat computation
The Top-Hat algorithm is divided into two phases:
Access to parameter description
The Top-Hat transformation allows detecting the dark areas of a grayscale image, or the valleys of function $f$, using the closing function.
By changing the size of the closing and the bounds of the threshold, one may choose the width and the depth of the selected valleys.
Similarly, this algorithm allows detecting the white areas of a grayscale image, or the narrow peaks of function $f$, using an opening.
By changing the values of the size of the opening and the bounds of the threshold, it is possible to choose the width and the height of the selected peaks.
It would be impossible to obtain the same result with a simple threshold.
The Top-Hat segmentation extracts small elements and details from given images. It detects the dark or the bright areas, corresponding to the valleys or the narrow peaks.
There are two types of Top-Hat transforms:
- The Black Top-Hat: it is defined as the difference between the closing with a particular kernel and the input image. The smaller the kernel, the smaller the elements detected in the Top-Hat image. A threshold allows selecting the darker elements of the Top-Hat result (the depth of the selected valleys), as shown in Figure 1.
- The White Top-Hat: it is defined as the difference between the input image and its opening (using a particular kernel). The threshold allows selecting the brighter elements of the Top-Hat result.
Figure 1. Black Top-Hat computation
The Top-Hat algorithm is divided into two phases:
- The Top-Hat image computation, depending on the Top-Hat type and the closing/opening parameters (steps 1 and 2 on Figure 1).
- The Thresholding, to select the depth of valleys or narrow peaks (step 3 on figure 1).
Function Syntax
This function returns outputBinaryImage.
// Function prototype
std::shared_ptr< iolink::ImageView > topHat( std::shared_ptr< iolink::ImageView > inputGrayImage, int32_t kernelRadius, TopHat::ObjectLightness objectLightness, iolink::Vector2d thresholdRange, std::shared_ptr< iolink::ImageView > outputBinaryImage = NULL );
This function returns outputBinaryImage.
// Function prototype. top_hat( input_gray_image, kernel_radius = 3, object_lightness = TopHat.ObjectLightness.BRIGHT_OBJECTS, threshold_range = [128, 255], output_binary_image = None )
This function returns outputBinaryImage.
// Function prototype. public static IOLink.ImageView TopHat( IOLink.ImageView inputGrayImage, Int32 kernelRadius = 3, TopHat.ObjectLightness objectLightness = ImageDev.TopHat.ObjectLightness.BRIGHT_OBJECTS, double[] thresholdRange = null, IOLink.ImageView outputBinaryImage = null );
Class Syntax
Parameters
Parameter Name | Description | Type | Supported Values | Default Value | |||||
---|---|---|---|---|---|---|---|---|---|
inputGrayImage |
The input gray level image. | Image | Binary, Label or Grayscale | nullptr | |||||
kernelRadius |
The half size of the structuring element in pixels. A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. | Int32 | >=1 | 3 | |||||
objectLightness |
The lightness of objects to detect.
|
Enumeration | BRIGHT_OBJECTS | ||||||
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_gray_image |
The input gray level image. | image | Binary, Label or Grayscale | None | |||||
kernel_radius |
The half size of the structuring element in pixels. A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. | int32 | >=1 | 3 | |||||
object_lightness |
The lightness of objects to detect.
|
enumeration | BRIGHT_OBJECTS | ||||||
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 | |||||
---|---|---|---|---|---|---|---|---|---|
inputGrayImage |
The input gray level image. | Image | Binary, Label or Grayscale | null | |||||
kernelRadius |
The half size of the structuring element in pixels. A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. | Int32 | >=1 | 3 | |||||
objectLightness |
The lightness of objects to detect.
|
Enumeration | BRIGHT_OBJECTS | ||||||
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" ); TopHat topHatAlgo; topHatAlgo.setInputGrayImage( foam ); topHatAlgo.setKernelRadius( 3 ); topHatAlgo.setObjectLightness( TopHat::ObjectLightness::BRIGHT_OBJECTS ); topHatAlgo.setThresholdRange( {128.0, 255.0} ); topHatAlgo.execute(); std::cout << "outputBinaryImage:" << topHatAlgo.outputBinaryImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip")) top_hat_algo = imagedev.TopHat() top_hat_algo.input_gray_image = foam top_hat_algo.kernel_radius = 3 top_hat_algo.object_lightness = imagedev.TopHat.BRIGHT_OBJECTS top_hat_algo.threshold_range = [128.0, 255.0] top_hat_algo.execute() print( "output_binary_image:", str( top_hat_algo.output_binary_image ) )
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" ); TopHat topHatAlgo = new TopHat { inputGrayImage = foam, kernelRadius = 3, objectLightness = TopHat.ObjectLightness.BRIGHT_OBJECTS, thresholdRange = new double[]{128.0, 255.0} }; topHatAlgo.Execute(); Console.WriteLine( "outputBinaryImage:" + topHatAlgo.outputBinaryImage.ToString() );
Function Examples
auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" ); auto result = topHat( foam, 3, TopHat::ObjectLightness::BRIGHT_OBJECTS, {128.0, 255.0} ); std::cout << "outputBinaryImage:" << result->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip")) result = imagedev.top_hat( foam, 3, imagedev.TopHat.BRIGHT_OBJECTS, [128.0, 255.0] ) print( "output_binary_image:", str( result ) )
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" ); IOLink.ImageView result = Processing.TopHat( foam, 3, TopHat.ObjectLightness.BRIGHT_OBJECTS, new double[]{128.0, 255.0} ); Console.WriteLine( "outputBinaryImage:" + result.ToString() );