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? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Eirinn Mackay Research Assistant Bartlett Group L6 Queensland Brain Institute Brisbane, Australia 07 334 66381 |
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 |
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 |
In reply to this post by Wayne Rasband
Thanks Wayne, that code runs at least 100 times faster than using
RoiManager.select on each ROI in turn. 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 |
Free forum by Nabble | Edit this page |