> On Mar 22, 2024, at 7:55 AM, Gabriel Landini <[email protected]> wrote:
> 
> Hello,
> Using the doWand to remove binary regions is quite slow compared to the 
> floodfill method (floodfill is approx 74 times faster in normal macro mode 
> and approx 260 faster (!) in batch mode in the example below).
> 
> But more importantly, I just noted that the doWand method fails to remove all 
> regions from the image.

Hi Gabriel,

Here is a version of your macro that is fast and removes all regions. It uses 
an overlay and the fill() macro function, which is much faster than 
run(“Clear”).

 setBatchMode(true);
 newImage("Untitled", "8-bit black", 2048, 2048, 1);
 run("Add Noise");
 setThreshold(0, 5);
 setOption("BlackBackground", true);
 run("Convert to Mask");
 run("Analyze Particles...", "clear overlay ");
 t0=getTime();
 Color.setForeground("black");
 sumOfAreas = 0;
 for (i=0; i<nResults; i++) {
      Overlay.activateSelection(i);
      sumOfAreas += getResult("Area", i);
      fill;
 }
 Roi.remove;
 print ("Time: "+getTime()-t0+" ms.");
 print ("Number of particles: "+nResults);
 print ("Average size: "+sumOfAreas/nResults);
 getStatistics(area, mean, min, max);
 if (mean!=0)
    print("Error: not all regions cleared”);

-wayne

> Running the macro below you find many remaining regions close the the top and 
> right borders on the result image 1.
> I suspect that the wand is missing some 8-connected pixels that form part of 
> the boundary of regions touching at the image borders.
> 
> 
> - - - - -
> newImage("Untitled", "8-bit black", 2048, 2048, 1);
> run("Add Noise");
> setThreshold(0, 5);
> setOption("BlackBackground", true);
> run("Convert to Mask");
> run("Duplicate...", "title=1");
> run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 show=Nothing 
> clear record");
> selectImage("1");
> t0=getTime();
> for (i=0; i<nResults; i++) {
>   x = getResult('XStart', i);
>   y = getResult('YStart', i);
>       doWand(x,y);
>       run("Clear");
> }
> print ("Wand: "+getTime()-t0+" ms.");
> 
> 
> selectImage("Untitled");
> run("Duplicate...", "title=2");
> setColor(0);
> selectImage("2");
> 
> t0=getTime();
> for (i=0; i<nResults; i++) {
>   x = getResult('XStart', i);
>   y = getResult('YStart', i);
>   floodFill(x, y, "8-connected");
> }
> print ("Floodfill: "+getTime()-t0+" ms.");
> 
> - - - - -
> 
> Regards
> 
> Gabriel
> 
> 
> 
> 
>> On 22/03/2024 00:43, Wayne Rasband wrote:
>> The “Record starts” checkbox has been replaced by “Overlay” but macros that 
>> use the ‘record’ keyword continue to work.
>> Here is an updated version of the CircularParticles macro linked to in the 
>> ImageJ User Guide that uses ‘overlay’ instead of ‘record’:
>> // This macro demonstrates how to erase non-circular objects
>> run("Blobs (25K)");
>> setThreshold(125, 248);
>> run("Set Measurements...", "area perimeter circularity decimal=3");
>> run("Analyze Particles...", "clear overlay");
>> for (i=0; i<nResults; i++) {
>>    circularity = getResult('Circ.', i);
>>    if (circularity<0.85) {
>>        Overlay.activateSelection(i);
>>        run("Clear");
>>    }
>> }
>> run("Select None");
>> exit;
>> // Original version that uses "Record starts"
>> run("Select None");
>> requires("1.29n");
>> run("Blobs (25K)");
>> setThreshold(125, 248);
>> run("Set Measurements...", "area perimeter circularity decimal=3");
>> run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 show=Nothing 
>> clear record");
>> for (i=0; i<nResults; i++) {
>>    x = getResult('XStart', i);
>>    y = getResult('YStart', i);
>>    circularity = getResult('Circ.', i);
>>    if (circularity<0.85) {
>>        doWand(x,y);
>>        run("Clear");
>>    }
>> }
>> run("Select None");

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Reply via email to