Segment image into foreground and background using graph-based segmentation
BW = lazysnapping(___,
segments the image or volume using name-value pairs to control aspects of the
segmentation.Name,Value
)
The lazy snapping algorithm developed by Li et al. clusters foreground and background values using the K-means method. This implementation of the lazy snapping algorithm does not cluster similar foreground or background pixels. To improve performance, reduce the number of pixels with similar values that are identified as foreground or background.
To obtain masks foremask
or backmask
interactively, you can draw an ROI on the image then create a mask from the ROI
by using the createMask
function. For more information, see ROI Creation Overview.
To obtain pixel indices foreind
or
backind
interactively, you can draw a Polyline
ROI object by using the drawpolyline
function. Get the x- and
y-coordinates of the vertices from the
Position
property of the Polyline
.
Finally, convert the coordinates to linear indices by using the sub2ind
function. Note that the
sub2ind
function uses (row,
column) coordinates instead of (x,
y) coordinates.
[1] Y. Li, S. Jian, C. Tang, H. Shum, Lazy Snapping In Proceedings from the 31st International Conference on Computer Graphics and Interactive Techniques, 2004.