ImageDev

ClosingLine2d

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

Access to parameter description

For an introduction: This algorithm successively runs a DilationLine2d and an ErosionLine2d with the same kernel in the opposite direction. A linear opening controls the direction of the opening, therefore making it possible to fill holes and bays thinner than the structuring element in its direction.
The closing is performed by using a linear structuring element. The direction of 0 degrees is horizontal and to the left, and the angles are calculated counter-clockwise.

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 outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > closingLine2d( std::shared_ptr< iolink::ImageView > inputImage, double orientationAngle, uint32_t kernelRadius, ClosingLine2d::BorderPolicy borderPolicy, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
closing_line_2d( input_image,
                 orientation_angle = 10,
                 kernel_radius = 3,
                 border_policy = ClosingLine2d.BorderPolicy.LIMITED,
                 output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
ClosingLine2d( IOLink.ImageView inputImage,
               double orientationAngle = 10,
               UInt32 kernelRadius = 3,
               ClosingLine2d.BorderPolicy borderPolicy = ImageDev.ClosingLine2d.BorderPolicy.LIMITED,
               IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name ClosingLine2d

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
orientationAngle
The angle of orientation in degrees. Float64 Any value 10
input
kernelRadius
The length of the linear structuring element in pixels. UInt32 >=1 3
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" );

ClosingLine2d closingLine2dAlgo;
closingLine2dAlgo.setInputImage( polystyrene );
closingLine2dAlgo.setOrientationAngle( 10 );
closingLine2dAlgo.setKernelRadius( 3 );
closingLine2dAlgo.setBorderPolicy( ClosingLine2d::BorderPolicy::EXTENDED );
closingLine2dAlgo.execute();

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

closing_line_2d_algo = imagedev.ClosingLine2d()
closing_line_2d_algo.input_image = polystyrene
closing_line_2d_algo.orientation_angle = 10
closing_line_2d_algo.kernel_radius = 3
closing_line_2d_algo.border_policy = imagedev.ClosingLine2d.EXTENDED
closing_line_2d_algo.execute()

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

ClosingLine2d closingLine2dAlgo = new ClosingLine2d
{
    inputImage = polystyrene,
    orientationAngle = 10,
    kernelRadius = 3,
    borderPolicy = ClosingLine2d.BorderPolicy.EXTENDED
};
closingLine2dAlgo.Execute();

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

Function Examples

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

auto result = closingLine2d( polystyrene, 10, 3, ClosingLine2d::BorderPolicy::EXTENDED );

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

result = imagedev.closing_line_2d( polystyrene, 10, 3, imagedev.ClosingLine2d.EXTENDED )

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

IOLink.ImageView result = Processing.ClosingLine2d( polystyrene, 10, 3, ClosingLine2d.BorderPolicy.EXTENDED );

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