pyimagej icon indicating copy to clipboard operation
pyimagej copied to clipboard

Slicing `net.imagej.Dataset` returns an `IntervalView` which does not support dimension metadata

Open elevans opened this issue 2 years ago • 1 comments

Here is a minimal example using the test_timeseries.tif sample data from the PyImageJ repo.

import imagej

# initialize ImageJ
ij = imagej.init()

# load data
dataset = ij.io().open("doc/sample-data/test_timeseries.tif")
xarr = ij.py.from_java(dataset)

# slice data
xarr_slice = xarr[10, :, :, :]
dataset_slice = dataset[ :, :, :, 10]

The xarray slice maintains the associated image metadata:

>>>  xarr_slice.shape
>>>  (250, 250, 3)
>>>  xarr_slice.dims
>>>  ('row', 'col', 'ch')

But the dataset slice (net.imglib2.view.IntervalView) looses the metadata.

>>>  dataset_slice.shape
>>>  (250, 250, 3)
>>>  dataset_slice.dims
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'net.imglib2.view.IntervalView' object has no attribute 'dims'

We should and can do better here. Instead of IntervalView we should wrap slices as net.imagej.Datasets with the appropriate metadata.

elevans avatar Oct 04 '22 14:10 elevans