ImageDev

GrayscaleFillHoles2d

Fills holes in particles of a two-dimensional grayscale image.

Access to parameter description

For an introduction: This algorithm is analogous to the FillHoles2d which is dedicated to the binary case. It fills darks areas that are not connected to the image borders with the maximal gray level surrounding them. This algorithm uses the grayscale reconstruction by erosion algorithm. The marker image used by the reconstruction is generated with gray levels equal to: The thresholdFillingValue parameter sets the maximum gray level from which the bottom of a valley is considered as a hole.



Figure 1. Original image, gray hole fill result (hole level = image maximum)

Reference:
P. Soille, Morphological Image Analysis. Principles and Applications, Second Edition, Springer-Verlag, Berlin, p.208, 2003.

See also

Function Syntax

This function returns the outputImage output parameter.
// Function prototype.
std::shared_ptr< iolink::ImageView >
grayscaleFillHoles2d( std::shared_ptr< iolink::ImageView > inputImage,
                      double thresholdFillingValue,
                      GrayscaleFillHoles2d::Neighborhood neighborhood,
                      std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns the outputImage output parameter.
// Function prototype.
grayscale_fill_holes_2d( input_image,
                         threshold_filling_value = 1,
                         neighborhood = GrayscaleFillHoles2d.Neighborhood.CONNECTIVITY_8,
                         output_image = None )
This function returns the outputImage output parameter.
// Function prototype.
public static IOLink.ImageView
GrayscaleFillHoles2d( IOLink.ImageView inputImage,
                      double thresholdFillingValue = 1,
                      GrayscaleFillHoles2d.Neighborhood neighborhood = ImageDev.GrayscaleFillHoles2d.Neighborhood.CONNECTIVITY_8,
                      IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name GrayscaleFillHoles2d

Parameter Name Description Type Supported Values Default Value
input
inputImage
The grayscale input image. Image Binary, Label or Grayscale nullptr
input
thresholdFillingValue
The value filling the marker image inside (the gray level under which valleys are filled). The common usage is to set it at the image maximum intensity. Float64 Any value 1
input
neighborhood
The 2D neighborhood configuration for performing erosions of the numerical reconstruction.
CONNECTIVITY_8 The structuring element is a square.
CONNECTIVITY_4 The structuring element is a cross.
Enumeration CONNECTIVITY_8
output
outputImage
The grayscale output image. Its dimensions and type are forced to the same values as the input. Image nullptr

Object Examples

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

GrayscaleFillHoles2d grayscaleFillHoles2dAlgo;
grayscaleFillHoles2dAlgo.setInputImage( polystyrene );
grayscaleFillHoles2dAlgo.setThresholdFillingValue( 0.0 );
grayscaleFillHoles2dAlgo.setNeighborhood( GrayscaleFillHoles2d::Neighborhood::CONNECTIVITY_8 );
grayscaleFillHoles2dAlgo.execute();

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

grayscale_fill_holes_2d_algo = imagedev.GrayscaleFillHoles2d()
grayscale_fill_holes_2d_algo.input_image = polystyrene
grayscale_fill_holes_2d_algo.threshold_filling_value = 0.0
grayscale_fill_holes_2d_algo.neighborhood = imagedev.GrayscaleFillHoles2d.CONNECTIVITY_8
grayscale_fill_holes_2d_algo.execute()

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

GrayscaleFillHoles2d grayscaleFillHoles2dAlgo = new GrayscaleFillHoles2d
{
    inputImage = polystyrene,
    thresholdFillingValue = 0.0,
    neighborhood = GrayscaleFillHoles2d.Neighborhood.CONNECTIVITY_8
};
grayscaleFillHoles2dAlgo.Execute();

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

Function Examples

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

auto result = grayscaleFillHoles2d( polystyrene, 0.0, GrayscaleFillHoles2d::Neighborhood::CONNECTIVITY_8 );

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

result = imagedev.grayscale_fill_holes_2d( polystyrene, 0.0, imagedev.GrayscaleFillHoles2d.CONNECTIVITY_8 )

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

IOLink.ImageView result = Processing.GrayscaleFillHoles2d( polystyrene, 0.0, GrayscaleFillHoles2d.Neighborhood.CONNECTIVITY_8 );

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