imagej / imagej/pyimagej

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

Open
#101 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

# 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.

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

...
```

**del_img**:
```
>>> del_img

...
```

# 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.

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.

Research direction

Start by running the provided pyimagej reproduction with a multi-channel time-lapse TIFF, then compare opening the saved output through Fiji's default drag-and-drop opener and the documented workarounds. Done means deleting frames still produces a TIFF that Fiji's default opener loads without an exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.