Particle Analyser for stack with Java

I am trying to use Practicle Analyser on a stack of images to give me the measurement table for a stack. I have searched for related posts online and I only found examples in jython.

I am using ImageJ2 “ImgPlus” and in order to use Praticle Analyser I had to convert my image to ImageJ1 “ImagePlus” then I applied filtering and thresholding on the result and lastly I am running a Particle Analyser on the output of type ImagePlus.
As it is explained in Jython in previous post

RoiManager roi = new RoiManager();
rt = new ResultsTable();
        
ParticleAnalyzer particleAnalyzer = new ParticleAnalyzer(ParticleAnalyzer.INCLUDE_HOLES +
                 ParticleAnalyzer.STACK_POSITION
                , -1, rt, 1, Double.MAX_VALUE, 0, 1);

particleAnalyzer.setRoiManager(roi);
particleAnalyzer.setResultsTable(rt);
imagePlusfiltered.setC(2);

ImagePlus analysedImage;
ImageStack stk = new ImageStack();
for (int imgSliceindx=0 ; imgSliceindx < imagePlusfiltered.getStackSize() ; imgSliceindx++) {
       imagePlusfiltered.setSliceWithoutUpdate(imgSliceindx+1);
       particleAnalyzer.analyze(imagePlusfiltered);
       analysedImage = particleAnalyzer.getOutputImage();
       stk.addSlice(analysedImage.getProcessor());
       particleAnalyzer.setRoiManager(roi);
       particleAnalyzer.setResultsTable(rt);
}

Still what I am getting is the analysis of the first slice only, the same result as doing this,
particleAnalyzer.analyze(imagePlusfiltered);

also trying this solution as shown in this post still gave the same result
particleAnalyzer.analyze(imagePlusfiltered, imagePlusfiltered.getProcessor());

Any Ideas where I should look?

These two lines were giving exception once I commented them I am having the sum of the counting in the ROI even when the ROI and ImageJ API are hidden.

analysedImage = particleAnalyzer.getOutputImage();
stk.addSlice(analysedImage.getProcessor());
1 Like