Segments cells using a marker-controlled watershed algorithm.
Seeds (markers) are detected automatically via distance-transform
peaks or h-minima inside the Otsu foreground of channel. The
watershed then floods from these seeds, level by level along the
surface, so that object boundaries follow its ridges; pixels outside
the foreground are never flooded (only expand_pixels grows objects
beyond it).
Arguments
- image
An
sg_imageobject.- channel
Integer index of the image channel used for segmentation. Default is
1L.- seed_method
Character string specifying how seeds are generated. One of
"h_minima"(default),"distance", or"markers".- h
Numeric; height parameter for h-minima or distance threshold fraction for seed detection. Default is
0.05.- min_distance
Integer; minimum pixel distance between seeds. Default is
10L.- expand_method
Character string specifying how seed regions are expanded. One of
"voronoi"(default) or"dilation".- expand_pixels
Integer; number of pixels to expand beyond the initial watershed regions. Default is
3L.- membrane_channel
Integer or
NULL. If provided, this channel is used as the topographic surface for watershed flooding. IfNULL, the invertedchannelimage is used.
Examples
set.seed(42)
pixels <- matrix(runif(400), nrow = 20, ncol = 20)
img <- new_sg_image(pixels)
mask <- sg_segment_watershed(img, seed_method = "distance", h = 0.3)
#> ℹ Generated 31 seeds via "distance".
#> ✔ Watershed segmented 31 objects.
print(mask)
#> <sg_mask>: 20 x 20, 31 cells
#> Method: watershed