Opening2d
Performs a two-dimensional opening using a structuring element matching with a square or a cross.
Access to parameter description
For an introduction:
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.
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
See also
Access to parameter description
For an introduction:
- section Mathematical Morphology
- section Introduction To Opening
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) |
(b) opening of size 5 with limited border policy, (c) same opening in extended mode
See also
Function Syntax
This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > opening2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, Opening2d::Neighborhood neighborhood, Opening2d::BorderPolicy borderPolicy, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype. opening_2d( input_image, kernel_radius = 3, neighborhood = Opening2d.Neighborhood.CONNECTIVITY_8, border_policy = Opening2d.BorderPolicy.LIMITED, output_image = None )
This function returns outputImage.
// Function prototype. public static IOLink.ImageView Opening2d( IOLink.ImageView inputImage, UInt32 kernelRadius = 3, Opening2d.Neighborhood neighborhood = ImageDev.Opening2d.Neighborhood.CONNECTIVITY_8, Opening2d.BorderPolicy borderPolicy = ImageDev.Opening2d.BorderPolicy.LIMITED, IOLink.ImageView outputImage = null );
Class Syntax
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
Enumeration | CONNECTIVITY_8 | ||||||
outputImage |
The output image. Its dimensions and type are forced to the same values as the input image. | Image | null |
Object Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); Opening2d opening2dAlgo; opening2dAlgo.setInputImage( polystyrene ); opening2dAlgo.setKernelRadius( 3 ); opening2dAlgo.setNeighborhood( Opening2d::Neighborhood::CONNECTIVITY_8 ); opening2dAlgo.setBorderPolicy( Opening2d::BorderPolicy::EXTENDED ); opening2dAlgo.execute(); std::cout << "outputImage:" << opening2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) opening_2d_algo = imagedev.Opening2d() opening_2d_algo.input_image = polystyrene opening_2d_algo.kernel_radius = 3 opening_2d_algo.neighborhood = imagedev.Opening2d.CONNECTIVITY_8 opening_2d_algo.border_policy = imagedev.Opening2d.EXTENDED opening_2d_algo.execute() print( "output_image:", str( opening_2d_algo.output_image ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); Opening2d opening2dAlgo = new Opening2d { inputImage = polystyrene, kernelRadius = 3, neighborhood = Opening2d.Neighborhood.CONNECTIVITY_8, borderPolicy = Opening2d.BorderPolicy.EXTENDED }; opening2dAlgo.Execute(); Console.WriteLine( "outputImage:" + opening2dAlgo.outputImage.ToString() );
Function Examples
std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" ); auto result = opening2d( polystyrene, 3, Opening2d::Neighborhood::CONNECTIVITY_8, Opening2d::BorderPolicy::EXTENDED ); std::cout << "outputImage:" << result->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif")) result = imagedev.opening_2d( polystyrene, 3, imagedev.Opening2d.CONNECTIVITY_8, imagedev.Opening2d.EXTENDED ) print( "output_image:", str( result ) )
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" ); IOLink.ImageView result = Processing.Opening2d( polystyrene, 3, Opening2d.Neighborhood.CONNECTIVITY_8, Opening2d.BorderPolicy.EXTENDED ); Console.WriteLine( "outputImage:" + result.ToString() );