Skip to content

Add support for net.imagej.roi.DefultROITree conversion to Python #258

Open
@elevans

Description

@elevans

If you have a net.imagej.Dataset with an attached net.imagej.roi.DefaultROITree and ask for an xarray.DataArray via ij.py.to_xarray() the conversion will fail with:

...
  File "/home/edward/Documents/repos/loci/scyjava/src/scyjava/_convert.py", line 82, in _raise_type_exception
    raise TypeError("Unsupported type: " + str(type(obj)))
TypeError: Unsupported type: <java class 'net.imagej.roi.DefaultROITree'>

This happens because at some point during the Dataset to DataArray step we look through the dataset's properties, which contains the DefaultROITree. This DefaultROITree is passed on to scyjava where it then fails to convert.

Here is a minimal example using the test data in the PyimageJ repo.

import imagej
import scyjava as sj

# init pyimagej
ij = imagej.init(mode='interactive')
print(f"ImageJ Version: {ij.getVersion()}")

# get ImageJ resources
OvalRoi = sj.jimport('ij.gui.OvalRoi')
ov = sj.jimport('ij.gui.Overlay')()

# load data
imp = ij.IJ.openImage('/doc/sample-data/test_timeseries.tif')

# draw ROI
roi = OvalRoi(56, 79, 102, 100)
imp.setRoi(roi)
ov.add(roi)
imp.setOverlay(ov)
imp.show()

# convert imp to dataset
ds = ij.py.to_dataset(imp)

# this call fails
# ij.ui().show(ds)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions