ParticleAnalyzer questions

Hi all,

I’m trying to script the particle analyzer and wanted to use the ParticleAnalyzer API to do so but I’m having some questions with it. I’ll first ask the questions and then paste the codes corresponding

  • Using code 1, why am I still getting all objects in the ResultsTable and not only the Summary ?
  • Using code 2, same issue, I’m still getting individual measurements
  • Using code 2, why does the redirect only work if the ImagePlus is visible ?
  • Using both code, I’m getting an extra line where the value in the column slice is DUP_blobs.gif which I guess is the summary ?

Code 1:

# ─── SCRIPT PARAMETERS ──────────────────────────────────────────────────────────

#@ Double(label="Minimum size for mitochondria detection", value=0.3) min_size_mito
#@ Double(label="Minimum circularity for mitochondria detection", value=0.2) min_circ_mito
#@ RoiManager rm
#@ ResultsTable rt

# ─── IMPORTS ────────────────────────────────────────────────────────────────────

import os
import csv
import glob
import sys
from itertools import izip

from java.lang import Double

# from java.awt import Color

from ij import IJ, ImagePlus, ImageStack, Prefs, WindowManager as wm
from ij.measure import Measurements as MEAS
from ij.plugin import Duplicator, ImageCalculator
from ij.plugin.frame import RoiManager
from ij.plugin.filter import Analyzer, ParticleAnalyzer as PA
from ij.gui import WaitForUserDialog, Roi, PointRoi
from ij.measure import ResultsTable

# Create the ParticleAnalyzer
options = PA.SHOW_RESULTS + PA.DISPLAY_SUMMARY
measurements = PA.FERET + PA.SHAPE_DESCRIPTORS + PA.INTEGRATED_DENSITY
particle_analyzer = PA(options, measurements, rt, min_size_mito, Double.POSITIVE_INFINITY, min_circ_mito, Double.POSITIVE_INFINITY)
PA.setSummaryTable(rt)

imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif")
imp_dup = Duplicator().run(imp, 1, 1, 1, imp.getNSlices(), 1, 1)

IJ.setAutoThreshold(imp_dup, "Otsu")
Prefs.blackBackground = True
IJ.run(imp_dup, "Convert to Mask", "")


Analyzer.setRedirectImage(imp)
particle_analyzer.analyze(imp_dup)
rt.show("Results")

Code 2:

# ─── SCRIPT PARAMETERS ──────────────────────────────────────────────────────────

#@ Double(label="Minimum size for mitochondria detection", value=0.3) min_size_mito
#@ Double(label="Minimum circularity for mitochondria detection", value=0.2) min_circ_mito
#@ RoiManager rm
#@ ResultsTable rt

# ─── IMPORTS ────────────────────────────────────────────────────────────────────

import os
import csv
import glob
import sys
from itertools import izip

from java.lang import Double

# from java.awt import Color

from ij import IJ, ImagePlus, ImageStack, Prefs, WindowManager as wm
from ij.measure import Measurements as MEAS
from ij.plugin import Duplicator, ImageCalculator
from ij.plugin.frame import RoiManager
from ij.plugin.filter import Analyzer, ParticleAnalyzer as PA
from ij.gui import WaitForUserDialog, Roi, PointRoi
from ij.measure import ResultsTable

# Create the ParticleAnalyzer
options = PA.SHOW_RESULTS + PA.DISPLAY_SUMMARY
measurements = PA.FERET + PA.SHAPE_DESCRIPTORS + PA.INTEGRATED_DENSITY
particle_analyzer = PA(options, measurements, rt, min_size_mito, Double.POSITIVE_INFINITY, min_circ_mito, Double.POSITIVE_INFINITY)
PA.setSummaryTable(rt)

imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif")
imp_dup = Duplicator().run(imp, 1, 1, 1, imp.getNSlices(), 1, 1)

IJ.setAutoThreshold(imp_dup, "Otsu")
Prefs.blackBackground = True
IJ.run(imp_dup, "Convert to Mask", "")


# Analyzer.setRedirectImage(imp)
# particle_analyzer.analyze(imp_dup)
# Seems to be necessary
imp.show()

PA.setSummaryTable(rt)
IJ.run("Set Measurements...", "shape feret's integrated redirect=[" + imp.getTitle() + "]  decimal=3")
IJ.run(imp_dup, "Analyze Particles...", "size=" + str(min_size_mito) + "-Infinity circularity=" + str(min_circ_mito) + "-1.00 summarize")

rt.show("Results")
1 Like

Hi all,

I tried again with different settings but I’m still stuck with the Analyze Particles part of my script ?

Any help would be welcome.

Thanks !