Re: RoiManager multiple selection
Posted by
Wayne Rasband on
Jun 11, 2009; 2:19am
URL: http://imagej.273.s1.nabble.com/RoiManager-multiple-selection-tp3692174p3692175.html
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