ImageDev

Erosion2d

Performs a two-dimensional erosion using a structuring element matching with a square or a cross.

Access to parameter description

For an introduction: The erosion is performed by an iterative method in which each step erodes the result of the previous step. The kernelRadius parameter tunes the number of iterations, which sets the kernel size.
This algorithm uses a basic structuring element with either 8 neighbors, or 4 neighbors, according to the neighborhood parameter.

<b> Figure 1.</b> Structuring elements
Figure 1. Structuring elements
See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > erosion2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, Erosion2d::Neighborhood neighborhood, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
erosion_2d(input_image: idt.ImageType,
           kernel_radius: int = 3,
           neighborhood: Erosion2d.Neighborhood = Erosion2d.Neighborhood.CONNECTIVITY_8,
           output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
Erosion2d( IOLink.ImageView inputImage,
           UInt32 kernelRadius = 3,
           Erosion2d.Neighborhood neighborhood = ImageDev.Erosion2d.Neighborhood.CONNECTIVITY_8,
           IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. The image type can be integer or float. Image Binary, Label, Grayscale or Multispectral nullptr
input
kernelRadius
The number of iterations (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. UInt32 >=1 3
input
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4 The structuring element is a cross.
CONNECTIVITY_8 The structuring element is a square.
Enumeration CONNECTIVITY_8
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input image. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. The image type can be integer or float. image Binary, Label, Grayscale or Multispectral None
input
kernel_radius
The number of iterations (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. uint32 >=1 3
input
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4 The structuring element is a cross.
CONNECTIVITY_8 The structuring element is a square.
enumeration CONNECTIVITY_8
output
output_image
The output image. Its dimensions and type are forced to the same values as the input image. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. The image type can be integer or float. Image Binary, Label, Grayscale or Multispectral null
input
kernelRadius
The number of iterations (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. UInt32 >=1 3
input
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4 The structuring element is a cross.
CONNECTIVITY_8 The structuring element is a square.
Enumeration CONNECTIVITY_8
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input image. Image null

Object Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

Erosion2d erosion2dAlgo;
erosion2dAlgo.setInputImage( polystyrene );
erosion2dAlgo.setKernelRadius( 3 );
erosion2dAlgo.setNeighborhood( Erosion2d::Neighborhood::CONNECTIVITY_8 );
erosion2dAlgo.execute();

std::cout << "outputImage:" << erosion2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

erosion_2d_algo = imagedev.Erosion2d()
erosion_2d_algo.input_image = polystyrene
erosion_2d_algo.kernel_radius = 3
erosion_2d_algo.neighborhood = imagedev.Erosion2d.CONNECTIVITY_8
erosion_2d_algo.execute()

print("output_image:", str(erosion_2d_algo.output_image))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

Erosion2d erosion2dAlgo = new Erosion2d
{
    inputImage = polystyrene,
    kernelRadius = 3,
    neighborhood = Erosion2d.Neighborhood.CONNECTIVITY_8
};
erosion2dAlgo.Execute();

Console.WriteLine( "outputImage:" + erosion2dAlgo.outputImage.ToString() );

Function Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = erosion2d( polystyrene, 3, Erosion2d::Neighborhood::CONNECTIVITY_8 );

std::cout << "outputImage:" << result->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

result = imagedev.erosion_2d(polystyrene, 3, imagedev.Erosion2d.CONNECTIVITY_8)

print("output_image:", str(result))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

IOLink.ImageView result = Processing.Erosion2d( polystyrene, 3, Erosion2d.Neighborhood.CONNECTIVITY_8 );

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