MorphologicalGradient2d
Approximates an image gradient by using morphological operations.
Access to parameter description
For an introduction:
Three modes are available to enhance edges inside particles (Internal), outside particles (External) or on the particle borders (Centered).
Figure 1. The Morphological Gradient effects with a label image in overlay:
(a) input gray level image, (b) internal morphological gradient, (c) external morphological gradient
This algorithm uses ErosionDisk2d or DilationDisk2d, and combines them as follows:
The morphological gradient can be considered as a non-linear high-pass filter. The bright edges are enhanced with a thickness proportional to the size of the structuring element. It is an approximation of the gradient modulus.
Two additional parameters are also provided:
Access to parameter description
For an introduction:
- section Edge Detection
- section Gradient
- section Morphology
Three modes are available to enhance edges inside particles (Internal), outside particles (External) or on the particle borders (Centered).
(a) |
(b) |
(c) |
(a) input gray level image, (b) internal morphological gradient, (c) external morphological gradient
This algorithm uses ErosionDisk2d or DilationDisk2d, and combines them as follows:
- Internal: $ O = I-E_B(I)$
- External: $ O = D_B(I)-I$
- Centered $ O = D_B(I)-E_B(I)$
The morphological gradient can be considered as a non-linear high-pass filter. The bright edges are enhanced with a thickness proportional to the size of the structuring element. It is an approximation of the gradient modulus.
Two additional parameters are also provided:
- The computation mode for morphological erosion and dilation: Fast or Precise.
- The size of structuring element for morphological operations.
Function Syntax
This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > morphologicalGradient2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, MorphologicalGradient2d::GradientMode gradientMode, MorphologicalGradient2d::Precision precision, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype. morphological_gradient_2d(input_image: idt.ImageType, kernel_radius: int = 3, gradient_mode: MorphologicalGradient2d.GradientMode = MorphologicalGradient2d.GradientMode.INTERNAL, precision: MorphologicalGradient2d.Precision = MorphologicalGradient2d.Precision.FASTER, output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype. public static IOLink.ImageView MorphologicalGradient2d( IOLink.ImageView inputImage, UInt32 kernelRadius = 3, MorphologicalGradient2d.GradientMode gradientMode = ImageDev.MorphologicalGradient2d.GradientMode.INTERNAL, MorphologicalGradient2d.Precision precision = ImageDev.MorphologicalGradient2d.Precision.FASTER, IOLink.ImageView outputImage = null );
Class Syntax
Parameters
Parameter Name | Description | Type | Supported Values | Default Value | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
inputImage |
The input image. | Image | Binary, Label, Grayscale or Multispectral | nullptr | |||||||
kernelRadius |
The radius in pixels of the disk structuring element used for morphological erosion and dilation. In centered mode, it corresponds to the thickness of the extracted edges and to their half thickness in other modes. | UInt32 | >=1 | 3 | |||||||
precision |
The precision for computation for morphological operations.
|
Enumeration | FASTER | ||||||||
gradientMode |
The computation mode of morphological gradient.
|
Enumeration | INTERNAL | ||||||||
outputImage |
The output image. | Image | nullptr |
Parameter Name | Description | Type | Supported Values | Default Value | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
input_image |
The input image. | image | Binary, Label, Grayscale or Multispectral | None | |||||||
kernel_radius |
The radius in pixels of the disk structuring element used for morphological erosion and dilation. In centered mode, it corresponds to the thickness of the extracted edges and to their half thickness in other modes. | uint32 | >=1 | 3 | |||||||
precision |
The precision for computation for morphological operations.
|
enumeration | FASTER | ||||||||
gradient_mode |
The computation mode of morphological gradient.
|
enumeration | INTERNAL | ||||||||
output_image |
The output image. | image | None |
Parameter Name | Description | Type | Supported Values | Default Value | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
inputImage |
The input image. | Image | Binary, Label, Grayscale or Multispectral | null | |||||||
kernelRadius |
The radius in pixels of the disk structuring element used for morphological erosion and dilation. In centered mode, it corresponds to the thickness of the extracted edges and to their half thickness in other modes. | UInt32 | >=1 | 3 | |||||||
precision |
The precision for computation for morphological operations.
|
Enumeration | FASTER | ||||||||
gradientMode |
The computation mode of morphological gradient.
|
Enumeration | INTERNAL | ||||||||
outputImage |
The output image. | Image | null |
Object Examples
auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); MorphologicalGradient2d morphologicalGradient2dAlgo; morphologicalGradient2dAlgo.setInputImage( polystyrene ); morphologicalGradient2dAlgo.setKernelRadius( 3 ); morphologicalGradient2dAlgo.setGradientMode( MorphologicalGradient2d::GradientMode::INTERNAL ); morphologicalGradient2dAlgo.setPrecision( MorphologicalGradient2d::Precision::FASTER ); morphologicalGradient2dAlgo.execute(); std::cout << "outputImage:" << morphologicalGradient2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) morphological_gradient_2d_algo = imagedev.MorphologicalGradient2d() morphological_gradient_2d_algo.input_image = polystyrene morphological_gradient_2d_algo.kernel_radius = 3 morphological_gradient_2d_algo.gradient_mode = imagedev.MorphologicalGradient2d.INTERNAL morphological_gradient_2d_algo.precision = imagedev.MorphologicalGradient2d.FASTER morphological_gradient_2d_algo.execute() print("output_image:", str(morphological_gradient_2d_algo.output_image))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); MorphologicalGradient2d morphologicalGradient2dAlgo = new MorphologicalGradient2d { inputImage = polystyrene, kernelRadius = 3, gradientMode = MorphologicalGradient2d.GradientMode.INTERNAL, precision = MorphologicalGradient2d.Precision.FASTER }; morphologicalGradient2dAlgo.Execute(); Console.WriteLine( "outputImage:" + morphologicalGradient2dAlgo.outputImage.ToString() );
Function Examples
auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); auto result = morphologicalGradient2d( polystyrene, 3, MorphologicalGradient2d::GradientMode::INTERNAL, MorphologicalGradient2d::Precision::FASTER ); std::cout << "outputImage:" << result->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) result = imagedev.morphological_gradient_2d(polystyrene, 3, imagedev.MorphologicalGradient2d.INTERNAL, imagedev.MorphologicalGradient2d.FASTER) print("output_image:", str(result))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); IOLink.ImageView result = Processing.MorphologicalGradient2d( polystyrene, 3, MorphologicalGradient2d.GradientMode.INTERNAL, MorphologicalGradient2d.Precision.FASTER ); Console.WriteLine( "outputImage:" + result.ToString() );