imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.17k stars 332 forks source link

"NameError: name 'command' is not defined" when running ImageJ jython script headless #275

Open markemus opened 3 years ago

markemus commented 3 years ago
Traceback (most recent call last):
  File "/home/markemus/dev/pix2pix/stardist_imagej_script.py", line 52, in <module>
    res = command.run(StarDist2D, False, "input", imp, "modelChoice", "Versatile (H&E nuclei)",).get()
  NameError: name 'command' is not defined

The script includes the services:

#@ DatasetIOService io
#@ CommandService command

and runs successfully when it's run from the ImageJ gui. Do services not work in headless mode? Is there an alternative to using command to run StarDist2D, or another way to import it?

EDIT: The command I'm calling is: ./ImageJ-linux64 --headless --jython ~/dev/pix2pix/stardist_imagej_script.py

imagejan commented 3 years ago

@markemus can you try using the --ij2 flag, and the language-agnostic --run instead of --jython?

./ImageJ-linux64 --ij2 --headless --run ~/dev/pix2pix/stardist_imagej_script.py

See also https://imagej.net/Scripting_Headless.