Skip to content

Instantly share code, notes, and snippets.

@mutterer
Last active June 25, 2018 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutterer/31c4056fe8782424e6ee058ce78b912e to your computer and use it in GitHub Desktop.
Save mutterer/31c4056fe8782424e6ee058ce78b912e to your computer and use it in GitHub Desktop.
An ImageJ Toolset to interactively create image parts
// Pie Cut Toolset modified from the star_tool.ijm sample macro
//
var minSize = 12;
var nPoints = 6;
var ratio = 0;
var lineWidth = 2;
var fillStar = false;
macro "Pie Tool - B17C039T0f28*" {
getCursorLoc(x, y, z, flags);
x0=x; y0=y;
getSelectionBounds(rx, ry, w, h);
if ((x>rx)&&(x<rx+w)&&(y>ry)&&(y<ry+h)&&selectionType>0) {
// move existing star
while ((flags&16)!=0) {
getCursorLoc(x, y, z, flags);
Roi.move(rx+x-x0, ry+y-y0);
wait(10);
}
exit();
}
// or create a new one
makeLine (x0,y0,x0+1,y0+1);
while ((flags&16)!=0) {
getCursorLoc(x, y, z, flags);
xs=newArray(nPoints*2);
ys=newArray(nPoints*2);
r = maxOf(minSize,sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0)));
a = atan2(x-x0,y-y0);
for (i=0; i<nPoints; i++) {
xs[i*2] = x0 + r*sin(a+i*2*PI/nPoints);
xs[i*2+1] = x0 + ratio*r*sin(a+(i+0.5)*2*PI/nPoints);
ys[i*2] = y0 + r*cos(a+i*2*PI/nPoints);
ys[i*2+1] = y0 + ratio*r*cos(a+(i+0.5)*2*PI/nPoints);
}
makeSelection("polygon",xs,ys);
wait(20);
}
}
macro "Pie Tool Options" {
nPoints = getNumber("Number of parts", nPoints);
}
macro "Cut Action Tool - C000O0d66O9d66L6f90L9f00" {
roiManager('reset');
getSelectionCoordinates(xpoints, ypoints);
xp=newArray(3); yp=newArray(3);
xp[0]=xpoints[1]; yp[0]=ypoints[1];
for (i=0; i<xpoints.length/2; i++) {
xp[1]=xpoints[2*i];
yp[1]=ypoints[2*i];
xp[2]=xpoints[(2*i+2)%xpoints.length];
yp[2]=ypoints[(2*i+2)%xpoints.length];
makeSelection("polygon", xp, yp);
roiManager('add');
}
roiManager("Show All with labels");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment