Login  Register

Binary granulometry macro

Posted by Li-Ping Yuan on May 03, 2010; 6:38pm
URL: http://imagej.273.s1.nabble.com/Binary-granulometry-macro-tp3688327.html

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