ImageDev

OpeningByReconstruction2d

Performs a two-dimensional opening by reconstruction with a structuring element matching with a square.

Access to parameter description

An opening by reconstruction consists in applying an erosion followed by a morphological reconstruction. In the binary case, opening by reconstruction can be used for removing small objects without modifying edges of the large ones. In the grayscale case, opening by reconstruction can be used for performing a Top Hat by reconstruction for detecting bright small structures without getting artifacts from the boundary concavities of the large ones.

<b> (a) </b>
(a)
<b> (b) </b>
(b)
<b> (c) </b>
(c)
Figure 1. Binary opening by reconstruction: (a) The binary input image,
(b) classic opening of size 3, (c) opening by reconstruction of size 3


See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > openingByReconstruction2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, OpeningByReconstruction2d::Neighborhood neighborhood, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
opening_by_reconstruction_2d( input_image,
                              kernel_radius = 3,
                              neighborhood = OpeningByReconstruction2d.Neighborhood.CONNECTIVITY_8,
                              output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
OpeningByReconstruction2d( IOLink.ImageView inputImage,
                           UInt32 kernelRadius = 3,
                           OpeningByReconstruction2d.Neighborhood neighborhood = ImageDev.OpeningByReconstruction2d.Neighborhood.CONNECTIVITY_8,
                           IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name OpeningByReconstruction2d

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label or Grayscale 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 for performing dilations or erosions.
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

Object Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

OpeningByReconstruction2d openingByReconstruction2dAlgo;
openingByReconstruction2dAlgo.setInputImage( polystyrene );
openingByReconstruction2dAlgo.setKernelRadius( 3 );
openingByReconstruction2dAlgo.setNeighborhood( OpeningByReconstruction2d::Neighborhood::CONNECTIVITY_8 );
openingByReconstruction2dAlgo.execute();

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

opening_by_reconstruction_2d_algo = imagedev.OpeningByReconstruction2d()
opening_by_reconstruction_2d_algo.input_image = polystyrene
opening_by_reconstruction_2d_algo.kernel_radius = 3
opening_by_reconstruction_2d_algo.neighborhood = imagedev.OpeningByReconstruction2d.CONNECTIVITY_8
opening_by_reconstruction_2d_algo.execute()

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

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

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

Function Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = openingByReconstruction2d( polystyrene, 3, OpeningByReconstruction2d::Neighborhood::CONNECTIVITY_8 );

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

result = imagedev.opening_by_reconstruction_2d( polystyrene, 3, imagedev.OpeningByReconstruction2d.CONNECTIVITY_8 )

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

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

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