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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roifile-2026.7.30.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

roifile-2026.7.30-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file roifile-2026.7.30.tar.gz.

File metadata

  • Download URL: roifile-2026.7.30.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for roifile-2026.7.30.tar.gz
Algorithm Hash digest
SHA256 9da29d1ef8088522636e951c93a634a41308f03392c3c96e24f5371491807a41
MD5 7d03e0d220eabf59ecaeec497b8c892a
BLAKE2b-256 dc6c1d13ff9600a4197b3a9738020f5189d43fd5ec78662a279173dfd1e6d88d

See more details on using hashes here.

File details

Details for the file roifile-2026.7.30-py3-none-any.whl.

File metadata

  • Download URL: roifile-2026.7.30-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for roifile-2026.7.30-py3-none-any.whl
Algorithm Hash digest
SHA256 109e86078ba056b35fc2b6d2dcfac8942408202223b0ef5c4aa6f8047a94d68b
MD5 bb13a83d96dda780de839d931c59c869
BLAKE2b-256 e1ec0830d60c31a7b8e1c953568ff873bd9fbc7a751bb83a704cf25cba4a367a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page