RoiManager "Combine"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

RoiManager "Combine"

Ben.BigHair
Hello,

I am having difficulty understanding the "Combine" operation for the
RoiManager.  Here is an example...

(1) run the "RoiManagerAddParticles.txt" example macro availbale at

http://rsb.info.nih.gov/ij/macros/RoiManagerAddParticles.txt


(2) select the first and second ROIs by shift-clicking on...

        0005-0063
        0014-0108

(3) press the "Combine" button (both ROIs are highlighted)

(4) then press the "Measure" button

At this point two measurements are added - identical to the originals.
I expected a single measurement.  Is there a way to have ImageJ treat
the two as a single ROI?

Thanks and cheers,
Ben
Reply | Threaded
Open this post in threaded view
|

Re: RoiManager "Combine"

Wayne Rasband
> Hello,
>
> I am having difficulty understanding the "Combine" operation for the
> RoiManager.  Here is an example...
>
> (1) run the "RoiManagerAddParticles.txt" example macro availbale at
>
> http://rsb.info.nih.gov/ij/macros/RoiManagerAddParticles.txt
>
>
> (2) select the first and second ROIs by shift-clicking on...
>
> 0005-0063
> 0014-0108
>
> (3) press the "Combine" button (both ROIs are highlighted)
>
> (4) then press the "Measure" button
>
> At this point two measurements are added - identical to the originals.
> I expected a single measurement.  Is there a way to have ImageJ treat
> the two as a single ROI?

Press the "m" key (Analyze>Measure) and ImageJ will treat the two as a
single ROI. Or add the combined ROI to the ROI Manager, select it and
press the "Measure" button.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: RoiManager "Combine"

Ben.BigHair
Wayne Rasband wrote:

>> Hello,
>>
>> I am having difficulty understanding the "Combine" operation for the
>> RoiManager.  Here is an example...
>>
>> (1) run the "RoiManagerAddParticles.txt" example macro availbale at
>>
>> http://rsb.info.nih.gov/ij/macros/RoiManagerAddParticles.txt
>>
>>
>> (2) select the first and second ROIs by shift-clicking on...
>>
>>     0005-0063
>>     0014-0108
>>
>> (3) press the "Combine" button (both ROIs are highlighted)
>>
>> (4) then press the "Measure" button
>>
>> At this point two measurements are added - identical to the originals.
>> I expected a single measurement.  Is there a way to have ImageJ treat
>> the two as a single ROI?
>
> Press the "m" key (Analyze>Measure) and ImageJ will treat the two as a
> single ROI. Or add the combined ROI to the ROI Manager, select it and
> press the "Measure" button.
>

Ah!  Thanks.  I folled myself into thinking that "Combine" would replace
the two automatically and "Add" - but that would be too destructive.

Within a macro I can get the two to combine and be added, I can delete
the original two, but when I select the last element to measure it
selects all of the ROIs.  This is different than if I manually combine
add and measure the two.

Here is the example I am using...

// RoiManagerAddParticles2
// This macro demonstrates how to add particle analyzer
// outlines to the ROI Manager. Note that doWand() may
// not work reliably unless the objects being traced
// have been highlighted in red using setThreshold().
//Nothing clear record
   requires("1.33f");
   run("Blobs (25K)");
   setThreshold(125, 248);
   run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 show
=Nothing display clear record");
   for (i=0; i<nResults; i++) {
       x = getResult('XStart', i);
       y = getResult('YStart', i);
       doWand(x,y);
       roiManager("add");
   }


run("Record...");

print("Count after Analyze: " + roiManager("Count"));

// select 1 and 2 to combine - add them as a new ROI

roiManager("Deselect");
roiManager("Select", 1);
roiManager("Select", 2);
roiManager("Combine");
roiManager("Add");
print("Count after Combine and Add: " + roiManager("Count"));

// now remove 1 and 2  (in reverse order)

roiManager("Deselect");
roiManager("Select", 2);
roiManager("delete");
print("Count after first deletion: " + roiManager("Count"));
roiManager("Select",1);
roiManager("delete");
print("Count after first deletion: " + roiManager("Count"));

// finally, select the last element and measure that

roiManager("Deselect");
n = roiManager("count");
print("Count at end: " + n);
lastIndex = n-1;
print("Index to select and measure: " + lastIndex);
roiManager("Select",lastIndex);
run("Measure");
Reply | Threaded
Open this post in threaded view
|

Re: RoiManager "Combine"

Wayne Rasband
The roiManager("select", index) function selects one ROI at a time. As
a workaround, use setKeyDown("shift") to combine the ROIs:

   // combine the first two ROIs and measure
   requires("1.37i");
   roiManager("select", 0);
   setKeyDown("shift");
   roiManager("select", 1);
   setKeyDown("none");
   run("Measure");

Note that there is a bug in the ROI Manager "Combine" function that
causes it to combine all the ROIs when only one is selection. This is
fixed in ImageJ 1.37m.

-wayne


