NonBlockingGenericDialog Exception thrown by Mosaic Particle Tracker plugin in Fiji --headless

Dear forum,

I am trying to run the Mosaic particle tracker in Fiji/ImageJ from the command line. Ultimately, my goal is to use the Mosaic particle tracking plugin on a cluster. I was hoping you could help me fix the issue of a java.lang.VerifyError: Bad type on operand stack generated by ij/gui/NonBlockingGenericDialog.

When I call a file “particle-tracker.py”

#@ String path
import os
from ij import IJ
path = str(path)
files = []
counta = 0
for file in os.listdir(path):
    if file.endswith('tif'):
        files.append(os.path.join(path, file))
        counta+=1
files = sorted(files)
if len(files) <1:
    raise Exception("No files matching the criteria in "+path)
counti = 1
for file in files:
    print("("+str(counti)+"/"+str(counta)+") Processing: "+file)
    imp = IJ.openImage(file)
    IJ.run(imp, "Particle Tracker 2D/3D", "radius=3 cutoff=0.001 per/abs=0.500 link=2 displacement=10 dynamics=Brownian")

with this command (on MacOS) on a folder of tif files:
/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --console --run /Users/rene/particle_tracker.py 'path="/Users/rene/TIFFs"'
Fiji opens, the Fiji status bar updates on frames it processes, and the terminal also spits out information on progress. The plugin successfully outputs particle tracking information as files in the “path” directory. Besides the Fiji program window, no other windows are displayed. I kill the program with ctrl-C.

However, as soon as I insert the --headless option in the command, the program throws the above mentioned exception. I have seen this described as an issue here:
http://imagej.1557.x6.nabble.com/Re-NonBlockingGenericDialog-for-Process-gt-Filters-td5021830.html

My unsuccessful attempts to fix this: I opened the mosaic jar file in Eclipse (and in JByteMod) and modified individual or all instances of NonBlockingGenericDialog to GenericDialog (i.e. I butchered other people’s code, without knowing anything about it or about the programming language). It sometimes throws other exceptions (java.awt.HeadlessException) and did not work.

I would really appreciate your help! and/or the answer to a few questions:

  • The NonBlockingGenericDialog class seems to be called when a preview window is created. With or w/o headless mode, there is no actual preview window created, so why does one work, the other doesn’t?
  • Would changing the plugin code require major rewriting, i.e. do the two classes NonBlockingGenericDialog and Generic Dialog have different attributes, i.e. why did my attempt fail?
  • If there is no way I can change the plugin, and no fix to the referenced issue for headless mode in ImageJ in the foreseeable future, would you advise to implement something like a mock display via a program called xvfb?

Hi,

Unfortunately Particle Tracker is quite old software and it uses NonBlockingGenericDialog which makes –headless option useless.
First, let’s deal with closing Fiji after running the script:

#@ String path
import os
from ij import IJ
# ------ NEW LINE:
from java.lang import System;


path = str(path)
files = []
counta = 0

for file in os.listdir(path):
    if file.endswith('tif'):
        files.append(os.path.join(path, file))
        counta+=1
files = sorted(files)
if len(files) <1:
    raise Exception("No files matching the criteria in "+path)
counti = 1
for file in files:
    print("("+str(counti)+"/"+str(counta)+") Processing: "+file)
    imp = IJ.openImage(file)
    IJ.run(imp, "Particle Tracker 2D/3D", "radius=3 cutoff=0.001 per/abs=0.500 link=2 displacement=10 dynamics=Brownian")

# ------ NEW LINE:
System.exit(0);

Check lines marked with NEW LINE. I’m not sure if this is the best way to close Fiji when running script from command line but I do not know other way. With above little changes now when I run such command:

ImageJ-macosx --ij2 --run /Users/gonciarz/test/particle_tracker.py 'path="/Users/gonciarz/test"'

particle tracker runs and after it Fiji window is closed.

Now second part of problem - how to run it on a cluster. Since we need some graphics environment we can use Xvfb to fake it. So the only modification to above command line would be to run it like:

xvfb-run Fiji.app/ImageJ-linux64 --ij2 --run /home/gonciarz/fiji/test/particle_tracker.py 'path="/home/gonciarz/fiji/test"'

I’ve checked above command on our cluster and everything runs smoothly.

Krzysztof,

Thank you so much for your answer! This looks fantastic!
The first part works like a charm. I’ll report back if I have troubles on the cluster in the next days. My next obstacle is installing fiji & xvfb in an environment on the cluster.

Best wishes to Dresden & vielen Dank!

PS: I find the Mosaic particle tracker very reliable when working with a larger 3D dataset, but if anyone has great experience with another app, I’d be happy to test it :slight_smile: