pyimagej
pyimagej copied to clipboard
Trouble loading TIFF files
Dear PyImageJ team,
I am currently trying to use PyImageJ on a local linux server with the hope of analysing some z-stack data using TrackMate. I mmanaged to install PyImageJ as per the instructions via conda/mamba and the installation appears to work via the recommended test.
However, when I try to load any TIFF files, for example, using the following Python code:
import imagej
ij = imagej.init('/data/axela/Fiji.app')
im = ij.io().open('test_timeseries.tif')
I get the following error
Traceback (most recent call last):
File "DefaultIOService.java", line 68, in org.scijava.io.DefaultIOService.open
File "DefaultIOService.java", line 93, in org.scijava.io.DefaultIOService.open
File "DatasetIOPlugin.java", line 52, in io.scif.io.DatasetIOPlugin.open
File "DatasetIOPlugin.java", line 94, in io.scif.io.DatasetIOPlugin.open
File "DefaultDatasetIOService.java", line 133, in io.scif.services.DefaultDatasetIOService.open
File "DefaultDatasetIOService.java", line 152, in io.scif.services.DefaultDatasetIOService.open
File "ImgOpener.java", line 243, in io.scif.img.ImgOpener.openImgs
File "ImgOpener.java", line 487, in io.scif.img.ImgOpener.createReader
File "DefaultInitializeService.java", line 91, in io.scif.services.DefaultInitializeService.initializeReader
File "AbstractReader.java", line 271, in io.scif.AbstractReader.setSource
File "AbstractParser.java", line 53, in io.scif.AbstractParser.parse
File "AbstractParser.java", line 314, in io.scif.AbstractParser.parse
File "AbstractParser.java", line 244, in io.scif.AbstractParser.parse
File "TIFFFormat.java", line 939, in io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse
File "TIFFFormat.java", line 957, in io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse
File "MinimalTIFFFormat.java", line 412, in io.scif.formats.MinimalTIFFFormat$Parser.typedParse
io.scif.FormatException: io.scif.FormatException: Invalid TIFF file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "DefaultIOService.java", line 68, in org.scijava.io.DefaultIOService.open
File "DefaultIOService.java", line 93, in org.scijava.io.DefaultIOService.open
File "DatasetIOPlugin.java", line 52, in io.scif.io.DatasetIOPlugin.open
File "DatasetIOPlugin.java", line 94, in io.scif.io.DatasetIOPlugin.open
File "DefaultDatasetIOService.java", line 133, in io.scif.services.DefaultDatasetIOService.open
File "DefaultDatasetIOService.java", line 152, in io.scif.services.DefaultDatasetIOService.open
File "ImgOpener.java", line 243, in io.scif.img.ImgOpener.openImgs
File "ImgOpener.java", line 487, in io.scif.img.ImgOpener.createReader
File "DefaultInitializeService.java", line 91, in io.scif.services.DefaultInitializeService.initializeReader
File "AbstractReader.java", line 279, in io.scif.AbstractReader.setSource
java.io.IOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "DefaultIOService.java", line 68, in org.scijava.io.DefaultIOService.open
File "DefaultIOService.java", line 93, in org.scijava.io.DefaultIOService.open
File "DatasetIOPlugin.java", line 52, in io.scif.io.DatasetIOPlugin.open
File "DatasetIOPlugin.java", line 94, in io.scif.io.DatasetIOPlugin.open
File "DefaultDatasetIOService.java", line 133, in io.scif.services.DefaultDatasetIOService.open
File "DefaultDatasetIOService.java", line 152, in io.scif.services.DefaultDatasetIOService.open
File "ImgOpener.java", line 243, in io.scif.img.ImgOpener.openImgs
File "ImgOpener.java", line 493, in io.scif.img.ImgOpener.createReader
io.scif.img.ImgIOException: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "DefaultIOService.java", line 68, in org.scijava.io.DefaultIOService.open
File "DefaultIOService.java", line 93, in org.scijava.io.DefaultIOService.open
File "DatasetIOPlugin.java", line 52, in io.scif.io.DatasetIOPlugin.open
File "DatasetIOPlugin.java", line 94, in io.scif.io.DatasetIOPlugin.open
File "DefaultDatasetIOService.java", line 133, in io.scif.services.DefaultDatasetIOService.open
File "DefaultDatasetIOService.java", line 163, in io.scif.services.DefaultDatasetIOService.open
Exception: Java Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test_imagej.py", line 14, in <module>
dataset = ij.io().open('test_image.tif')
java.io.IOException: java.io.IOException: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
I find that a current workfound is replacing io().open
with the legacy command `ij.IJ.openImage('test_timeseries.tif'). Then, however, I cannot run TrackMate via the following code:
import imagej
ij = imagej.init('/data/axela/Fiji.app', mode='interactive')
im = ij.IJ.openImage('test_image.tif')
plugin = 'TrackMate' # Set plugin for imagej
args = {} # Set the arguments
ij.py.run_plugin(plugin, args, image)
Because I will get the following error:
Please open an image before running TrackMate.
[java.lang.Enum.toString] Please open an image before running TrackMate.[java.lang.Enum.toStrin
Examining this, it appears when I use IJ.openImage
and check type(im)
, the variable im
is defined as a <class 'NoneType'>
. Do you have any advice on how to get around this? Thanks very much for your time!
Best wishes, Axel.
HI @axelalmet,
Thank you for the thorough post on the issue. To me it looks like you're passing an invalid path to the .tif
file. Are you sure you're giving it the right path? I can see in your example you're trying to use the sample test_timeseries.tif
which is in pyimagej/doc/sample-data
, did you open the REPL in this directory when testing or pass the full file path? IJ.openImage
returning a NoneType
also seems to indicate the same problem.
Hi @elevans,
Thank you for getting back to me and apologies for the late response. The way I have things set up, I downloaded test_timeseries.tif
directly and put it in the same folder as my Python script, which I called test_imagej.py
. However, when I tried specifying the full path to test_timeseries.tif
, which is /data/axela/ImagingData/test_timeseries.tif
, I still end up with the same error.
Best wishes, Axel.
Encountered same error before, as this post, can you try imp = ij.IJ.openImage()
to open instead of ij.io().open()
? It solves it for me.
Using ij.io().open(file_path)
is definitely preferred over ij.IJ.openImage(file_path)
; the former is ImageJ2, and the latter is the original ImageJ which only works when the ImageJ Legacy support is enabled in PyImageJ.
@axelalmet With a fresh installation of PyImageJ at latest version (1.4.1 as of this writing), and using the newest version of ImageJ2 (currently 2.13.1), do you still have this error when opening TIFFs via ij.io().open
, and using the full path to the TIFF file?