Converting macro to python script (headless) - There are no images open


I am a developer and new to ImageJ and by no means claim an understanding of its use, however I was trying to do something that I thought would be relatively straight forward.

I have a working macro that I was attempting to turn into a python script that could be run from the command line, headless.

I ran into an issue that has me stumped.

The following code is stored in a file called “”: (note the entire macro does more than this, but I have limited to the salient code)

   from ij import IJ
   imp = IJ.openImage("C:\\Users\\me\\\\IMG_0723.JPG"), "Hue Colours", "white_min=200 black_max=100 tolerance=10 light_dark_threshold=0.50 
      saturation_min=0.10 _white _red _greenyellow_light _aqua _orange _greenyellow_dark_ _grey _brown 
      _green_light_ _yellow_light_ _green_dark_ _magenta _yellow_dark_ make"), "8-bit", "")"Dilate")

When I run “ImageJ-win64.exe --ij2 --headless --console --run”, I receive the error “There are no images open”.

When running the same code via the ImageJ GUI scripting console, it works.

I have tried changing"Dilate") to, "Dilate") but that complains that the args are not a string.

I think what is happening is that “Dilate” wants to run on the active image window, but doesn’t support having an image object passed to it. If this is true, how can I make this work in a headless scenario?

Thanks in advance for the help. I have been searching and reading for hours and can’t seem to find an existing example of this issue.

Hi @DanH,

the run() method expects an image as first argument and all together three arguments. Otherwise you may get the error you saw. Try,, "Dilate", "");

That could be it.


1 Like

Thanks @haesleinhuepf !

That got me past the error and makes perfect sense. Should have realized from the “8-bit” run reference that a 3rd parameter is expected even if it is blank.


1 Like