ImageDev

FillHoles2d

Fills the holes inside particles of a two-dimensional binary image.

Access to parameter description

For an introduction: This algorithm fills the holes inside particles, irrespective of their size.
Holes inside objects are filled using a numerical reconstruction applied on the complement of the input image, from markers made of pixels of the image frame.

<b> Figure 1.</b> Illustration of the hole filling algorithm
Figure 1. Illustration of the hole filling algorithm

Note: Since the reconstruction is applied on the input image complement, selecting a 4-neighbor connectivity fills holes connected to the background with a 8-neighbor connectivity.

See also
See related example

Function Syntax

This function returns the outputObjectImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
fillHoles2d( std::shared_ptr< iolink::ImageView > inputObjectImage,
             FillHoles2d::Neighborhood neighborhood,
             std::shared_ptr< iolink::ImageView > outputObjectImage = NULL );
This function returns the outputObjectImage output parameter.
// Function prototype.
fill_holes_2d( input_object_image, neighborhood = FillHoles2d.Neighborhood.CONNECTIVITY_8, output_object_image = None )
This function returns the outputObjectImage output parameter.
// Function prototype.
public static IOLink.ImageView
FillHoles2d( IOLink.ImageView inputObjectImage,
             FillHoles2d.Neighborhood neighborhood = ImageDev.FillHoles2d.Neighborhood.CONNECTIVITY_8,
             IOLink.ImageView outputObjectImage = null );

Class Syntax

Parameters

Class Name FillHoles2d

Parameter Name Description Type Supported Values Default Value
input
inputObjectImage
The input binary or label image. Image Binary or Label nullptr
input
neighborhood
The 2D neighborhood configuration for performing numerical reconstruction.
CONNECTIVITY_8 Morphological reconstruction is performed with a 8-neighbor connectivity.
CONNECTIVITY_4 Morphological reconstruction is performed with a 4-neighbor connectivity.
Enumeration CONNECTIVITY_8
output
outputObjectImage
The output binary or label image. Its dimensions and type are forced to the same values as the input image. Image nullptr

Object Examples

auto polystyrene_sep = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene_sep.vip" );

FillHoles2d fillHoles2dAlgo;
fillHoles2dAlgo.setInputObjectImage( polystyrene_sep );
fillHoles2dAlgo.setNeighborhood( FillHoles2d::Neighborhood::CONNECTIVITY_8 );
fillHoles2dAlgo.execute();

std::cout << "outputObjectImage:" << fillHoles2dAlgo.outputObjectImage()->toString();
polystyrene_sep = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep.vip"))

fill_holes_2d_algo = imagedev.FillHoles2d()
fill_holes_2d_algo.input_object_image = polystyrene_sep
fill_holes_2d_algo.neighborhood = imagedev.FillHoles2d.CONNECTIVITY_8
fill_holes_2d_algo.execute()

print( "output_object_image:", str( fill_holes_2d_algo.output_object_image ) )
ImageView polystyrene_sep = Data.ReadVipImage( @"Data/images/polystyrene_sep.vip" );

FillHoles2d fillHoles2dAlgo = new FillHoles2d
{
    inputObjectImage = polystyrene_sep,
    neighborhood = FillHoles2d.Neighborhood.CONNECTIVITY_8
};
fillHoles2dAlgo.Execute();

Console.WriteLine( "outputObjectImage:" + fillHoles2dAlgo.outputObjectImage.ToString() );

Function Examples

auto polystyrene_sep = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene_sep.vip" );

auto result = fillHoles2d( polystyrene_sep, FillHoles2d::Neighborhood::CONNECTIVITY_8 );

std::cout << "outputObjectImage:" << result->toString();
polystyrene_sep = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep.vip"))

result = imagedev.fill_holes_2d( polystyrene_sep, imagedev.FillHoles2d.CONNECTIVITY_8 )

print( "output_object_image:", str( result ) )
ImageView polystyrene_sep = Data.ReadVipImage( @"Data/images/polystyrene_sep.vip" );

IOLink.ImageView result = Processing.FillHoles2d( polystyrene_sep, FillHoles2d.Neighborhood.CONNECTIVITY_8 );

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