pyimagej icon indicating copy to clipboard operation
pyimagej copied to clipboard

Add support for `net.imagej.roi.DefultROITree` conversion to Python

Open elevans opened this issue 1 year ago • 1 comments

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)

elevans avatar Apr 17 '23 22:04 elevans

I've created a new branch for this issue: pyimagej/258-roitree-conversion.

elevans avatar Apr 21 '23 14:04 elevans