ImageDev

Closing2d

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

Access to parameter description

For an introduction: This algorithm successively runs a Dilation2d and an Erosion2d with the same kernel.
The kernelRadius parameter tunes the number of iterations of each operation, 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

With a classic implementation, morphological closing systematically considers areas out of the image as a replication of the image borders at each step of the algorithm. Therefore, when applying a closing, some objects close to the image borders may be connected to the border at the dilation step and not be retro propagated after the dilation, while one would expect to keep them disconnected from the border. The borderPolicy parameter manages this case. The default mode, LIMITED, corresponds to the classic behavior. The EXTENDED mode properly manages image borders by extending them by a size equal to the structuring element's. This mode can be slower and more memory consuming, especially when the structuring element size is high.

<b> (a) </b>
(a)
<b> (b) </b>
(b)
<b> (c) </b>
(c)
Figure 2. Closing and border policy: (a) The binary input image,
(b) closing of size 10 with limited border policy, (c) same closing in extended mode


See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > closing2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, Closing2d::Neighborhood neighborhood, Closing2d::BorderPolicy borderPolicy, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
closing_2d( input_image,
            kernel_radius = 3,
            neighborhood = Closing2d.Neighborhood.CONNECTIVITY_8,
            border_policy = Closing2d.BorderPolicy.LIMITED,
            output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
Closing2d( IOLink.ImageView inputImage,
           UInt32 kernelRadius = 3,
           Closing2d.Neighborhood neighborhood = ImageDev.Closing2d.Neighborhood.CONNECTIVITY_8,
           Closing2d.BorderPolicy borderPolicy = ImageDev.Closing2d.BorderPolicy.LIMITED,
           IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name Closing2d

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
borderPolicy
The border policy to apply.
LIMITED The limited mode is faster to compute, but can produce unexpected results for particles close to the image border.
EXTENDED The Extended mode is slower to compute, but produces the expected results for particles close to the image border.
Enumeration LIMITED
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

Object Examples

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

Closing2d closing2dAlgo;
closing2dAlgo.setInputImage( polystyrene );
closing2dAlgo.setKernelRadius( 3 );
closing2dAlgo.setNeighborhood( Closing2d::Neighborhood::CONNECTIVITY_8 );
closing2dAlgo.setBorderPolicy( Closing2d::BorderPolicy::EXTENDED );
closing2dAlgo.execute();

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

closing_2d_algo = imagedev.Closing2d()
closing_2d_algo.input_image = polystyrene
closing_2d_algo.kernel_radius = 3
closing_2d_algo.neighborhood = imagedev.Closing2d.CONNECTIVITY_8
closing_2d_algo.border_policy = imagedev.Closing2d.EXTENDED
closing_2d_algo.execute()

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

Closing2d closing2dAlgo = new Closing2d
{
    inputImage = polystyrene,
    kernelRadius = 3,
    neighborhood = Closing2d.Neighborhood.CONNECTIVITY_8,
    borderPolicy = Closing2d.BorderPolicy.EXTENDED
};
closing2dAlgo.Execute();

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

Function Examples

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

auto result = closing2d( polystyrene, 3, Closing2d::Neighborhood::CONNECTIVITY_8, Closing2d::BorderPolicy::EXTENDED );

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

result = imagedev.closing_2d( polystyrene, 3, imagedev.Closing2d.CONNECTIVITY_8, imagedev.Closing2d.EXTENDED )

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

IOLink.ImageView result = Processing.Closing2d( polystyrene, 3, Closing2d.Neighborhood.CONNECTIVITY_8, Closing2d.BorderPolicy.EXTENDED );

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