ImageDev

ClosingDisk2d

Performs a two-dimensional closing using a structuring element matching with a disk.

Access to parameter description

For an introduction: This algorithm successively runs a DilationDisk2d and an ErosionDisk2d with the same kernel.
It supports two modes: a fast mode that combines dilations and erosions using different neighborhoods and a precise mode (slower) that ensures a real disk structuring element. The mode can be selected with the precision parameter.

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.
This option is illustrated in the Closing2d documentation (Figure 2).

See also

Function Syntax

This function returns the outputImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
closingDisk2d( std::shared_ptr< iolink::ImageView > inputImage,
               uint32_t kernelRadius,
               ClosingDisk2d::Precision precision,
               ClosingDisk2d::BorderPolicy borderPolicy,
               std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns the outputImage output parameter.
// Function prototype.
closing_disk_2d( input_image,
                 kernel_radius = 3,
                 precision = ClosingDisk2d.Precision.FASTER,
                 border_policy = ClosingDisk2d.BorderPolicy.LIMITED,
                 output_image = None )
This function returns the outputImage output parameter.
// Function prototype.
public static IOLink.ImageView
ClosingDisk2d( IOLink.ImageView inputImage,
               UInt32 kernelRadius = 3,
               ClosingDisk2d.Precision precision = ImageDev.ClosingDisk2d.Precision.FASTER,
               ClosingDisk2d.BorderPolicy borderPolicy = ImageDev.ClosingDisk2d.BorderPolicy.LIMITED,
               IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name ClosingDisk2d

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 the 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 length of the disk radius in pixels. UInt32 >=1 3
input
precision
The precision of the computation method.
FASTER The operation is computed with a fast mode, which approximates a circular structuring element by combining erosions using 8 and 4 neighborhoods.
PRECISE The operation is computed with a precise mode (slower), which ensures a real circular structuring element.
Enumeration FASTER
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" );

ClosingDisk2d closingDisk2dAlgo;
closingDisk2dAlgo.setInputImage( polystyrene );
closingDisk2dAlgo.setKernelRadius( 3 );
closingDisk2dAlgo.setPrecision( ClosingDisk2d::Precision::FASTER );
closingDisk2dAlgo.setBorderPolicy( ClosingDisk2d::BorderPolicy::EXTENDED );
closingDisk2dAlgo.execute();

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

closing_disk_2d_algo = imagedev.ClosingDisk2d()
closing_disk_2d_algo.input_image = polystyrene
closing_disk_2d_algo.kernel_radius = 3
closing_disk_2d_algo.precision = imagedev.ClosingDisk2d.FASTER
closing_disk_2d_algo.border_policy = imagedev.ClosingDisk2d.EXTENDED
closing_disk_2d_algo.execute()

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

ClosingDisk2d closingDisk2dAlgo = new ClosingDisk2d
{
    inputImage = polystyrene,
    kernelRadius = 3,
    precision = ClosingDisk2d.Precision.FASTER,
    borderPolicy = ClosingDisk2d.BorderPolicy.EXTENDED
};
closingDisk2dAlgo.Execute();

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

Function Examples

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

auto result = closingDisk2d( polystyrene, 3, ClosingDisk2d::Precision::FASTER, ClosingDisk2d::BorderPolicy::EXTENDED );

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

result = imagedev.closing_disk_2d( polystyrene, 3, imagedev.ClosingDisk2d.FASTER, imagedev.ClosingDisk2d.EXTENDED )

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

IOLink.ImageView result = Processing.ClosingDisk2d( polystyrene, 3, ClosingDisk2d.Precision.FASTER, ClosingDisk2d.BorderPolicy.EXTENDED );

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