ImageDev

HExtrema2d

Detects and merges the local maxima or minima of a two-dimensional grayscale image and marks them in a binary image.

Access to parameter description

For an introduction: This algorithm detects and merges local maxima or minima presenting a contrast with their context of minimal height $h$.

In case of local maxima detection, the input is subtracted from the contrast coefficient $h$, then a grayscale reconstruction by dilation is performed on the result of this subtraction.
The regional maxima of the reconstructed image are called the h-maxima.

For detecting local minima, the input is added to the contrast coefficient $h$, then a grayscale reconstruction by erosion is performed with the result of this addition as marker image.
The regional minima of the reconstructed image are called the h-minima.

This algorithm only works with homogeneous gray level objects. The appropriate $h$ value depends on the local contrast between the gray level objects to detect. Increasing this factor too much may eliminate some previously merged objects.

This algorithm is useful for filtering noisy maxima or minima sets.
It also can be used as particle markers in various algorithms; for example, watershed detection.

<b> Figure 1.</b> One-dimensional example of a reconstruction by dilation
Figure 1. One-dimensional example of a reconstruction by dilation




Figure 2. Original image (left) and merged maxima in red (right, contrast=60).


Reference:
P. Soille, Morphological Image Analysis. Principles and Applications, Second Edition, Springer-Verlag, Berlin, pp.203-204, 2003.

See also

Function Syntax

This function returns outputBinaryImage.
// Function prototype
std::shared_ptr< iolink::ImageView > hExtrema2d( std::shared_ptr< iolink::ImageView > inputImage, HExtrema2d::ExtremaType extremaType, uint32_t contrast, HExtrema2d::Neighborhood neighborhood, std::shared_ptr< iolink::ImageView > outputBinaryImage = nullptr );
This function returns outputBinaryImage.
// Function prototype.
h_extrema_2d(input_image: idt.ImageType,
             extrema_type: HExtrema2d.ExtremaType = HExtrema2d.ExtremaType.MAXIMA,
             contrast: int = 4,
             neighborhood: HExtrema2d.Neighborhood = HExtrema2d.Neighborhood.CONNECTIVITY_8,
             output_binary_image: idt.ImageType = None) -> idt.ImageType
This function returns outputBinaryImage.
// Function prototype.
public static IOLink.ImageView
HExtrema2d( IOLink.ImageView inputImage,
            HExtrema2d.ExtremaType extremaType = ImageDev.HExtrema2d.ExtremaType.MAXIMA,
            UInt32 contrast = 4,
            HExtrema2d.Neighborhood neighborhood = ImageDev.HExtrema2d.Neighborhood.CONNECTIVITY_8,
            IOLink.ImageView outputBinaryImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input grayscale image. Image Grayscale nullptr
input
extremaType
The type of extrema to detect.
MAXIMA The regional maxima are extracted from the input image.
MINIMA The regional minima are extracted from the input image.
Enumeration MAXIMA
input
contrast
The contrast level h. UInt32 Any value 4
input
neighborhood
The 2D neighborhood configuration used for the morphological operations.
CONNECTIVITY_4 The neighborhood configuration is a cross.
CONNECTIVITY_8 The neighborhood configuration is a square.
Enumeration CONNECTIVITY_8
output
outputBinaryImage
The output binary image. Its dimensions are forced to the same values as the input. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input grayscale image. image Grayscale None
input
extrema_type
The type of extrema to detect.
MAXIMA The regional maxima are extracted from the input image.
MINIMA The regional minima are extracted from the input image.
enumeration MAXIMA
input
contrast
The contrast level h. uint32 Any value 4
input
neighborhood
The 2D neighborhood configuration used for the morphological operations.
CONNECTIVITY_4 The neighborhood configuration is a cross.
CONNECTIVITY_8 The neighborhood configuration is a square.
enumeration CONNECTIVITY_8
output
output_binary_image
The output binary image. Its dimensions are forced to the same values as the input. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input grayscale image. Image Grayscale null
input
extremaType
The type of extrema to detect.
MAXIMA The regional maxima are extracted from the input image.
MINIMA The regional minima are extracted from the input image.
Enumeration MAXIMA
input
contrast
The contrast level h. UInt32 Any value 4
input
neighborhood
The 2D neighborhood configuration used for the morphological operations.
CONNECTIVITY_4 The neighborhood configuration is a cross.
CONNECTIVITY_8 The neighborhood configuration is a square.
Enumeration CONNECTIVITY_8
output
outputBinaryImage
The output binary image. Its dimensions are forced to the same values as the input. Image null

Object Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

HExtrema2d hExtrema2dAlgo;
hExtrema2dAlgo.setInputImage( polystyrene );
hExtrema2dAlgo.setExtremaType( HExtrema2d::ExtremaType::MAXIMA );
hExtrema2dAlgo.setContrast( 4 );
hExtrema2dAlgo.setNeighborhood( HExtrema2d::Neighborhood::CONNECTIVITY_8 );
hExtrema2dAlgo.execute();

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

h_extrema_2d_algo = imagedev.HExtrema2d()
h_extrema_2d_algo.input_image = polystyrene
h_extrema_2d_algo.extrema_type = imagedev.HExtrema2d.MAXIMA
h_extrema_2d_algo.contrast = 4
h_extrema_2d_algo.neighborhood = imagedev.HExtrema2d.CONNECTIVITY_8
h_extrema_2d_algo.execute()

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

HExtrema2d hExtrema2dAlgo = new HExtrema2d
{
    inputImage = polystyrene,
    extremaType = HExtrema2d.ExtremaType.MAXIMA,
    contrast = 4,
    neighborhood = HExtrema2d.Neighborhood.CONNECTIVITY_8
};
hExtrema2dAlgo.Execute();

Console.WriteLine( "outputBinaryImage:" + hExtrema2dAlgo.outputBinaryImage.ToString() );

Function Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = hExtrema2d( polystyrene, HExtrema2d::ExtremaType::MAXIMA, 4, HExtrema2d::Neighborhood::CONNECTIVITY_8 );

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

result = imagedev.h_extrema_2d(polystyrene, imagedev.HExtrema2d.MAXIMA, 4, imagedev.HExtrema2d.CONNECTIVITY_8)

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

IOLink.ImageView result = Processing.HExtrema2d( polystyrene, HExtrema2d.ExtremaType.MAXIMA, 4, HExtrema2d.Neighborhood.CONNECTIVITY_8 );

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