Particale Analyzer ImageJ2 Not giving out results

I am Trying to apply Particle Analysis on my dataset. I am having problem with AnalyzeParticle. It shows out the window
image

and then when I press ok it asks if I want to process the 3 images and when I press yes, I get no results. Actually it is only a tif Image that has green information. It opens a 3 channel image “RGB” having only information on the green channel while blank on the red and blue

Why I am seeing no results?

Below is my code,

// ImageJ2 Instance
imageJ = new ImageJ();

// Loading Image
dataset = imageJ.scifio().datasetIO().open(selectedFile.getPath());
setDataset(dataset);

// Creating services for Binary Conversion
Context context = imageJ.getContext();
CommandService commandService = context.getService(CommandService.class);
Future<CommandModule> future = commandService.run(Binarize.class, true, "inputData", dataset);

try {
       //Converting the image to Binary
       Dataset binarized = (Dataset) future.get().getOutput("outputMask");

      // Converting from ImageJ2 ImgPlus() to ImageJ1 ImagePlus()
      image = binarized.getImgPlus().getImg();
      ImagePlus imagePlus = ImageJFunctions.wrap(image,"Binary Image");

      // Counting 
      ParticleAnalyzer particleAnalyzer = new ParticleAnalyzer();
      particleAnalyzer.setup("Output",imagePlus);
      particleAnalyzer.setHideOutputImage(false);
      particleAnalyzer.analyze(imagePlus);

      } catch (InterruptedException | ExecutionException e) {
              e.printStackTrace();
        }

Edit: Now I get part of the problem
It is because when I upload the image as RGB while it actually has only information on the green channel, what happens is that ParticalAnalyzer, analyse only the first image and give its results. So I started to see output once I did this

ParticleAnalyzer particleAnalyzer = new ParticleAnalyzer(ParticleAnalyzer.INCLUDE_HOLES+ParticleAnalyzer.SHOW_OUTLINES, 0, null, 0, Double.MAX_VALUE, 0, 1);
imagePlus.setC(2); // Making the active channel infront to be the green one with information
particleAnalyzer.analyze(imagePlus);
particleAnalyzer.getOutputImage().show();

Now the questions would be,

  1. Why ParticleAnalyzer doesn’t analyse the 3 channels separatley?
  2. Is there a better way to tell ImageJ, please detect that it is only a green channel automatically?
  3. Why I only see output results as an image as shown below. Where are the results and the window of objects?

Hey @Mourka,

the particle analyser has a pulldown Show where you can select what it should output after separating objects. In your screenshot above, you selected “Nothing” and that’s why no image window opened. Furthermore, there are some checkboxes allowing you to open a table with results (“Display Results”).
Please refer to the user guide to learn what you can show with the particle analyser:
https://imagej.nih.gov/ij/docs/guide/146-30.html

Furthermore, if you want to only process a single channel image, I recommend duplicating this channel first.

Regarding programming the ParticleAnalyser (I’m not an expert on this one), the best resource to look at might be its API: https://imagej.nih.gov/ij/developer/api/ij/plugin/filter/ParticleAnalyzer.html

I hope that helps.

Cheers,
Robert

1 Like

it helped as now I have a ROI window but still trying to figure out the results table window. I chose a ParticleAnalyzer.SHOW_RESULTS option but I only see it printed in the console.

The particle analyser has a method which takes a table. Could you please try handing over a ResultsTable and show() it after the processing?

1 Like

I did this,

RoiManager roi = new RoiManager()
ResultsTable rt = new ResultsTable();

ParticleAnalyzer particleAnalyzer = new ParticleAnalyzer(
       ParticleAnalyzer.INCLUDE_HOLES+
       ParticleAnalyzer.SHOW_RESULTS
       , 0, null, 1, Double.MAX_VALUE, 0, 1);

ParticleAnalyzer.setRoiManager(roi);
ParticleAnalyzer.setResultsTable(rt);
rt.show("Results");

I also did this

RoiManager roi = new RoiManager()
ResultsTable rt = new ResultsTable();

ParticleAnalyzer particleAnalyzer = new ParticleAnalyzer(
       ParticleAnalyzer.INCLUDE_HOLES+
       ParticleAnalyzer.SHOW_RESULTS
       , 0, rt, 1, Double.MAX_VALUE, 0, 1);

ParticleAnalyzer.setRoiManager(roi);
rt.show("Results");

because of SHOW_RESULTS option the results are printed on the console but no windows appear. The ROI Show up and present the objects normally.

Now I can say that the table appeared once I showed ImageJ API which is something that I want to avoid. Is there any way that I can collect what was written on the console and create my own table from it?

Could you set the table before calling analyse and afterwards show it?

Furthermore, please use the object particleAnalyser in your code when setting the table and not the ParticleAnalyser class. :wink:

1 Like
ResultsTable rt = new ResultsTable();
RoiManager roi = new RoiManager();
ParticleAnalyzer particleAnalyzer = null;
particleAnalyzer.setResultsTable(rt);
particleAnalyzer.setRoiManager(roi);

particleAnalyzer = new ParticleAnalyzer(
       ParticleAnalyzer.INCLUDE_HOLES+
       ParticleAnalyzer.SHOW_RESULTS
       , 0, rt, 1, Double.MAX_VALUE, 0, 1);
       
imagePlusfiltered.setC(2);
particleAnalyzer.analyze(imagePlusfiltered);
rt.show("Results");

It gives the same results while by adding these two lines before the code to show imageJ1. It does appear.

ij.ImageJ imgJ =  new ij.ImageJ();
imgJ.show(true);