Get the Values of Distribution

Hi there

I am trying to use the function “Distribution” in a macro to guess best values to be used in Analyze particles.
So the first step consists in running Analyze particles with no values:

run("Analyze Particles...", "display clear");

Then from the results generated I use the following command to obtain the distribution:
run("Distribution...", "parameter=Area automatic");

Then I would like to obtain the values of the distribution which appear only when I click LIST. My walk around is to use WaitForUser but it is not ideal because it requires a click:

waitForUser("Please Click the LIST button."
+"\n Then Click OK");

Then I use:

SelectWindow("Area Distribution");

To get the content of the distribution values.
So my question is: Is there a way to call the “List” directly within the macro without having to click?
Thank you all in advance

I didn’t find a function. But as a workaround you can use the Robot plugin to simulate a mouse click on the window and you can create a macro command from it for the automatization (use the macro recorder):

Eventually set the location of the “Area Distribution” window before you calculate the mouse position of the required action, see:

setLocation(x, y);
getLocationAndSize(x, y, width, height);

with the distribution plot as the active window, you can get the bin starts and counts using:

Plot.getValues(bins, counts);
Array.print (bins);
Array.print (counts);



Thank you for your reply.
That’s a really smart way to overcome the issue.
I liked it and I will keep it in mind.

Hi Jerome

Thank you very much for your reply. Your method is more direct and I have used it successfully.

It solved my problem !

Here is the code that runs twice analyze particles:
1- With 0 and infinity area values to get the distribution of the particles area
2- With the best guess area values determined by step 1

Thank you all.

run("Analyze Particles...", "display clear");
run("Distribution...", "parameter=Area automatic");
selectWindow("Area Distribution");
Plot.getValues(BinArray, CountArray);

selectWindow("Area Distribution");

  run("Clear Results");

Array.getStatistics(BinArray, MinBin, MaxBin, MeanBin, StdDevBin);
Array.getStatistics(CountArray, MinCount, MaxCount, MeanCount, StdDevCount);

// Then I create a new array named Particle Size that includes only the Bin with a count higher than the meanCount
for (Rown=0; Rown<CountArray.length; Rown++){
  if(Count > MeanCount){
Array.getStatistics(ParticleSizeArray, MinParticleSize, MaxParticleSize, MeanParticleSize, StdDevParticleSize);
// These are the values I was looking for MinParticleSize MaxParticleSize

// Now I can run the particle again but with the "best guess" values from the first analyze particle above
run("Analyze Particles...", "size=&MinParticleSize-&MaxParticleSize show=Overlay clear summarize");

This doesn’t seem to work in batch mode. When I use setBatchMode(true); in a macro, I get the error: No plot or histogram window in line XX: Plot . getValues ( bins , counts <)> ;
Is there any possibility to get the values from the Distribution plot while in batch mode?