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

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]"

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

  • Fix undefined enum values overwriting UNKNOWN member value (breaking).

  • Fix autoname to use center of bounding box (breaking).

  • Fix writing names, properties, and text with non-BMP characters.

  • Fix unwrapping of empty bounding boxes.

  • Fix coordinates of subpixel RECT and OVAL ROIs.

  • Fix various edge cases in reading, writing, and hexcolor.

  • Raise ValueError on oversized data and skip non-ROI ZIP entries (breaking).

  • Add text_draw_string_mode field.

  • Improve plotting (closed and filled shapes, colors, pixel offset).

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

  • …

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

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.11.6
File Size Uploaded Provenance Actions
roifile-2026.11.6.tar.gz 31.9 kB Without provenance Details for roifile-2026.11.6.tar.gz

Built distribution (wheel)

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

Total release size: 55.7 kB

Release files / roifile-2026.11.6.tar.gz

Download URL roifile-2026.11.6.tar.gz
Size 31.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec82880c154ba1548c83b5bbc52db63ca94fcf73d4b601e5aea2e0ec5f1b3208
BLAKE2b-256 checksum
How to use checksums
767f0a1d0768be7a686a7e83648b2bf36d91d33d7910965d3680eaddfc76678b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

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

Download URL roifile-2026.11.6-py3-none-any.whl
Size 23.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50f98abfe4bdac14224262648f8a304a6f5a61cede361dfb77de5fe276167845
BLAKE2b-256 checksum
How to use checksums
7360550b745097cabe1458a844dee81ed21f9a58352ff2b96d40df30d33876c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for roifile 2026.11.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2026.11.6 This release

2 release files No provenance

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