ImageDev

HExtremaWatershed

Computes the watershed lines of a grayscale image.

Access to parameter description

For an introduction: This algorithm applies a watershed using as a landscape image either, in dark objects mode, the input image directly or, in bright objects mode, its negative.
A contrast level parameter is used to reduce the number of markers for the watershed process and thus of false positive separation lines.

This algorithm is a high-level combination of numerical reconstruction and watershed algorithms.
There is a limitation to the separation ability: if some particles overlap too much, they are not separated by the algorithm. A sensible criteria is that the distance between particle centroids should be larger than their greatest radius.
This algorithm can be used on the gradient modulus to compute best-fit contours.

Note: This algorithm requires up to 8 times the size of the input image as free memory. If the system does not have enough free memory, this algorithm will fail during its computation. In this case, the HExtremaWatershedByBlock should be used instead.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > hExtremaWatershed( std::shared_ptr< iolink::ImageView > inputGrayImage, HExtremaWatershed::ObjectLightness objectLightness, int32_t contrastValue, HExtremaWatershed::OutputType outputType, HExtremaWatershed::AlgorithmMode algorithmMode, HExtremaWatershed::Neighborhood neighborhood, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
h_extrema_watershed( input_gray_image,
                     object_lightness = HExtremaWatershed.ObjectLightness.DARK_OBJECTS,
                     contrast_value = 30,
                     output_type = HExtremaWatershed.OutputType.SEPARATED_OBJECTS,
                     algorithm_mode = HExtremaWatershed.AlgorithmMode.REPEATABLE,
                     neighborhood = HExtremaWatershed.Neighborhood.CONNECTIVITY_26,
                     output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
HExtremaWatershed( IOLink.ImageView inputGrayImage,
                   HExtremaWatershed.ObjectLightness objectLightness = ImageDev.HExtremaWatershed.ObjectLightness.DARK_OBJECTS,
                   Int32 contrastValue = 30,
                   HExtremaWatershed.OutputType outputType = ImageDev.HExtremaWatershed.OutputType.SEPARATED_OBJECTS,
                   HExtremaWatershed.AlgorithmMode algorithmMode = ImageDev.HExtremaWatershed.AlgorithmMode.REPEATABLE,
                   HExtremaWatershed.Neighborhood neighborhood = ImageDev.HExtremaWatershed.Neighborhood.CONNECTIVITY_26,
                   IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name HExtremaWatershed

Parameter Name Description Type Supported Values Default Value
input
inputGrayImage
The input grayscale image. Image Grayscale nullptr
input
objectLightness
The lightness of objects to separate.
DARK_OBJECTS The watershed is directly applied on the input image in order to separate dark areas.
BRIGHT_OBJECTS The watershed is applied on the negative of the input image in order to separate bright areas.
Enumeration DARK_OBJECTS
input
outputType
The type of result image.
SEPARATED_OBJECTS The result image is a grayscale image representing the original from which separation lines are added to dark objects or subtracted from bright objects (split areas).
WATERSHED_RIDGES The result image is a binary image representing the separation lines (watershed).
SEPARATED_BASINS The result image is a label image representing the catchment areas (labeled complement of the watershed).
CONTIGUOUS_BASINS The result image is a label image representing the catchment areas with separation lines filled by a label.
Enumeration SEPARATED_OBJECTS
input
algorithmMode
The mode for applying the watershed algorithm.
REPEATABLE The result is repeatable but slower to compute.
FAST The result is faster to compute but not repeatable because of asynchronous parallel computation. Since a watershed problem does not generally have a unique solution, two processings of the same image can lead to two different results (both exact).
Enumeration REPEATABLE
input
contrastValue
The depth of the valley used to select the markers of the watershed. Int32 >=0 30
input
neighborhood
The 3D neighborhood configuration. This parameter is ignored with a 2D input image.
CONNECTIVITY_6 The structuring element is composed of voxels with a common face with the voxel of interest.
CONNECTIVITY_18 The structuring element is composed of voxels with at least one common edge.
CONNECTIVITY_26 The structuring element is a full cube.
Enumeration CONNECTIVITY_26
output
outputImage
The output grayscale, binary or label image. Its dimensions are forced to the same values as the input image. Its type depends on the outputType parameter. Image nullptr

Object Examples

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

HExtremaWatershed hExtremaWatershedAlgo;
hExtremaWatershedAlgo.setInputGrayImage( foam );
hExtremaWatershedAlgo.setObjectLightness( HExtremaWatershed::ObjectLightness::DARK_OBJECTS );
hExtremaWatershedAlgo.setContrastValue( 30 );
hExtremaWatershedAlgo.setOutputType( HExtremaWatershed::OutputType::SEPARATED_OBJECTS );
hExtremaWatershedAlgo.setAlgorithmMode( HExtremaWatershed::AlgorithmMode::REPEATABLE );
hExtremaWatershedAlgo.setNeighborhood( HExtremaWatershed::Neighborhood::CONNECTIVITY_26 );
hExtremaWatershedAlgo.execute();

std::cout << "outputImage:" << hExtremaWatershedAlgo.outputImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

h_extrema_watershed_algo = imagedev.HExtremaWatershed()
h_extrema_watershed_algo.input_gray_image = foam
h_extrema_watershed_algo.object_lightness = imagedev.HExtremaWatershed.DARK_OBJECTS
h_extrema_watershed_algo.contrast_value = 30
h_extrema_watershed_algo.output_type = imagedev.HExtremaWatershed.SEPARATED_OBJECTS
h_extrema_watershed_algo.algorithm_mode = imagedev.HExtremaWatershed.REPEATABLE
h_extrema_watershed_algo.neighborhood = imagedev.HExtremaWatershed.CONNECTIVITY_26
h_extrema_watershed_algo.execute()

print( "output_image:", str( h_extrema_watershed_algo.output_image ) )
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

HExtremaWatershed hExtremaWatershedAlgo = new HExtremaWatershed
{
    inputGrayImage = foam,
    objectLightness = HExtremaWatershed.ObjectLightness.DARK_OBJECTS,
    contrastValue = 30,
    outputType = HExtremaWatershed.OutputType.SEPARATED_OBJECTS,
    algorithmMode = HExtremaWatershed.AlgorithmMode.REPEATABLE,
    neighborhood = HExtremaWatershed.Neighborhood.CONNECTIVITY_26
};
hExtremaWatershedAlgo.Execute();

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

Function Examples

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

auto result = hExtremaWatershed( foam, HExtremaWatershed::ObjectLightness::DARK_OBJECTS, 30, HExtremaWatershed::OutputType::SEPARATED_OBJECTS, HExtremaWatershed::AlgorithmMode::REPEATABLE, HExtremaWatershed::Neighborhood::CONNECTIVITY_26 );

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

result = imagedev.h_extrema_watershed( foam, imagedev.HExtremaWatershed.DARK_OBJECTS, 30, imagedev.HExtremaWatershed.SEPARATED_OBJECTS, imagedev.HExtremaWatershed.REPEATABLE, imagedev.HExtremaWatershed.CONNECTIVITY_26 )

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

IOLink.ImageView result = Processing.HExtremaWatershed( foam, HExtremaWatershed.ObjectLightness.DARK_OBJECTS, 30, HExtremaWatershed.OutputType.SEPARATED_OBJECTS, HExtremaWatershed.AlgorithmMode.REPEATABLE, HExtremaWatershed.Neighborhood.CONNECTIVITY_26 );

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