ImageDev

MarkerBasedWatershed2d

Performs a fast determination of the watershed lines in a two-dimensional grayscale image from a predefined set of markers.

Access to parameter description

For an introduction: This algorithm performs a fast determination of the watershed lines from specified markers in a label image.
It determines the crest lines separating the markers.

Three ways of presenting the resulting image are provided: Note: Because two bits are used to code the pixels during the algorithm, the input gray level image should range from 0 to 16383. If the range is greater, a normalization is applied to reduce the dynamic of this image.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > markerBasedWatershed2d( std::shared_ptr< iolink::ImageView > inputGrayImage, std::shared_ptr< iolink::ImageView > inputMarkerImage, MarkerBasedWatershed2d::AlgorithmMode algorithmMode, MarkerBasedWatershed2d::OutputType outputType, MarkerBasedWatershed2d::Neighborhood neighborhood, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
marker_based_watershed_2d( input_gray_image,
                           input_marker_image,
                           algorithm_mode = MarkerBasedWatershed2d.AlgorithmMode.REPEATABLE,
                           output_type = MarkerBasedWatershed2d.OutputType.SEPARATED_REGIONS,
                           neighborhood = MarkerBasedWatershed2d.Neighborhood.CONNECTIVITY_4,
                           output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
MarkerBasedWatershed2d( IOLink.ImageView inputGrayImage,
                        IOLink.ImageView inputMarkerImage,
                        MarkerBasedWatershed2d.AlgorithmMode algorithmMode = ImageDev.MarkerBasedWatershed2d.AlgorithmMode.REPEATABLE,
                        MarkerBasedWatershed2d.OutputType outputType = ImageDev.MarkerBasedWatershed2d.OutputType.SEPARATED_REGIONS,
                        MarkerBasedWatershed2d.Neighborhood neighborhood = ImageDev.MarkerBasedWatershed2d.Neighborhood.CONNECTIVITY_4,
                        IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name MarkerBasedWatershed2d

Parameter Name Description Type Supported Values Default Value
input
inputGrayImage
The input grayscale image representing the landscape of the watershed. Image Grayscale nullptr
input
inputMarkerImage
The input label image of markers. Image Label nullptr
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
outputType
The type of output image.
LINES The output is a binary image representing only the watershed lines.
CONTIGUOUS_REGIONS The output is a label image representing only the marked basins. Pixels belonging to the watershed lines are filled with the most present label of their 8 neighbors.
SEPARATED_REGIONS The output is a label image representing only the marked basins. Pixels belonging to the watershed lines are considered as background (set to 0).
Enumeration SEPARATED_REGIONS
input
neighborhood
The type of neighborhood used for the propagation.
CONNECTIVITY_4 Connected components are defined by a 4-neighbor connectivity. The connectivity pattern is a cross.
CONNECTIVITY_8 Connected components are defined by a 8-neighbor connectivity. The connectivity pattern is a square.
Enumeration CONNECTIVITY_4
output
outputImage
The output binary image. Its dimensions are forced to the same values as the input image. Its type depends on the selected outputType and potentially on the highest label of the inputMarkerImage. Image nullptr

Object Examples

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

MarkerBasedWatershed2d markerBasedWatershed2dAlgo;
markerBasedWatershed2dAlgo.setInputGrayImage( polystyrene );
markerBasedWatershed2dAlgo.setInputMarkerImage( polystyrene_sep_label );
markerBasedWatershed2dAlgo.setAlgorithmMode( MarkerBasedWatershed2d::AlgorithmMode::REPEATABLE );
markerBasedWatershed2dAlgo.setOutputType( MarkerBasedWatershed2d::OutputType::LINES );
markerBasedWatershed2dAlgo.setNeighborhood( MarkerBasedWatershed2d::Neighborhood::CONNECTIVITY_4 );
markerBasedWatershed2dAlgo.execute();

std::cout << "outputImage:" << markerBasedWatershed2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))
polystyrene_sep_label = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_sep_label.vip"))

marker_based_watershed_2d_algo = imagedev.MarkerBasedWatershed2d()
marker_based_watershed_2d_algo.input_gray_image = polystyrene
marker_based_watershed_2d_algo.input_marker_image = polystyrene_sep_label
marker_based_watershed_2d_algo.algorithm_mode = imagedev.MarkerBasedWatershed2d.REPEATABLE
marker_based_watershed_2d_algo.output_type = imagedev.MarkerBasedWatershed2d.LINES
marker_based_watershed_2d_algo.neighborhood = imagedev.MarkerBasedWatershed2d.CONNECTIVITY_4
marker_based_watershed_2d_algo.execute()

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

MarkerBasedWatershed2d markerBasedWatershed2dAlgo = new MarkerBasedWatershed2d
{
    inputGrayImage = polystyrene,
    inputMarkerImage = polystyrene_sep_label,
    algorithmMode = MarkerBasedWatershed2d.AlgorithmMode.REPEATABLE,
    outputType = MarkerBasedWatershed2d.OutputType.LINES,
    neighborhood = MarkerBasedWatershed2d.Neighborhood.CONNECTIVITY_4
};
markerBasedWatershed2dAlgo.Execute();

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

Function Examples

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

auto result = markerBasedWatershed2d( polystyrene, polystyrene_sep_label, MarkerBasedWatershed2d::AlgorithmMode::REPEATABLE, MarkerBasedWatershed2d::OutputType::LINES, MarkerBasedWatershed2d::Neighborhood::CONNECTIVITY_4 );

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

result = imagedev.marker_based_watershed_2d( polystyrene, polystyrene_sep_label, imagedev.MarkerBasedWatershed2d.REPEATABLE, imagedev.MarkerBasedWatershed2d.LINES, imagedev.MarkerBasedWatershed2d.CONNECTIVITY_4 )

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

IOLink.ImageView result = Processing.MarkerBasedWatershed2d( polystyrene, polystyrene_sep_label, MarkerBasedWatershed2d.AlgorithmMode.REPEATABLE, MarkerBasedWatershed2d.OutputType.LINES, MarkerBasedWatershed2d.Neighborhood.CONNECTIVITY_4 );

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