> Ah!  Thanks.  I folled myself into thinking that "Combine" would
> replace the two automatically and "Add" - but that would be too
> destructive.
>
> Within a macro I can get the two to combine and be added, I can delete
> the original two, but when I select the last element to measure it
> selects all of the ROIs.  This is different than if I manually combine
> add and measure the two.
>
> Here is the example I am using...
>
> // RoiManagerAddParticles2
> // This macro demonstrates how to add particle analyzer
> // outlines to the ROI Manager. Note that doWand() may
> // not work reliably unless the objects being traced
> // have been highlighted in red using setThreshold().
> //Nothing clear record
>   requires("1.33f");
>   run("Blobs (25K)");
>   setThreshold(125, 248);
>   run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 show
> =Nothing display clear record");
>   for (i=0; i<nResults; i++) {
>       x = getResult('XStart', i);
>       y = getResult('YStart', i);
>       doWand(x,y);
>       roiManager("add");
>   }
>
>
> run("Record...");
>
> print("Count after Analyze: " + roiManager("Count"));
>
> // select 1 and 2 to combine - add them as a new ROI
>
> roiManager("Deselect");
> roiManager("Select", 1);
> roiManager("Select", 2);
> roiManager("Combine");
> roiManager("Add");
> print("Count after Combine and Add: " + roiManager("Count"));
>
> // now remove 1 and 2  (in reverse order)
>
> roiManager("Deselect");
> roiManager("Select", 2);
> roiManager("delete");
> print("Count after first deletion: " + roiManager("Count"));
> roiManager("Select",1);
> roiManager("delete");
> print("Count after first deletion: " + roiManager("Count"));
>
> // finally, select the last element and measure that
>
> roiManager("Deselect");
> n = roiManager("count");
> print("Count at end: " + n);
> lastIndex = n-1;
> print("Index to select and measure: " + lastIndex);
> roiManager("Select",lastIndex);
> run("Measure");
>
Reply | Threaded
Open this post in threaded view
|

Re: RoiManager "Combine"

Ben.BigHair
Wayne Rasband wrote:

> The roiManager("select", index) function selects one ROI at a time. As a
> workaround, use setKeyDown("shift") to combine the ROIs:
>
>   // combine the first two ROIs and measure
>   requires("1.37i");
>   roiManager("select", 0);
>   setKeyDown("shift");
>   roiManager("select", 1);
>   setKeyDown("none");
>   run("Measure");
>
> Note that there is a bug in the ROI Manager "Combine" function that
> causes it to combine all the ROIs when only one is selection. This is
> fixed in ImageJ 1.37m.


OK! and Thanks!

Ben
Reply | Threaded
Open this post in threaded view
|

Re: RoiManager "Combine"

Ben.BigHair
In reply to this post by Wayne Rasband
Wayne Rasband wrote:

> The roiManager("select", index) function selects one ROI at a time. As a
> workaround, use setKeyDown("shift") to combine the ROIs:
>
>   // combine the first two ROIs and measure
>   requires("1.37i");
>   roiManager("select", 0);
>   setKeyDown("shift");
>   roiManager("select", 1);
>   setKeyDown("none");
>   run("Measure");
>
> Note that there is a bug in the ROI Manager "Combine" function that
> causes it to combine all the ROIs when only one is selection. This is
> fixed in ImageJ 1.37m.

Hello again,

I used the above quite successfully to combine ROIs ... until now.  I am
using ImageJ 1.37p on Max OSX.  The setDownKey("shift") doesn't appear
to work as only the last selected ROI is selected.

I have appended the macro I adapted from the example macro
"RoiManagerAddParticles.txt"   Here is the relevant loop where I use the
setKeyDown("shift") command. This doesn't appear to select all of the
ROIs - but see that "blobs.gif" shows all of the outlines.  Anyway, a
call to roiManager("combine") causes an error with the message "More
than one item must be selected, or none."

   roiManager("select",0);      
   for (i=1; i<roiManager("count"); i++){
    setKeyDown("shift");
            roiManager("select", i);
            setKeyDown("none");
   }



I have also tried it with the setKeyDown() calls are on the outside of
the loop, as shown below, but with similar results, *except* that in
"blobs.gif" only the last item is outlined.

     //select all of the Rois
   roiManager("select",0);      
   setKeyDown("shift");
   for (i=1; i<roiManager("count"); i++){
                roiManager("select", i);
   }
   setKeyDown("none");


Could this be a bug in the setKeyDown() or roiManager("combine")
commands?  Or do I have something out of proper sequence?

Thanks!
BEn


****BEGIN

// ImageJ Macro
// RoiManagerAddParticles
// This macro demonstrates how to add particle analyzer
// outlines to the ROI Manager. Note that doWand() may
// not work reliably unless the objects being traced
// have been highlighted in red using setThreshold().
//Nothing clear record
   requires("1.33f");
   run("Blobs (25K)");
   setThreshold(125, 248);
   roiManager("reset");
   run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 show
=Nothing display clear record");
   for (i=0; i<nResults; i++) {
       x = getResult('XStart', i);
       y = getResult('YStart', i);
       doWand(x,y);
       roiManager("add");
   }

   //select all of the Rois
   roiManager("select",0);      
   for (i=1; i<roiManager("count"); i++){
    setKeyDown("shift");
            roiManager("select", i);
            setKeyDown("none");
   }
   showMessage("All should be selected in ROI Manager now - but they
aren't (except in 'blobs.gif'!)");
   //  roiManager("combine");
  //  roiManager("add");

   roiManager("deselect");
     //select all of the Rois
   roiManager("select",0);      
   setKeyDown("shift");
   for (i=1; i<roiManager("count"); i++){
            roiManager("select", i);
   }
   setKeyDown("none");
   showMessage("All should be selected in ROI Manager now - but they
aren't (even in 'blobs.gif'!)");
   //  roiManager("combine");
   //  roiManager("add");




****END