Login  Register

Re: RoiManager multiple selection

Posted by Eirinn Mackay on Jun 11, 2009; 4:12am
URL: http://imagej.273.s1.nabble.com/RoiManager-multiple-selection-tp3692174p3692177.html

Thanks for the quick response Wayne. Will this code work with stacks  
or will I need extra code to ensure each ROI is drawn on its  
designated slice?
Cheers,
Eirinn
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Eirinn Mackay
Research Assistant
Bartlett Group L6
Queensland Brain Institute
Brisbane, Australia
07 334 66381




On 11/06/2009, at 12:19 PM, Rasband Wayne wrote:

> On Jun 10, 2009, at 7:49 PM, Eirinn Mackay wrote:
>
>> Hi all,
>> Is it possible to select multiple ROIs programmatically? I'd like  
>> to select all that match a certain characteristic, draw them to the  
>> image with one foreground color, then select other ROIs and draw  
>> them with a different foreground color.
>> I am writing a python script so I'm using the API, but I can always  
>> call a macro command if necessary.
>>
>> The API describes a function - select(int index, boolean  
>> shiftKeyDown, boolean altKeyDown) - but those boolean arguments  
>> don't appear to work. If either of them are true, nothing can be  
>> selected.
>> I've tried selecting each ROI in turn and drawing it, but this is  
>> prohibitively slow.
>>
>> Any ideas?
>
> Use the getRoisAsArray() method to get all the ROIs and then use the  
> drawPixels() method to draw selected ROIs in the array. Here is a  
> JavaScript example that draws half the ROIs in the ROI Manager in  
> red and the other half in blue.
>
>   manager = RoiManager.getInstance();
>   if (manager==null)
>      IJ.error("ROI Manager is not open");
>   rois = manager.getRoisAsArray();
>   img = IJ.getImage();
>   ip = img.getProcessor();
>   for (i=0; i<rois.length; i++) {
>      if (i<rois.length/2)
>          ip.setColor(Color.red);
>      else
>          ip.setColor(Color.blue);
>      rois[i].drawPixels(ip);
>   }
>   img.updateAndDraw();
>
> -wayne