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");
AreaDistributionContent=getInfo("window.contents");

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:

http://imagej.1557.x6.nabble.com/set-location-of-ImageJ-window-at-launch-by-macro-td3683089.html

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

Hi,
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);

Sincerely,
Jerome

3 Likes

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("Close");

if(isOpen("Results")){
  run("Clear Results");
  selectWindow("Results");
  run("Close");
}

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

MeanCount=round(MeanCount);
// Then I create a new array named Particle Size that includes only the Bin with a count higher than the meanCount
ParticleSize="";
for (Rown=0; Rown<CountArray.length; Rown++){
  Count=round(CountArray[Rown]);
  if(Count > MeanCount){
    ParticleSize=ParticleSize+round(BinArray[Rown])+"\n";
  }
}
ParticleSizeArray=split(ParticleSize,"\n");
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");
3 Likes

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?