Problems when running particle analyzer in headless mode

Hi, when try to run the Particle Analyzer in headless mode I get the error show below, but it works fine when I run the respective python script from the script editor (non-headless) --> see code below. (addROIManager = False)

As far as I remember is has always worked fine, so I am little clueless what is going on here. Any ideas?

Sebi

(base) C:\Users\m1srh\Documents\Apeer_Modules\particle_analyzer_fiji_e5f51d0e-07a1-4ca0-b868-619fcc2b504f>docker run -it --rm -v c:\Temp\input:/input -v c:\Temp\output:/output --env-file wfe.env test/apeer_test_panalyzer:latest
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/Fiji.app/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/Fiji.app/plugins/Max_Inscribed_Circles-1.1.0.jar
[INFO] Reading available sites from https://imagej.net/
[INFO] Starting ...
[INFO] Filename               : /input/cell2D_TH.ome.tiff
[INFO] -----------------------------------------
[INFO] Extract Channel        : True
[INFO] Channel Index          : 1
[INFO] -----------------------------------------
[INFO] Fill Holes             : True
[INFO] -----------------------------------------
[INFO] Watershed Separation   : True
[INFO] -----------------------------------------
[INFO] Minimum Size [pixel]   : 100
[INFO] Maximum Size [pixel]   : 100000000
[INFO] Minimum Circularity    : 0.0
[INFO] Maximum Circularity    : 1.0
[INFO] Exclude Edge Particles : True
[INFO] Result Table Format    : csv
[INFO] ------------  START IMAGE ANALYSIS ------------
[INFO] New basename :/output/cell2D_TH
[INFO] Opening Image: /input/cell2D_TH.ome.tiff
[INFO] SizeC : 1
[INFO] ImageCount_OME : 0
[INFO] SeriesCount_BF : 1
[INFO] is3d : False
[INFO] ScaleY : 0.454
[INFO] ScaleX : 0.454
[INFO] Extension : .ome.tiff
[INFO] SizeT : 1
[INFO] Output SizeX : 1376
[INFO] ScaleZ : 1.0
[INFO] Output SizeY : 1104
[INFO] SizeX : 1376
[INFO] Pyramid Level Output : 0
[INFO] SizeZ : 1
[INFO] SizeY : 1104
[INFO] Output Slices : 1
[INFO] Start Processing ...
Number of Channels: 1
[INFO] Fill Holes ...
Watershed : 2D image
Apply Watershed to Binary image ...
<type 'ij.process.ByteProcessor'>
('isBinary : ', True)
        Label   Area    BX      BY      Width   Height  Slice
