rois_to_napari_shapes#

movement.napari.convert_roi.rois_to_napari_shapes(rois)[source]#

Convert a sequence of movement RoIs to napari shapes.

The returned dictionary can be passed directly to napari’s Shapes layer constructor to add all regions of interest (RoIs) in a single call.

Parameters:

rois (Sequence[BaseRegionOfInterest]) – Sequence of LineOfInterest or PolygonOfInterest objects to convert.

Returns:

A dictionary with the following keys:

  • "data": list of (N, 2) arrays in (y, x) order.

  • "shape_type": list of napari shape type strings.

  • "properties": dict with a "name" key containing the RoI names.

Return type:

dict[str, Any]

Notes

The mapping from movement RoI classes to napari shape types is:

movement RoI class

napari shape type

LineOfInterest

"path"

PolygonOfInterest

"polygon"

This function is the inverse of napari_shapes_layer_to_rois(), but some shape information is not preserved when converting back. Specifically, "line", "rectangle", and "ellipse" shapes drawn in napari are all returned as "path" or "polygon".

A closed LineOfInterest (created with loop=True) is also affected: napari has no closed-path shape type, so the segment connecting the last point back to the first is dropped and a warning is emitted.

See also

napari_shapes_layer_to_rois

The inverse of this function.