watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerwatersheds_marker (Operator)

Name

watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerwatersheds_marker — Extract watersheds and combine basins based on markers.

Signature

watersheds_marker(Image, Markers : Basins : : )

Herror watersheds_marker(const Hobject Image, const Hobject Markers, Hobject* Basins)

Herror T_watersheds_marker(const Hobject Image, const Hobject Markers, Hobject* Basins)

void WatershedsMarker(const HObject& Image, const HObject& Markers, HObject* Basins)

HRegion HImage::WatershedsMarker(const HRegion& Markers) const

static void HOperatorSet.WatershedsMarker(HObject image, HObject markers, out HObject basins)

HRegion HImage.WatershedsMarker(HRegion markers)

def watersheds_marker(image: HObject, markers: HObject) -> HObject

Description

watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerWatershedsMarkerwatersheds_marker segments an image based on the topology of the gray values and returns the resulting regions in BasinsBasinsBasinsBasinsbasinsbasins. The image is interpreted as a “mountain range”. Higher gray values correspond to “mountains”, while lower gray values correspond to “valleys”. The image, interpreted in this particular way, is flooded, starting with the regions defined in MarkersMarkersMarkersMarkersmarkersmarkers, until the entire image is filled. Thus, each pixel is assigned to the marker to which it has the path with the lowest maximum height. If this is the case for multiple markers, the pixel is assigned to either of them.

The resulting basins, one per input region in MarkersMarkersMarkersMarkersmarkersmarkers, are returned in BasinsBasinsBasinsBasinsbasinsbasins. Note that some of those regions might be empty. This can happen if, for example, two marker regions are in the same watershed basin. If a pixel is contained in multiple marker regions, only the last marker region is used as seed for that pixel. It is advised that the marker regions do not overlap.

The flooding is performed only for the domain of ImageImageImageImageimageimage. Parts of the marker regions outside the domain of ImageImageImageImageimageimage are ignored.

It is advisable to apply a smoothing operator (e.g., binomial_filterbinomial_filterBinomialFilterBinomialFilterBinomialFilterbinomial_filter or gauss_filtergauss_filterGaussFilterGaussFilterGaussFiltergauss_filter) to the input image before calling watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerWatershedsMarkerwatersheds_marker. To segment an image, it is also often reasonable to run an edge extractor (such as edges_imageedges_imageEdgesImageEdgesImageEdgesImageedges_image or edges_coloredges_colorEdgesColorEdgesColorEdgesColoredges_color) on the image, and pass the resulting amplitude image to watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerWatershedsMarkerwatersheds_marker.

Attention

If the image contains many fine structures or is noisy, many watershed regions need to be processed internally, and thus the runtime increases considerably.

Execution Information

Parameters

ImageImageImageImageimageimage (input_object)  singlechannelimage objectHImageHObjectHImageHobject (byte / uint2 / real)

Input image.

MarkersMarkersMarkersMarkersmarkersmarkers (input_object)  region-array objectHRegionHObjectHRegionHobject

Initial markers from which to flood the image.

BasinsBasinsBasinsBasinsbasinsbasins (output_object)  region-array objectHRegionHObjectHRegionHobject *

Basins for all markers.

Example (HDevelop)

read_image (Image, 'printer_chip/printer_chip_01')
edges_image (Image, ImaAmp, ImaDir, 'canny', 1, 'nms', 20, 40)

* Compute background marker
full_domain (ImaAmp, ImageFull)
erosion_circle (Image, RegionErosion, 2.5)
difference (Image, RegionErosion, Boundary)

* Compute foreground markers
threshold (Image, Region, 200, 255)
erosion_circle (Region, RegionErosion1, 7.5)
connection (RegionErosion1, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1500, 99999)

* Apply marker-based watersheds
concat_obj (Boundary, SelectedRegions, MarkerRegions)
watersheds_marker (ImageFull, MarkerRegions, Basins)

* Display results
dev_display (Image)
dev_set_color (['#FF000055', '#00FF0055', '#0000FF55', '#FF00FF55', '#FFFF0055', '#00FFFF55', '#80FF0055', '#0080FF55'])
dev_display (MarkerRegions)
dev_set_draw ('fill')
dev_display (Basins)

Result

If all input parameters are valid, watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerWatershedsMarkerwatersheds_marker returns TRUE. If necessary, an exception is raised.

Possible Predecessors

binomial_filterbinomial_filterBinomialFilterBinomialFilterBinomialFilterbinomial_filter, gauss_filtergauss_filterGaussFilterGaussFilterGaussFiltergauss_filter, smooth_imagesmooth_imageSmoothImageSmoothImageSmoothImagesmooth_image, invert_imageinvert_imageInvertImageInvertImageInvertImageinvert_image, edges_imageedges_imageEdgesImageEdgesImageEdgesImageedges_image

Possible Successors

expand_regionexpand_regionExpandRegionExpandRegionExpandRegionexpand_region, select_shapeselect_shapeSelectShapeSelectShapeSelectShapeselect_shape, reduce_domainreduce_domainReduceDomainReduceDomainReduceDomainreduce_domain, openingopeningOpeningOpeningOpeningopening

Alternatives

watershedswatershedsWatershedsWatershedsWatershedswatersheds, pouringpouringPouringPouringPouringpouring, watersheds_thresholdwatersheds_thresholdWatershedsThresholdWatershedsThresholdWatershedsThresholdwatersheds_threshold

Module

Foundation