read_roi#

ktch.io.read_roi(file_path, as_frame=False)[source]#

Read an ImageJ ROI file (.roi) or ROI set (.zip).

Reads the ROI types that store a list of coordinates: closed outlines (polygon, freehand, traced), open curves (polyline, freeline), angles and points. The coordinates are returned as the file stores them, in pixels with y downward (see RoiData for where an integer coordinate lies in a pixel).

Parameters:
file_pathstr or pathlib.Path

Path to a .roi file, or to a .zip of .roi files such as the ROI Manager saves. Entries of the .zip that are not .roi files are skipped.

as_framebool, default=False

If True, return a DataFrame.

Returns:
resultRoiData or list of RoiData or pd.DataFrame

A RoiData for a single ROI, a list of them, in the order of the ROI set, for several, or, with as_frame=True, one DataFrame with columns x, y, name and position and a MultiIndex (specimen_id, coord_id).

Raises:
FileNotFoundError

If the file does not exist.

ValueError

If the file is not a .roi or .zip file, if a ROI set holds no .roi file, if a ROI is not in the ImageJ format or is truncated, or if a ROI is of a type without a coordinate list (rectangle, oval, straight line, composite, text, image, or a freehand ellipse or rotated rectangle). The message names the ROI.

Examples

>>> from ktch.io import read_roi
>>> rois = read_roi("RoiSet.zip")
>>> rois[0].coords