ImageDev

MorphologicalGradient2d

Approximates an image gradient by using morphological operations.

Access to parameter description

For an introduction: This algorithm emphasizes the edges of the objects using morphological operations.
Three modes are available to enhance edges inside particles (Internal), outside particles (External) or on the particle borders (Centered).

<b> (a) </b>
(a)
<b> (b) </b>
(b)
<b> (c) </b>
(c)
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: Where $E_B$ (resp. $D_B$) is a morphological erosion (resp. dilation) by a structuring element B.

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: See also

Function Syntax

This function returns the outputImage output parameter.
// 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 = NULL );
This function returns the outputImage output parameter.
// Function prototype.
morphological_gradient_2d( input_image,
                           kernel_radius = 3,
                           gradient_mode = MorphologicalGradient2d.GradientMode.INTERNAL,
                           precision = MorphologicalGradient2d.Precision.FASTER,
                           output_image = None )
This function returns the outputImage output parameter.
// 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

Class Name MorphologicalGradient2d

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
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
input
precision
The precision for computation for morphological operations.
FASTER The mophological operations are computed with a fast mode .
PRECISE The mophological operations are computed with a precise mode.
Enumeration FASTER
input
gradientMode
The computation mode of morphological gradient.
INTERNAL The engine emphasizes the internal edges.
EXTERNAL The engine emphasizes the external edges.
CENTERED The engine emphasizes the edges on objects borders.
Enumeration INTERNAL
output
outputImage
The output image. Image nullptr

Object Examples

std::shared_ptr< iolink::ImageView > 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

std::shared_ptr< iolink::ImageView > 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() );