imagej / imagej/pyimagej

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

Open
#258 1 comment 0 reactions 1 assignee View on GitHub

@elevans is already working on this.

Since Apr 21, 2023.

enhancement
Dominant language
Python
Stars
534
Forks
95
PR merge metrics
No merged PRs in 30d

Description

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:

```python
...
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:
```
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.

```python
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)
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.