ImageJ headless script cannot take multiple command line parameters

Goal

Hi all, I’m currently trying to modify an headless ImageJ python script so that I can provide multiple command line arguments to specify both input file name and output path.

Ideally, I am trying to run the script as:

ImageJ-linux64 --ij2 --headless --console --run myScript.py "FILENAME='/path/to/filename'" "OUTPATH='/path/to/output'"

with FILENAME as input file path, and OUTPATH as output file path.

Problem

FILENAME parameter works fine, but when I try to add another parameter by

# @String OUTPATH

or

# @File(label = "Output Directory," style = 'directory) OUTPATH

I get an error from ImageJ saying that

Unrecognized format or file not found:
OUTPATH='/path/to/output'

It seems that I cannot add additional string parameter for some reason.

I can seem to create another simple ImageJ script

# @String name1
# @String name2
print(name1 + name2)

and this script does not have a problem with multiple parameters. (i.e. “name1=‘apple’” “name2=‘banana’”)

Does anyone have a thought on why my script cannot recognize second input parameter and only one right now?

I’m including the head of the script below, as I suspect the issue must be somewhere here.

Thanks.

Code

# @File(label = "Image File", persist= false) FILENAME
# @OUTPUT String FILENAME
# @UIService uiService
# @LogService log

import os
import sys
from loci.formats import MetadataTools
from loci.formats import ImageReader
from loci.plugins.out import Exporter
from loci.plugins import LociExporter
from loci.plugins. in import ImporterOptions
from loci.plugins.util import LociPrefs
from loci.plugins import BF
from loci.formats. in import ZeissCZIReader
from loci.formats. in import DynamicMetadataOptions
from ij import IJ, ImagePlus, ImageStack, Prefs
from ij.measure import Calibration
#from org.scijava.log import LogLevel

# get the FILENAME as string
imagefile = FILENAME.toString()


I suspect you want to send both arguments as a single string, and then split it… but maybe there is another way.

1 Like

Oh that’s an interesting suggestion; I suppose I could do “FILENAME=‘input/file/path | output/file/path’” and split them in the script.

Thanks, I will be using that as a temporary solution for now. I hope I get to eventually find out why multiple parameters is not working though.

1 Like