// This macro divides a circular selection // into a set of slices (like pie slices). // Author: Johannes Schindelin // 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("freehand", x, y); roiManager("Add"); }