ImageDev

OpeningDisk2d

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

Access to parameter description

For an introduction: This algorithm successively runs an ErosionDisk2d and a DilationDisk2d with the same kernel.
It supports two modes: a fast mode that combines erosions and dilations 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 opening systematically considers areas out of the image as a replication of the image borders at each step of the algorithm. Therefore, when applying an opening, some thin object parts cut by the image borders may be removed at the erosion step and not be restored after the dilation, while one would expect to keep them. 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 Opening2d documentation (Figure 2).

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > openingDisk2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, OpeningDisk2d::Precision precision, OpeningDisk2d::BorderPolicy borderPolicy, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
opening_disk_2d(input_image: idt.ImageType,
                kernel_radius: int = 3,
                precision: OpeningDisk2d.Precision = OpeningDisk2d.Precision.FASTER,
                border_policy: OpeningDisk2d.BorderPolicy = OpeningDisk2d.BorderPolicy.LIMITED,
                output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
OpeningDisk2d( IOLink.ImageView inputImage,
               UInt32 kernelRadius = 3,
               OpeningDisk2d.Precision precision = ImageDev.OpeningDisk2d.Precision.FASTER,
               OpeningDisk2d.BorderPolicy borderPolicy = ImageDev.OpeningDisk2d.BorderPolicy.LIMITED,
               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
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
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
border_policy
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
kernel_radius
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
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
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 null

Object Examples

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

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

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

opening_disk_2d_algo = imagedev.OpeningDisk2d()
opening_disk_2d_algo.input_image = polystyrene
opening_disk_2d_algo.kernel_radius = 3
opening_disk_2d_algo.precision = imagedev.OpeningDisk2d.FASTER
opening_disk_2d_algo.border_policy = imagedev.OpeningDisk2d.EXTENDED
opening_disk_2d_algo.execute()

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

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

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

Function Examples

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

auto result = openingDisk2d( polystyrene, 3, OpeningDisk2d::Precision::FASTER, OpeningDisk2d::BorderPolicy::EXTENDED );

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

result = imagedev.opening_disk_2d(polystyrene, 3, imagedev.OpeningDisk2d.FASTER, imagedev.OpeningDisk2d.EXTENDED)

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

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

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