How to implement multiple elliptical selections in ImageJ API?

plugin
selection
Tags: #<Tag:0x00007fb87b8bd568> #<Tag:0x00007fb87b8bd338>

#1

I was wondering how to draw multiple elliptical selections using the ImageJ API. I know that you can do this using the setKeyDown(“shift”) command in the macro language, so I was wondering what the equivalent was in the ImageJ API.

Thank you for your help,
Ben Smith


#2

You can use e.g. the ROI Manager to create composite selections, see:

https://imagej.nih.gov/ij/developer/macro/functions.html

roiManager(“combine”)

Uses the union operator on the selected ROIs to create a composite
selection. Combines all ROIs if none are selected.

Example:

run("Blobs (25K)");
makeOval(58, 24, 31, 35);
roiManager("Add");
makeOval(87, 98, 31, 28);
roiManager("Add");
makeOval(160, 164, 36, 38);
roiManager("Add");
makeOval(83, 197, 41, 32);
roiManager("Add");
roiManager("Combine");
roiManager("Add");

#3

You are specifically asking about the API, so here goes an example using ij.gui.Roi and its subclasses (using Groovy; only small changes required for any other scripting language):

// @ImagePlus imp

import ij.gui.Roi
import ij.gui.OvalRoi
import ij.gui.PolygonRoi
import ij.gui.ShapeRoi

roi1 = new OvalRoi(10, 10, 80, 50)
roi2 = new PolygonRoi((float[])[2,98,10], (float[])[7,93,70], Roi.POLYGON)

compositeRoi = new ShapeRoi(roi1).or(new ShapeRoi(roi2))

imp.setRoi(compositeRoi)

#4

Awesome, thank you for the help!