1       C1-cell2D_TH.ome.tiff   184.886 69.008  3.632   18.614  13.166  1
2       C1-cell2D_TH.ome.tiff   246.927 157.084 16.344  18.160  17.706  1
3       C1-cell2D_TH.ome.tiff   192.512 106.690 18.614  16.798  14.074  1
4       C1-cell2D_TH.ome.tiff   324.220 25.878  19.068  23.154  18.160  1
...
100     C1-cell2D_TH.ome.tiff   200.139 440.834 463.988 18.614  16.344  1
101     C1-cell2D_TH.ome.tiff   218.277 439.018 480.786 17.252  18.160  1
[ERROR] null
Traceback (most recent call last):
  File "/Fiji.app/scripts/panalyzer_fiji.py", line 182, in <module>
    imp, pastack, results = run(IMAGEPATH, outputpath_orig,
  File "/Fiji.app/scripts/panalyzer_fiji.py", line 94, in run
    pastack, results = AnalyzeTools.analyzeParticles(imp,
  File "/Fiji.app/scripts/fijipytools.py", line 810, in analyzeParticles
    p.analyze(imp, ip)
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at ij.text.TextWindow.<init>(TextWindow.java:53)
        at ij.text.TextWindow.<init>(TextWindow.java:41)
        at ij.measure.ResultsTable.show(ResultsTable.java:978)
        at ij.plugin.filter.ParticleAnalyzer.updateSliceSummary(ParticleAnalyzer.java:675)
        at ij.plugin.filter.ParticleAnalyzer.analyze(ParticleAnalyzer.java:615)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
java.awt.HeadlessException: java.awt.HeadlessException

        at org.python.core.Py.JavaError(Py.java:552)
        at org.python.core.Py.JavaError(Py.java:543)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:515)
        at org.python.core.PyObject.__call__(PyObject.java:519)
        at org.python.core.PyMethod.__call__(PyMethod.java:156)
        at fijipytools$py.analyzeParticles$27(/Fiji.app/scripts/fijipytools.py:814)
        at fijipytools$py.call_function(/Fiji.app/scripts/fijipytools.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyFunction.function___call__(PyFunction.java:471)
        at org.python.core.PyFunction.__call__(PyFunction.java:466)
        at org.python.pycode._pyx0.run$1(/Fiji.app/scripts/panalyzer_fiji.py:109)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/panalyzer_fiji.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyFunction.function___call__(PyFunction.java:471)
        at org.python.core.PyFunction.__call__(PyFunction.java:466)
        at org.python.pycode._pyx0.f$0(/Fiji.app/scripts/panalyzer_fiji.py:227)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/panalyzer_fiji.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at ij.text.TextWindow.<init>(TextWindow.java:53)
        at ij.text.TextWindow.<init>(TextWindow.java:41)
        at ij.measure.ResultsTable.show(ResultsTable.java:978)
        at ij.plugin.filter.ParticleAnalyzer.updateSliceSummary(ParticleAnalyzer.java:675)
        at ij.plugin.filter.ParticleAnalyzer.analyze(ParticleAnalyzer.java:615)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        ... 36 more

(base) C:\Users\m1srh\Documents\Apeer_Modules\particle_analyzer_fiji_e5f51d0e-07a1-4ca0-b868-619fcc2b504f>

Python coded used:

class AnalyzeTools:

    @staticmethod
    def analyzeParticles(imp, minsize, maxsize, mincirc, maxcirc,
                         filename='Test.czi',
                         addROIManager=True,
                         headless=False,
                         exclude=True):

        if addROIManager is True:

            # get the ROI manager instance
            rm = RoiManager.getInstance()
            if rm is None:
                rm = RoiManager()
            rm.runCommand("Associate", "true")

            if exclude is False:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \

            if exclude is True:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        if addROIManager is False:

            if exclude is False:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \

            if exclude is True:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        measurements = PA.STACK_POSITION \
            + PA.LABELS \
            + PA.AREA \
            + PA.RECT \

        results = ResultsTable()
        p = PA(options, measurements, results, minsize, maxsize, mincirc, maxcirc)
        p.setHideOutputImage(True)
        particlestack = ImageStack(imp.getWidth(), imp.getHeight())

        for i in range(imp.getStackSize()):
            imp.setSliceWithoutUpdate(i + 1)
            ip = imp.getProcessor()
            #IJ.run(imp, "Convert to Mask", "")
            p.analyze(imp, ip)
            mmap = p.getOutputImage()
            particlestack.addSlice(mmap.getProcessor())

        return particlestack, results

I tested the script above also without putting Fiji inside a Docker container an ran into the same issue. The the problem is rather that the Particle Analyzer does not work in headless mode anymore.

Any idea?

Sebi

λ Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
Feb 18, 2020 11:56:00 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[INFO] Overriding Ice ; identifier: script:LUTs/_CMOcean/Ice_.ijm; jar: file:/C:/Users/m1srh/Documents/Fiji/jars/scijava-common-2.80.1.jar
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/C:/Users/m1srh/Documents/Fiji/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/C:/Users/m1srh/Documents/Fiji/plugins/Max_Inscribed_Circles-1.1.0.jar
[WARNING] Ignoring invalid argument: -ij2
[INFO] Starting ...
[INFO] Filename               : C:\Temp\input\cell2D_TH.ome.tiff
[INFO] -----------------------------------------
[INFO] Extract Channel        : False
[INFO] Channel Index          : 1
[INFO] -----------------------------------------
[INFO] Fill Holes             : True
[INFO] -----------------------------------------
[INFO] Watershed Separation   : True
[INFO] Watershed Conectivity  : 6
[INFO] -----------------------------------------
[INFO] Minimum Size [pixel]   : 10
[INFO] Maximum Size [pixel]   : 100000
[INFO] Minimum Circularity    : 0.3
[INFO] Maximum Circularity    : 1.0
[INFO] Exclude Edge           : True
[INFO] Result Table Format    : csv
[INFO] ------------  START IMAGE ANALYSIS ------------
[INFO] New basename :C:\Temp\input\cell2D_TH
[INFO] Opening Image: C:\Temp\input\cell2D_TH.ome.tiff
[INFO] SizeC : 1
[INFO] ImageCount_OME : 0
[INFO] SeriesCount_BF : 1
[INFO] is3d : False
[INFO] ScaleY : 0.454
[INFO] ScaleX : 0.454
[INFO] Extension : .ome.tiff
[INFO] SizeT : 1
[INFO] Output SizeX : 1376
[INFO] ScaleZ : 1.0
[INFO] Output SizeY : 1104
[INFO] SizeX : 1376
[INFO] Pyramid Level Output : 0
[INFO] SizeZ : 1
[INFO] SizeY : 1104
[INFO] Output Slices : 1
[INFO] Start Processing ...
[INFO] Fill Holes ...
Detected 2D image.
Watershed : 2D image
Apply Watershed to Binary image ...
<type 'ij.process.ByteProcessor'>
('isBinary : ', True)
        Label   Area    BX      BY      Width   Height  Slice
1       cell2D_TH.ome-bin       897     152     8       41      29      1
2       cell2D_TH.ome-bin       1198    346     36      40      39      1
3       cell2D_TH.ome-bin       934     235     41      37      31      1
4       cell2D_TH.ome-bin       1573    57      42      51      40      1
5       cell2D_TH.ome-bin       1459    9       67      33      54      1
6       cell2D_TH.ome-bin       1511    1253    69      51      37      1
7       cell2D_TH.ome-bin       1358    157     70      41      48      1
8       cell2D_TH.ome-bin       999     540     70      32      44      1
9       cell2D_TH.ome-bin       873     278     76      42      30      1
10      cell2D_TH.ome-bin       877     58      104     33      37      1
11      cell2D_TH.ome-bin       906     310     112     43      28      1
12      cell2D_TH.ome-bin       1065    218     125     44      31      1
13      cell2D_TH.ome-bin       1044    69      143     48      36      1
14      cell2D_TH.ome-bin       916     255     153     44      30      1
15      cell2D_TH.ome-bin       1167    530     169     37      42      1
16      cell2D_TH.ome-bin       1409    127     193     48      41      1
17      cell2D_TH.ome-bin       921     219     194     36      40      1
18      cell2D_TH.ome-bin       852     192     217     40      29      1
19      cell2D_TH.ome-bin       714     566     221     33      31      1
20      cell2D_TH.ome-bin       1001    631     225     45      34      1
21      cell2D_TH.ome-bin       935     338     229     42      29      1
22      cell2D_TH.ome-bin       591     584     234     28      33      1
23      cell2D_TH.ome-bin       713     97      235     34      31      1
24      cell2D_TH.ome-bin       928     724     238     51      23      1
25      cell2D_TH.ome-bin       2409    24      242     54      62      1
26      cell2D_TH.ome-bin       1184    503     246     44      36      1
27      cell2D_TH.ome-bin       806     409     250     34      32      1
28      cell2D_TH.ome-bin       923     78      259     30      39      1
29      cell2D_TH.ome-bin       1274    786     266     50      34      1
30      cell2D_TH.ome-bin       734     108     267     31      27      1
31      cell2D_TH.ome-bin       1258    191     268     49      37      1
32      cell2D_TH.ome-bin       1160    1046    268     35      45      1
33      cell2D_TH.ome-bin       1466    975     303     37      49      1
34      cell2D_TH.ome-bin       1421    697     314     49      45      1
35      cell2D_TH.ome-bin       501     75      319     23      29      1
36      cell2D_TH.ome-bin       1240    904     325     34      47      1
37      cell2D_TH.ome-bin       863     595     329     36      32      1
38      cell2D_TH.ome-bin       710     94      330     31      30      1
39      cell2D_TH.ome-bin       1101    394     343     37      42      1
40      cell2D_TH.ome-bin       1039    475     344     34      51      1
41      cell2D_TH.ome-bin       1026    817     345     36      42      1
42      cell2D_TH.ome-bin       1076    560     369     39      35      1
43      cell2D_TH.ome-bin       1473    1030    371     44      52      1
44      cell2D_TH.ome-bin       1316    667     375     48      42      1
45      cell2D_TH.ome-bin       897     861     404     28      44      1
46      cell2D_TH.ome-bin       1340    766     423     52      45      1
47      cell2D_TH.ome-bin       1093    445     430     49      34      1
48      cell2D_TH.ome-bin       1070    329     436     45      36      1
49      cell2D_TH.ome-bin       1021    652     438     49      36      1
50      cell2D_TH.ome-bin       1091    723     482     37      47      1
51      cell2D_TH.ome-bin       1029    370     488     51      28      1
52      cell2D_TH.ome-bin       1029    497     498     33      40      1
53      cell2D_TH.ome-bin       1503    919     500     51      46      1
54      cell2D_TH.ome-bin       978     263     514     47      29      1
55      cell2D_TH.ome-bin       873     453     526     49      24      1
56      cell2D_TH.ome-bin       1005    807     530     38      39      1
57      cell2D_TH.ome-bin       351     1013    545     21      23      1
58      cell2D_TH.ome-bin       340     1029    552     23      21      1
59      cell2D_TH.ome-bin       1370    892     558     47      39      1
60      cell2D_TH.ome-bin       851     287     564     37      31      1
61      cell2D_TH.ome-bin       739     227     568     32      33      1
62      cell2D_TH.ome-bin       681     1053    585     27      35      1
63      cell2D_TH.ome-bin       904     748     597     28      47      1
64      cell2D_TH.ome-bin       1004    819     600     36      39      1
65      cell2D_TH.ome-bin       1175    968     614     43      35      1
66      cell2D_TH.ome-bin       712     1215    645     32      29      1
67      cell2D_TH.ome-bin       802     710     647     27      44      1
68      cell2D_TH.ome-bin       1487    907     652     48      41      1
69      cell2D_TH.ome-bin       441     798     660     28      27      1
70      cell2D_TH.ome-bin       762     1232    668     30      38      1
71      cell2D_TH.ome-bin       939     1020    672     36      37      1
72      cell2D_TH.ome-bin       926     1180    674     37      35      1
73      cell2D_TH.ome-bin       518     820     680     28      29      1
74      cell2D_TH.ome-bin       992     755     682     42      37      1
75      cell2D_TH.ome-bin       966     470     695     28      42      1
76      cell2D_TH.ome-bin       790     548     705     29      39      1
77      cell2D_TH.ome-bin       988     506     720     37      36      1
78      cell2D_TH.ome-bin       461     978     723     21      26      1
79      cell2D_TH.ome-bin       1253    894     725     46      35      1
80      cell2D_TH.ome-bin       494     1000    725     22      25      1
81      cell2D_TH.ome-bin       1059    1182    730     34      49      1
82      cell2D_TH.ome-bin       379     1138    737     26      21      1
83      cell2D_TH.ome-bin       652     1148    748     29      30      1
84      cell2D_TH.ome-bin       1043    527     757     30      45      1
85      cell2D_TH.ome-bin       1016    486     759     33      40      1
86      cell2D_TH.ome-bin       312     1118    798     21      20      1
87      cell2D_TH.ome-bin       191     1104    802     17      15      1
88      cell2D_TH.ome-bin       768     556     807     37      31      1
89      cell2D_TH.ome-bin       876     515     812     32      37      1
90      cell2D_TH.ome-bin       396     1097    817     20      24      1
91      cell2D_TH.ome-bin       878     1116    834     35      36      1
92      cell2D_TH.ome-bin       1102    538     837     44      34      1
93      cell2D_TH.ome-bin       175     1152    846     15      15      1
94      cell2D_TH.ome-bin       860     505     848     32      37      1
95      cell2D_TH.ome-bin       877     1080    853     35      36      1
96      cell2D_TH.ome-bin       1235    13      873     50      32      1
97      cell2D_TH.ome-bin       1201    64      910     40      37      1
98      cell2D_TH.ome-bin       1279    21      929     45      42      1
99      cell2D_TH.ome-bin       1200    873     991     43      37      1
100     cell2D_TH.ome-bin       971     971     1022    41      36      1
101     cell2D_TH.ome-bin       1059    967     1059    38      40      1
[ERROR] Traceback (most recent call last):
  File "C:\Users\m1srh\Documents\Fiji\scripts\test_pa_loca_PAl.py", line 164, in <module>
    pastack, results = AnalyzeTools.analyzeParticles(imp,
  File "C:\Users\m1srh\Documents\Fiji\scripts\fijipytools.py", line 817, in analyzeParticles
    p.analyze(imp, ip)
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at ij.text.TextWindow.<init>(TextWindow.java:53)
        at ij.text.TextWindow.<init>(TextWindow.java:41)
        at ij.measure.ResultsTable.show(ResultsTable.java:978)
        at ij.plugin.filter.ParticleAnalyzer.updateSliceSummary(ParticleAnalyzer.java:675)
        at ij.plugin.filter.ParticleAnalyzer.analyze(ParticleAnalyzer.java:615)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
java.awt.HeadlessException: java.awt.HeadlessException

        at org.python.core.Py.JavaError(Py.java:552)
        at org.python.core.Py.JavaError(Py.java:543)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:515)
        at org.python.core.PyObject.__call__(PyObject.java:519)
        at org.python.core.PyMethod.__call__(PyMethod.java:156)
        at fijipytools$py.analyzeParticles$27(C:/Users/m1srh/Documents/Fiji/scripts/fijipytools.py:821)
        at fijipytools$py.call_function(C:/Users/m1srh/Documents/Fiji/scripts/fijipytools.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyFunction.function___call__(PyFunction.java:471)
        at org.python.core.PyFunction.__call__(PyFunction.java:466)
        at org.python.pycode._pyx0.f$0(C:/Users/m1srh/Documents/Fiji/scripts/test_pa_loca_PAl.py:207)
        at org.python.pycode._pyx0.call_function(C:/Users/m1srh/Documents/Fiji/scripts/test_pa_loca_PAl.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at ij.text.TextWindow.<init>(TextWindow.java:53)
        at ij.text.TextWindow.<init>(TextWindow.java:41)
        at ij.measure.ResultsTable.show(ResultsTable.java:978)
        at ij.plugin.filter.ParticleAnalyzer.updateSliceSummary(ParticleAnalyzer.java:675)
        at ij.plugin.filter.ParticleAnalyzer.analyze(ParticleAnalyzer.java:615)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        ... 30 more

Did it work in the past? With which versions of ImageJ1?

Certainly, the ROI Manager does not work headless:

Hi Curtis,

I am aware that the ROI manager does not work headless, but I do not use it. And I have a docker container (Apeer Module) where my script still works:

czsip/fiji_linux64_baseimage/1.2.2

But what I do to call the function below and set addROIManager=False when I run it headless.

BTW: It does not work on Windows 10 (headless) and it also does not work inside an docker container based on ubuntu.

But when I use the with the conainer from above it does work. If you wnat I can share the APEER module with you, so you can check the working version.

class AnalyzeTools:

    @staticmethod
    def analyzeParticles(imp,
                         minsize,
                         maxsize,
                         mincirc,
                         maxcirc,
                         filename='Test.czi',
                         addROIManager=False,
                         headless=False,
                         exclude=True):

        if addROIManager:

            # get the ROI manager instance
            rm = RoiManager.getInstance()
            if rm is None:
                rm = RoiManager()
            rm.runCommand("Associate", "true")

            if not exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \

            if exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        if not addROIManager:

            if not exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \

            if exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        measurements = PA.STACK_POSITION \
            + PA.LABELS \
            + PA.AREA \
            + PA.RECT \

        results = ResultsTable()
        p = PA(options, measurements, results, minsize, maxsize, mincirc, maxcirc)
        p.setHideOutputImage(True)
        particlestack = ImageStack(imp.getWidth(), imp.getHeight())

        for i in range(imp.getStackSize()):
            imp.setSliceWithoutUpdate(i + 1)
            ip = imp.getProcessor()
            #IJ.run(imp, "Convert to Mask", "")
            p.analyze(imp, ip)
            mmap = p.getOutputImage()
            particlestack.addSlice(mmap.getProcessor())

        return particlestack, results

@sebi06 you didn’t answer @ctrueden’s question yet, which would probably make it much easier to help you:

It would indeed be very helpful to know which version of ij.jar you were using in the different cases.

My suspicion is that this commit by @Wayne breaks your workflow:

In particular, you error message above:

… points at this specific line that was changed in that commit:

- 		summaryTable.show(title);
+ 		if (showSummaryTable)
+			summaryTable.show(title);

I’m however puzzled why this should have worked before and now break in headless mode.

Maybe @Wayne can help?

1 Like

When it was working in found inside the jars folder: ij-1.52n.jar. Does that help?

1 Like

It supports my hypothesis that there’s a bug or regression in ij-1.52p and later.

1 Like

Let me know if you need more info etc. because this issue is quite annoying because it potentially breaks quite a few modules on our APEER platform (if you push new versions), where people use ImageJ or Fiji inside Docker Containers.

This error is caused by a ImageJ 1.52p regression that is fixed in the latest ImageJ daily build (1.52u20). The daily build adds these two lines

  if  (GraphicsEnvironment.isHeadless())
    return; // Tables can't be displayed in headless mode

to the beginning of the ResultsTable.show(String) method. You can work around this regression by not using the particle analyzer’s DISPLAY_SUMMARY option.

3 Likes

Thanks guys for the help.