Processing filter headless in jython


That is probably a trivial question but I am having issues to run filters on images in headless mode. When I am running the following with:
ImageJ-linux64 --ij2 --headless --console --run

from ij import IJ
from import ImagePlusReader,ImporterOptions,ImportProcess

# import image
opts = ImporterOptions()
process = ImportProcess(opts)
impReader = ImagePlusReader(process)
imps = impReader.openImagePlus()

curImp = imps[0], "Gaussian Blur...", "sigma=1 stack")

I get

Reading LSM metadata for series #0
[WARN] Unknown Immersion value 'DIC' will be stored as "Other"
[WARN] Unknown LaserMedium value '' will be stored as "Other"
[WARN] Unknown LaserType value 'Chameleon' will be stored as "Other"
java.lang.VerifyError: Bad type on operand stack
Exception Details:
    ij/gui/NonBlockingGenericDialog.dispose()V @5: invokestatic
    Type 'ij/gui/NonBlockingGenericDialog' (current frame, stack[0]) is not assignable to 'java/awt/Window'
  Current Frame:
    bci: @5
    flags: { }
    locals: { 'ij/gui/NonBlockingGenericDialog' }
    stack: { 'ij/gui/NonBlockingGenericDialog' }
    0x0000000: 2ab7 001a 2ab8 001b 2ab4 000b c600 1e2a
    0x0000010: b400 0bb6 000c 4c2b c600 122a b400 0fc6
    0x0000020: 000b 2b2a b400 0fb6 001c b1            
  Stackmap Table:

	at ij.plugin.filter.GaussianBlur.showDialog(
	at ij.plugin.filter.PlugInFilterRunner.<init>(
	at ij.IJ.runPlugIn(
	at ij.Executer.runCommand(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.python.core.PyReflectedFunction.__call__(
	at org.python.core.PyReflectedFunction.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.pycode._pyx0.f$0(
	at org.python.pycode._pyx0.call_function(
	at org.python.core.Py.runCode(
	at org.python.core.__builtin__.eval(
	at org.python.core.__builtin__.eval(
	at org.python.util.PythonInterpreter.eval(
	at org.python.jsr223.PyScriptEngine.eval(
	at org.python.jsr223.PyScriptEngine.eval(
	at javax.script.AbstractScriptEngine.eval(
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

What am I doing wrong?

I could get it to run with:
xvfb-run ImageJ-linux64 --ij2 --console --run

as suggested here:

Not sure if that is the solution?

Hi, it seems that some of the filters in ImageJ have been updated with option to work with NonBlockingGenericDialog (ImageJ 1.52q). It allows some interaction while using a filter (so user in GUI env. can zoom to some part of image while using a filter etc.)

There is an option in Edit->Option->Misc... (or from code Prefs.nonBlockingFilterDialogs) to choose between GenericDialog of NonBlockingGenericDialog. It works fine in GUI but in headless mode even if GenericDialog is default it gives me same error as you got.

Usually on cluster I’m run stuff with xvfb-run so that kind of problems are not visible to me but maybe someone knows solution without xvfb-run that actually works?

Actually method newDialog after mentioned update has a description:

/** Returns a new NonBlockingGenericDialog with given title, unless
	 *  java is running in headless mode; then a GenericDialog will be
	 *  returned (headless mode does not support the NonBlockingGenericDialog).
	 *  @param title Dialog title
	 *  @param imp   The image associated with this dialog
public static GenericDialog newDialog(String title, ImagePlus imp) {

so I it should run smoothly in headless mode but… does not.

This ImageJ 1.52q regression if fixed in the latest daily build (1.53h55).

This minimal script reproduces the problem:

  imp = IJ.openImage("");
  IJ.log("blur1: "+imp.getStatistics().stdDev);, "Gaussian Blur...", "sigma=10");
  IJ.log("blur2: "+imp.getStatistics().stdDev);

The commit is at