Login  Register

Re: Binary granulometry macro

Posted by Michael Schmid on May 04, 2010; 9:55am
URL: http://imagej.273.s1.nabble.com/Binary-granulometry-macro-tp3688327p3688332.html

Hi Li,

not an attempt to answer your questions, but an alternative way of  
doing something similar:

It seems that you want to have statistics on the particles. Assuming  
that 'erode' would be circular symmetric (it is not) your macro would  
give statistics on the maximum distance from the center. This is  
similar to, but not equal to 0.5*MinFeret width.
Feret (caliper length): you can get it directly from 'Analyze  
particles' with suitable 'set measurements'.
If you are not satisfied with Feret width, you can still do it with  
'Analyze Particles':

Run Process>Binary>Distance Map on your binary image, threshold at  
1-255, then run the particle analyzer. You can then use  
'Distribution' to get a histogram of the maxima, i.e., the maximum  
distance from the center.
Your macro would give the statistics in a different way: larger  
particles would get a larger weight. If you want this, you have to  
multiply the 'max' and 'area' columns of the particle analyzer  
results and do the histogram from this.


A few more remarks on your code:

- When using binary operations like 'erode' in a macro, always set  
the binary options first, otherwise you might get an undesired  
results. By setting the options, you could also do several iterations  
at once, no need for the 'j' loop.

- getImageStatistics or getRawStatistics give you min&max, it would  
tell you when everything is eroded.

- Histogram is limited to the current selection, so you can easily  
threshold your image at some level (e.g. 1-255) and then 'create  
selection'.


Michael
________________________________________________________________

On 3 May 2010, at 20:38, Li-Ping Yuan wrote:

> I just wrote my first macro to calclate binary granulometry.
> Hi All,
>
> I just wrote my first macro to calclate binary granulometry.  It  
> worked but still need your kind help.
>
> The code is:
>
> run("Blobs (25K)");
> run("Make Binary");    //  select object areas/pisels
> run("Duplicate...", "title=erode.gif");    // for keeping  
> sequentially eroded images
> run("Duplicate...", "title=size-map.gif");     //  for the result  
> size map.
> run("Divide...", "value=255");   //  initialize all selected pixels  
> with value 1 in size-map.
> for (i=1;i<12;i++) {
>    selectWindow("erode.gif");
>    run("Erode");
>    run("Duplicate...", "title=dilate.gif");  //  for each eroded  
> image, dilate all the way back.
>    for (j=0;j<i;j++) {
>       run("Dilate");
> }
>    run("Divide...", "value=255");   //  for all survived pixels,  
> add one to the size map.
>    run("Image Calculator...", "image1=size-map.gif operation=Add  
> image2=dilate.gif ");
>    selectWindow("dilate.gif");
>    close();
> }
> selectWindow("erode.gif");
> close();
> selectWindow("size-map.gif");
> run("Enhance Contrast", "saturated=0.5");   //  to see the result.
> run("Histogram");   //   to get mean, std, and etc.  But how can I  
> exclude background pixels?
>
> Problems:
> 1. What's the best way to detect an images when all seleceted  
> areas are eroded away?  I tried and error with this image to set  
> the loop with 12 erosions.  It will be nice to detect that  
> automatically and stop the loop.
> 2. The histogram at the end calculates mean and std including  
> background pixel (value=0).  Is there a way to calculate with only  
> selected pixels (value > 0)?
> 3. Erosion and dilation are pretty fast, the adding (image  
> calculator) is very slow.  (I turned on the macro recorder to see  
> the progress)  Is there a good way to speed up?  write in Java?
> 4. Any other software available for binary granulometry?   Matlab?  
> ImagePro?
> 5. Any other coments are welcome.
> Thanks in advance for your comments/answers.
>  Li-Ping (Li) Yuan
>