Skip to main content

Read and write ImageJ ROI format

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.9.22

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 and Documentation 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.9.22

  • Accept buffer objects and avoid unnecessary copies in ImagejRoi.frombytes.

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

Import functions and classes used in these examples:

>>> from roifile import (
...     ImagejRoi,
...     roiread,
...     roiwrite,
...     ROI_TYPE,
...     ROI_POINT_SIZE,
...     ROI_OPTIONS,
... )

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 the command line:

python -m roifile _test.roi

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

Metadata

Release files for roifile 2026.9.22

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.9.22
File Size Uploaded
roifile-2026.9.22.tar.gz 29.0 kB Details

Built distribution (wheel)

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

Total release size: 50.9 kB

Release files / roifile-2026.9.22.tar.gz

Download URL roifile-2026.9.22.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ba1de699dbabef664564cba6c021c2a01b47437d95b17d6ecf78287f46ef1a54
BLAKE2b-256 checksum
How to use checksums
5f2cd0706309b51ee03c180d34cbe914150188f0d3cb9b7c31ce30c934910ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

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

Download URL roifile-2026.9.22-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bde74e084c4f2f07edd0d54df41fc3b482a548044ed43fbbed3e0db6b77363e
BLAKE2b-256 checksum
How to use checksums
9bdc4b2843b4d5f7ce8f328f8c17616f76f3d935b313047ca1c67e4c6d31392a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7
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