Skip to content

Instantly share code, notes, and snippets.

@tferr
Created June 13, 2017 16:47
Show Gist options
  • Save tferr/0e3c5933b99f9c34425eb016baad9298 to your computer and use it in GitHub Desktop.
Save tferr/0e3c5933b99f9c34425eb016baad9298 to your computer and use it in GitHub Desktop.
Fixed size Rectangular ROI tool for IJ1
/* Subfield Tool.ijm
* IJ BAR: https://github.com/tferr/Scripts
*
* Creates a square ROI sized from on the length of a straight line
*/
var sizeRatio = 1/3;
macro "SubField Tool - C037 L0ff0 R3399" {
getCursorLoc(x, y, z, flags);
xstart = x; ystart = y;
x2 = x; y2 = y;
while (flags&16!=0) {
getCursorLoc(x, y, z, flags);
if (x!=x2 || y!=y2)
makeLine(xstart, ystart, x, y);
}
dx = (x2 - x);
dy = (y2 - y);
width = sizeRatio * sqrt(dx * dx + dy * dy);
xMid = (x2 + x) / 2;
yMid = (y2 + y) / 2;
makeRectangle(xMid, yMid, width, width);
setTool(0);
}
macro "SubField Tool Options" {
sizeRatio = getNumber("ROI width (fraction of line length)", sizeRatio);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment