Sort Segments¶
Sort segments from a skeletonized image into two categories: leaf objects and other objects.
plantcv.morphology.segment_sort(skel_img, objects, mask=None)
returns Secondary objects, primary objects
- Parameters:
- skel_img - Skeleton image (output from plantcv.morphology.skeletonize)
- objects - Segment objects (output from plantcv.morphology.segment_skeleton)
- mask - Binary mask for debugging. If provided, debug image will be overlaid on the mask.
- Context:
- Sorts skeleton segments into two categories: primary and secondary segments. Segments get classified as primary if both end points of the segment coincide with branch points. Segments get classified as secondary if at least one of their endpoints coincide with a tip. By this classification method in the example below primary segments are stem and secondary segments are leaves. Secondary segments get colored green and primary segments get colored fuschia.
Reference Images
from plantcv import plantcv as pcv
# Set global debug behavior to None (default), "print" (to file),
# or "plot" (Jupyter Notebooks or X11)
pcv.params.debug = "print"
# Adjust line thickness with the global line thickness parameter (default = 5),
# and provide binary mask of the plant for debugging. NOTE: the objects and
# hierarchies returned will be exactly the same but the debugging image will look different.
pcv.params.line_thickness = 3
leaf_obj, other_obj = pcv.morphology.segment_sort(skel_img=skeleton,
objects=obj,
hierarchies=hier)
leaf_obj, other_obj = pcv.morphology.segment_sort(skel_img=skeleton,
objects=obj,
hierarchies=hier,
mask=plant_mask)
Segmented Image without Mask
Segmented Image with Mask