This algorithm successively runs an Erosion2d and a Dilation2d 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.
Figure 1. Structuring elements
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. Therefore, this mode can be
slower and more memory consuming, especially when the structuring element size is high.
(a)
(b)
(c)
Figure 2. Opening and border policy: (a) The binary input image,
(b) opening of size 5 with limited border policy, (c) same opening in extended mode
// Command constructor.Opening2d();/// Gets the inputImage parameter./// The input image. The image type can be integer or float.
std::shared_ptr< iolink::ImageView> inputImage()const;/// Sets the inputImage parameter./// The input image. The image type can be integer or float.void setInputImage( std::shared_ptr< iolink::ImageView> inputImage );/// Gets the kernelRadius parameter./// 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_t kernelRadius()const;/// Sets the kernelRadius parameter./// 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.void setKernelRadius(constuint32_t& kernelRadius );/// Gets the neighborhood parameter./// The 2D neighborhood configuration.Opening2d::Neighborhood neighborhood()const;/// Sets the neighborhood parameter./// The 2D neighborhood configuration.void setNeighborhood(constOpening2d::Neighborhood& neighborhood );/// Gets the borderPolicy parameter./// The border policy to apply.Opening2d::BorderPolicy borderPolicy()const;/// Sets the borderPolicy parameter./// The border policy to apply.void setBorderPolicy(constOpening2d::BorderPolicy& borderPolicy );/// Gets the outputImage parameter./// The output image. Its dimensions and type are forced to the same values as the input image.
std::shared_ptr< iolink::ImageView> outputImage()const;/// Sets the outputImage parameter./// The output image. Its dimensions and type are forced to the same values as the input image.void setOutputImage( std::shared_ptr< iolink::ImageView> outputImage );// Method to launch the command.void execute();
# Property of the inputImage parameter.Opening2d.input_image
# Property of the kernelRadius parameter.Opening2d.kernel_radius
# Property of the neighborhood parameter.Opening2d.neighborhood
# Property of the borderPolicy parameter.Opening2d.border_policy
# Property of the outputImage parameter.Opening2d.output_image
// Method to launch the command.
execute()
// Command constructor.Opening2d()// Property of the inputImage parameter.Opening2d.inputImage
// Property of the kernelRadius parameter.Opening2d.kernelRadius
// Property of the neighborhood parameter.Opening2d.neighborhood
// Property of the borderPolicy parameter.Opening2d.borderPolicy
// Property of the outputImage parameter.Opening2d.outputImage
// Method to launch the command.Execute()
Parameters
Parameter Name
Description
Type
Supported Values
Default Value
inputImage
The input image. The image type can be integer or float.
Image
Binary, Label, Grayscale or Multispectral
nullptr
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
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
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4
The structuring element is a cross.
CONNECTIVITY_8
The structuring element is a square.
Enumeration
CONNECTIVITY_8
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_image
The input image. The image type can be integer or float.
image
Binary, Label, Grayscale or Multispectral
None
border_policy
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
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
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_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
inputImage
The input image. The image type can be integer or float.
Image
Binary, Label, Grayscale or Multispectral
null
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
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
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4
The structuring element is a cross.
CONNECTIVITY_8
The structuring element is a square.
Enumeration
CONNECTIVITY_8
outputImage
The output image. Its dimensions and type are forced to the same values as the input image.