[SOLVED] Save Summary in headlessmode

Dear,

I would convert a macro to run it in headless mode.
This macro run several times “Analyze Particles”. All is ok, except at the end when macro should save Summary window of “Analyze Particles” into a csv file with this line:

selectWindow("Summary");
saveAs("Text", dir2 + titleResult);

Of course there is no Summary Window as resuts of Analyze Particules are displayed in terminal, so I have this message in terminal:
No window with the tittle "Summary" found

So my question: How can I get result from this “window” in headless mode?

Thanks a lot

Hi,

if you don’t mind using to Jython then you might use this script or parts of it. I use in headless mode when running Fiji scripts inside docker containers.

class AnalyzeTools:

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

        if addROIManager is 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

    @staticmethod
    def create_resultfilename(filename, suffix='_Results', extension='txt'):

        # create the name for the result file
        rtfilename = os.path.splitext(filename)[0] + suffix + '.' + extension

        return rtfilename

This one can be later used to do this:

...

rtscavelocation = r'c:/temp'

# save the results
results.saveAs(rtsavelocation)

...

Hi
Thank you sebi06 for your proposition. I didn’t know at all jython. I try to study this proposition, but it was too “hard” for me.
Finally I use “nResults” which return the count result of Analyze Particles in headless mode, and another software for others results.

You can get and save the particle analyzer’s Summary table in headless mode using a script. You will need to upgrade to the latest daily build (1.52p57), which adds the ParticleAnalyzer.setSummaryTable() method. Here is a JavaScript example:

  img1 = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
  IJ.setAutoThreshold(img1, "Default");
  IJ.run("Set Measurements...", "area mean redirect=None decimal=3");
  rt = new ResultsTable();
  ParticleAnalyzer.setSummaryTable(rt);
  IJ.run(img1, "Analyze Particles...", "summarize");
  img2 = IJ.openImage("http://wsr.imagej.net/images/Dot_Blot.jpg");
  IJ.setAutoThreshold(img2, "Default");
  ParticleAnalyzer.setSummaryTable(rt);
  IJ.run(img2, "Analyze Particles...", "summarize");
  IJ.log("rt: "+rt);
  rt.save(IJ.getDir("temp")+"summary.csv");
  //rt.show("Summary");

Thank you Wayne for this tip. Exactlly wat I needed!