imagej / pyimagej

Use ImageJ from Python
https://pyimagej.readthedocs.io/
Other
474 stars 82 forks source link

Cannot use "Bio Formats Importer" FIJI plugin #133

Closed tomerfried closed 3 years ago

tomerfried commented 3 years ago

I'm trying to use "Bio Formats Importer" by running macros with pyimagej. this is the code:

import imagej
from scyjava import jimport
from skimage import io

ij = imagej.init('C:/Users/Tomer/Desktop/Hereon Project/Fiji.app')
WindowManager = jimport('ij.WindowManager')
macrotest = """
run("Bio-Formats Importer", "open=[C:/Users/Tomer/Desktop/Hereon Project/pyimagej/a.tif] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
"""
ij.py.run_macro(macrotest)
img = WindowManager.getCurrentImage()
ij.py.show(img)

and this is the error:

[java.lang.Enum.toString] Macro Error: Unrecognized command: "Bio-Formats Importer" in line 2

run ( "Bio-Formats Importer" , "open=[C:/Users/Tomer/Desktop/Hereon Project/pyimagej/a.tif] autoscale color_mode=Defaul...[java.lang.Enum.toString] 

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_3740/809048045.py in <module>
      6 ij.py.run_macro(macrotest)
      7 img = WindowManager.getCurrentImage()
----> 8 ij.py.show(img)

~\Desktop\Hereon Project\pyimagej\lib\site-packages\imagej\__init__.py in show(self, image, cmap)
    608             """
    609             if image is None:
--> 610                 raise TypeError('Image must not be None')
    611 
    612             # NB: Import this only here on demand, rather than above.

Iv'e tried using run_plugin() but the error is the same.

Is there a solution for this? because I didn't find any in previous topics online. Basically, all I need is a good images importer for tiff files, captured from a microscope for a biological research. It is important that there would not be a loss of data when importing.

I'd like to hear any alternatives for Bio Formats if you guys know something

Thank you

ctrueden commented 3 years ago

@tomerfried This is probably the same issue as #129. I'll investigate when I have time!

hinerm commented 3 years ago

@ctrueden @elevans so far I have confirmed that there is a negative interaction with the Bio-Formats plugins.config. The importer sets Location=[Local machine] windowless=false and if I instead pass an empty string, the Importer command is suddenly discovered within PyImageJ.

Other commands are similarly missing: Bio-Formats, Bio-Formats (Windowless) and Bio-Formats Windowless Importer (the latter two being the same command)

Oddly, the Bio-Formats (Remote) commands are both present.

To summarize the state of plugins.config:

So I guess the next step is to understand where these params are actually being parsed and interpreted. 😿

hinerm commented 3 years ago

@tomerfried so part of the problem is that ImageJ 1.x's plugin structure is entirely directory based and even though you are specifying a local app, ImageJ 1.x is unable to fully connect the dots to where your plugins are.

With a local Fiji.app you can work around this by doing one of:

sj.config.add_option('-Dplugins.dir=C:/Users/Tomer/Desktop/Hereon Project/Fiji.app/plugins') ij = imagej.init('C:/Users/Tomer/Desktop/Hereon Project/Fiji.app')


@elevans @ctrueden

This also works with a `jgo` initialization but it's kind of dumb since you have to know the jgo directory ahead of time.. e.g.:

import imagej import scyjava as sj sj.config.add_option('-Dplugins.dir=C:\Users\hiner\.jgo\net.imglib2\imglib2-imglyb\1.0.0+net.imagej-imagej-legacy-RELEASE+sc.fiji-fiji-RELEASE') ij = imagej.init('sc.fiji:fiji', headless=False) ij.ui().showUI()



If necessary we could add a bit of code to auto-set `plugins.dir` based on the initialization, but at least we have a workaround for now.

I'm now going to try and understand the mechanism behind the "best effort" plugin detection that still seems to be in play when `plugins.dir` is *not* set.
hinerm commented 3 years ago

I'm now going to try and understand the mechanism behind the "best effort" plugin detection that still seems to be in play when plugins.dir is not set.

It's in imagej-legacy, of course.

This pattern is too restrictive. 👿