pyimagej icon indicating copy to clipboard operation
pyimagej copied to clipboard

Deleting frames from a time series multi-channel stack throws exception in Fiji

Open elevans opened this issue 4 years ago • 1 comments

Issue

When slicing a multi-channel time lapse tif stack using pyimagej, Fiji's default drag and drop file reader fails to open the file and throws an exception.

Reproducing the bug

Requirements to reproduce bug:

  • A multi-channel time lapse tif stack (e.g. my file has 3 channels and 97 frames).
  • Delete time points from the data.
  • Drag and drop the output file into Fiji.

This snippet will delete 5 frames from a test file and save the output.

import imagej

# start pyimagej
ij = imagej.init()

# load test image
ij_img = ij.io().open('test.tif')
py_img = ij.py.from_java(ij_img)

# delete the first 5 frames
del_img = py_img[5:, :, :, :]

# write output file
out_img = ij.py.to_java(del_img)
file_name = 'test_output.tif'
ij.io().save(out_img, file_name)

When you drag and drop this output file into Fiji the following exception is thrown:

(Fiji Is Just) ImageJ 2.1.0/1.53c; Java 1.8.0_172 [64-bit]; Linux 5.8.0-41-generic; 333MB of 19573MB (1%)
 
java.lang.IllegalArgumentException: Unknown stack type
	at ij.ImageStack.getProcessor(ImageStack.java:289)
	at ij.ImagePlus.setStack(ImagePlus.java:742)
	at ij.ImagePlus.<init>(ImagePlus.java:158)
	at ij.io.Opener.openTiffStack(Opener.java:809)
	at ij.io.Opener.openTiff2(Opener.java:1034)
	at ij.io.Opener.openTiff(Opener.java:842)
	at ij.io.Opener.openImage(Opener.java:317)
	at ij.io.Opener.openImage(Opener.java:243)
	at ij.io.Opener.open(Opener.java:109)
	at ij.io.Opener.openAndAddToRecent(Opener.java:292)
	at ij.plugin.DragAndDrop.openFile(DragAndDrop.java:194)
	at ij.plugin.DragAndDrop.run(DragAndDrop.java:160)
	at java.lang.Thread.run(Thread.java:748)

Checking the xarray object indicates that the five frame deletion was performed successfully:

py_img:

>>> py_img
<xarray.DataArray (Time: 97, Channel: 3, y: 500, x: 500)>
...

del_img:

>>> del_img
<xarray.DataArray (Time: 92, Channel: 3, y: 500, x: 500)>
...

Work arounds

There are two easy work arounds that will enable Fiji to open the pyimagej modified files.

  1. Open the output image using File > Import > Image....
  2. Configure Fiji to use SCIFIO when openning files. Edit > Options > ImageJ2... and check the Use SCIFIO when openning files (BETA!) check box.

Comments

Opening files using either of these two methods works great. From my inspection the output files have been edited the way I intended to.

So there's clearly something "wrong" with the output files from pyimagej that the default opener on Fiji doesn't like.

elevans avatar Feb 08 '21 16:02 elevans

This sounds like an issue in the SCIFIO writer that is incompatible with the ImageJ1 TiffDecoder.

https://github.com/scifio/scifio/issues/322 might be related.

imagejan avatar Feb 09 '21 08:02 imagejan