RoiData#

class ktch.io.RoiData(specimen_name: str, coords: ndarray, roi_type: str = 'polygon', name: str | None = None, position: int | None = None, channel: int | None = None, slice: int | None = None, frame: int | None = None, subpixel: bool = False, spline_fit: bool = False)[source]#

One ImageJ region of interest (ROI) with a list of coordinates.

ImageJ and Fiji save a selection as a .roi file, and the ROI Manager saves a set of them as a .zip of .roi files. Other programs, such as cell-tracking software, export outlines in the same format.

Attributes:
specimen_namestr

The name of the .roi file, or of its entry in a ROI set, without the .roi suffix. It is unique within a ROI set.

coordsndarray of shape (n_coords, 2)

The coordinates as the file stores them, in pixels: x to the right and y downward from the top-left of the image. A closed outline does not repeat its first point.

roi_typestr

"polygon", "freehand" or "traced" for a closed outline, "polyline" or "freeline" for an open curve, "angle" for the three points of an angle, or "point" for points.

namestr or None

The name stored in the ROI, if any. Cell-tracking software, for example, can store the identifier of a tracked object here.

positionint or None

The position in an image stack (1-based), if stored.

channel, slice, frameint or None

The channel, slice and frame of a hyperstack (1-based), if stored.

subpixelbool

Whether the file stores sub-pixel (floating-point) coordinates.

spline_fitbool

Whether ImageJ fits a spline through the coordinates when it shows the ROI. The coordinates are then the control points.

Notes

Which point of a pixel an integer coordinate refers to depends on the program that wrote the file. ImageJ places the integer coordinates of an area ROI (polygon, freehand, traced) at the top-left corner of a pixel, and those of line and point ROIs at its centre. OpenCV’s drawing functions and matplotlib.pyplot.imshow() place integer coordinates at pixel centres. An outline that ImageJ’s wand tool traced along pixel edges is therefore drawn by those libraries half a pixel down and to the right of the edges it follows: subtract 0.5 from its coordinates to overlay it. Outlines that list their boundary pixels, as cv2.findContours does, need no shift.

to_dataframe()[source]#

Return the coordinates as a DataFrame.

Returns:
dfpd.DataFrame

Columns x, y, name and position. Index is a MultiIndex (specimen_id, coord_id).

to_numpy()[source]#

Return the coordinates.

Returns:
coordsndarray of shape (n_coords, 2)

The x and y coordinates.