ImageDev

HExtremaWatershedByBlock

Computes the watershed lines of a grayscale image in a low memory consumption mode.

Access to parameter description

For an introduction: This algorithm is equivalent to the HExtremaWatershed algorithm, but uses a totally different strategy in order to require much less memory.

It is based on a block-wise implementation of the watershed algorithm, building a graph allowing the propagation of the catchments areas through the entire image.

Note: See also

Function Syntax

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

Class Syntax

Parameters

Class Name HExtremaWatershedByBlock

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.
WHITE_OBJECTS The watershed is applied on the negative of the input image in order to separate bright areas.
Enumeration DARK_OBJECTS
input
contrastValue
The depth of the valley used to select the markers of the watershed. Int32 >=0 30
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_OBJECTS 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
blockSize
The size of blocks used to crop the input images. Int32 >=32 256
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" );

HExtremaWatershedByBlock hExtremaWatershedByBlockAlgo;
hExtremaWatershedByBlockAlgo.setInputGrayImage( foam );
hExtremaWatershedByBlockAlgo.setObjectLightness( HExtremaWatershedByBlock::ObjectLightness::DARK_OBJECTS );
hExtremaWatershedByBlockAlgo.setContrastValue( 30 );
hExtremaWatershedByBlockAlgo.setOutputType( HExtremaWatershedByBlock::OutputType::SEPARATED_OBJECTS );
hExtremaWatershedByBlockAlgo.setAlgorithmMode( HExtremaWatershedByBlock::AlgorithmMode::REPEATABLE );
hExtremaWatershedByBlockAlgo.setBlockSize( 256 );
hExtremaWatershedByBlockAlgo.setNeighborhood( HExtremaWatershedByBlock::Neighborhood::CONNECTIVITY_26 );
hExtremaWatershedByBlockAlgo.execute();

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

h_extrema_watershed_by_block_algo = imagedev.HExtremaWatershedByBlock()
h_extrema_watershed_by_block_algo.input_gray_image = foam
h_extrema_watershed_by_block_algo.object_lightness = imagedev.HExtremaWatershedByBlock.DARK_OBJECTS
h_extrema_watershed_by_block_algo.contrast_value = 30
h_extrema_watershed_by_block_algo.output_type = imagedev.HExtremaWatershedByBlock.SEPARATED_OBJECTS
h_extrema_watershed_by_block_algo.algorithm_mode = imagedev.HExtremaWatershedByBlock.REPEATABLE
h_extrema_watershed_by_block_algo.block_size = 256
h_extrema_watershed_by_block_algo.neighborhood = imagedev.HExtremaWatershedByBlock.CONNECTIVITY_26
h_extrema_watershed_by_block_algo.execute()

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

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

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

Function Examples

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

auto result = hExtremaWatershedByBlock( foam, HExtremaWatershedByBlock::ObjectLightness::DARK_OBJECTS, 30, HExtremaWatershedByBlock::OutputType::SEPARATED_OBJECTS, HExtremaWatershedByBlock::AlgorithmMode::REPEATABLE, 256, HExtremaWatershedByBlock::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_by_block( foam, imagedev.HExtremaWatershedByBlock.DARK_OBJECTS, 30, imagedev.HExtremaWatershedByBlock.SEPARATED_OBJECTS, imagedev.HExtremaWatershedByBlock.REPEATABLE, 256, imagedev.HExtremaWatershedByBlock.CONNECTIVITY_26 )

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

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

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