Re: can I divide a circular ROI into equal slices?
Posted by dscho on
URL: http://imagej.273.s1.nabble.com/Problem-with-ROI-Manager-in-BatchMode-tp3682680p3682685.html
Hi Aryeh,
On Tue, 1 Nov 2011, Aryeh Weiss wrote:
> Is there a plugin or option to divide a circular ROI in a set of slices
> (like pie slices). I foudn something in the archives for dividing
> circular ROIs into hemispheres and quadrants. I was wondering if someone
> has a more general version of that?
I just had a little macro fun and came up with this one (beware: it
expects the current selection to be an oval ROI, and it has no error
handling whatsoever):
-- snipsnap --
// get the center and radii
getSelectionBounds(x, y, width, height);
radiusX = width / 2;
radiusY = height / 2;
centerX = x + radiusX;
centerY = y + radiusY;
// ask the user how many slices she wants
pieSliceCount = getNumber("How many slices?", 4);
angleSteps = 2 * PI * (radiusX + radiusY) / 4 / pieSliceCount;
// make the slices and add them to the ROI Manager
for (i = 0; i < pieSliceCount; i++) {
startAngle = 2 * PI * i / pieSliceCount;
endAngle = 2 * PI * (i + 1) / pieSliceCount;
x = newArray(angleSteps + 2);
y = newArray(angleSteps + 2);
for (step = 0; step <= angleSteps; step++) {
angle = startAngle + (endAngle - startAngle)
* step / angleSteps;
x[step] = centerX + radiusX * cos(angle);
y[step] = centerY + radiusY * sin(angle);
}
x[angleSteps + 1] = centerX;
y[angleSteps + 1] = centerY;
makeSelection("polygon", x, y);
roiManager("Add");
}