Skip to main content

Roifile is a Python library to read, write, create, and plot ImageJ ROIs, an undocumented and ImageJ application specific format to store regions of interest, geometric shapes, paths, text, and whatnot for image overlays.

Author:

Christoph Gohlke

License:

BSD-3-Clause

Version:

2026.7.30

DOI:

10.5281/zenodo.6941603

Quickstart

Install the roifile package and all dependencies from the Python Package Index:

python -m pip install -U "roifile[all]"

View overlays stored in a ROI, ZIP, or TIFF file:

python -m roifile file.roi

See Examples for using the programming interface.

Source code, examples, and support are available on GitHub.

Requirements

This revision was tested with the following requirements and dependencies (other versions may work):

Revisions

2026.7.30

  • Use Java compatible rounding for subpixel coordinates (breaking).

  • Recover roi names stored as Latin-1 instead of UTF-16.

  • Drop support for Python 3.11 and numpy 2.0 (SPEC0).

  • Support Python 3.15.

2026.2.10

  • Revise wrapping of integer coordinates again (breaking).

  • Bump file version to 229.

  • Support groups > 255 (untested).

  • Support IMAGE subtype (requires imagecodecs).

  • Add point_type and point_size properties for point ROIs.

  • Do not return empty paths in path2coords.

  • Improve documentation.

2026.1.29

  • Fix code review issues.

2026.1.22

  • Fix boolean codec in ImagejRoi.properties.

2026.1.20

  • Fix reading ImagejRoi.props.

  • Add ImagejRoi.properties property to decode and encode ImagejRoi.props.

2026.1.8

  • Improve code quality.

  • Drop support for Python 3.10.

2025.12.12

  • Move tests to separate module.

2025.5.10

  • Support Python 3.14.

2025.2.20

Refer to the CHANGES file for older revisions.

Notes

The ImageJ ROI format cannot store integer coordinate values outside the range of -5000..60536.

Refer to the ImageJ RoiDecoder.java source code for a reference implementation.

Other Python packages handling ImageJ ROIs:

Examples

Create a new ImagejRoi instance from an array of x, y coordinates, then set ROI properties:

>>> roi = ImagejRoi.frompoints([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]])
>>> roi.roitype = ROI_TYPE.POINT
>>> roi.point_size = ROI_POINT_SIZE.LARGE
>>> roi.options |= ROI_OPTIONS.SHOW_LABELS

Export the instance to an ImageJ ROI formatted byte string or file:

>>> out = roi.tobytes()
>>> out[:4]
b'Iout'
>>> roi.tofile('_test.roi')

Read the ImageJ ROI from the file and verify the content:

>>> roi2 = ImagejRoi.fromfile('_test.roi')
>>> roi2 == roi
True
>>> roi.roitype == ROI_TYPE.POINT
True
>>> roi.subpixelresolution
True
>>> roi.coordinates()
array([[1.1, 2.2],
       [3.3, 4.4],
       [5.5, 6.6]], dtype=float32)
>>> roi.left, roi.top, roi.right, roi.bottom
(1, 2, 7, 8)
>>> roi2.name = 'test'

Plot the ROI using matplotlib:

>>> roi.plot()

Write the ROIs to a ZIP file:

>>> roiwrite('_test.zip', [roi, roi2], mode='w')

Read the ROIs from the ZIP file:

>>> rois = roiread('_test.zip')
>>> assert len(rois) == 2 and rois[0] == roi and rois[1].name == 'test'

Write the ROIs to an ImageJ formatted TIFF file:

>>> import numpy
>>> import tifffile
>>> tifffile.imwrite(
...     '_test.tif',
...     numpy.zeros((9, 9), 'u1'),
...     imagej=True,
...     metadata={'Overlays': [roi.tobytes(), roi2.tobytes()]},
... )

Read the ROIs embedded in an ImageJ formatted TIFF file:

>>> rois = roiread('_test.tif')
>>> assert len(rois) == 2 and rois[0] == roi and rois[1].name == 'test'

View the overlays stored in a ROI, ZIP, or TIFF file from a command line:

python -m roifile _test.roi

For an advanced example, see roifile_demo.py in the source distribution.

Release files for roifile 2026.7.30

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for roifile 2026.7.30
File Size Uploaded
roifile-2026.7.30.tar.gz 28.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for roifile 2026.7.30
File Interpreter ABI Platform
roifile-2026.7.30-py3-none-any.whl Python 3 none any Details

Total release size:50.1 kB

Release files / roifile-2026.7.30.tar.gz

Download URL roifile-2026.7.30.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9da29d1ef8088522636e951c93a634a41308f03392c3c96e24f5371491807a41
BLAKE2b-256 checksum
How to use checksums
dc6c1d13ff9600a4197b3a9738020f5189d43fd5ec78662a279173dfd1e6d88d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / roifile-2026.7.30-py3-none-any.whl

Download URL roifile-2026.7.30-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
109e86078ba056b35fc2b6d2dcfac8942408202223b0ef5c4aa6f8047a94d68b
BLAKE2b-256 checksum
How to use checksums
e1ec0830d60c31a7b8e1c953568ff873bd9fbc7a751bb83a704cf25cba4a367a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page