Skip to content

Instantly share code, notes, and snippets.

@mutterer
Last active January 17, 2018 14:19
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/1a109bb9c90ed1825b3754bf724e6f80 to your computer and use it in GitHub Desktop.
Save mutterer/1a109bb9c90ed1825b3754bf724e6f80 to your computer and use it in GitHub Desktop.
Crops the clicked face in a image
// presiquites: A fresh Fiji installation
// subscribe to the IJ OpenCV plugins update site
macro "Frame Face Tool - C000T0f16F" {
getCursorLoc(x,y,z,flags);
if (isOpen("ROI Manager")) {
selectWindow("ROI Manager");
run("Close");
}
run("FaceDetectionJ ");
if (roiManager("count")== 0) exit("no face detected");
index=-1;
for (i=0;i<roiManager("count");i++) {
roiManager("select", i);
if (Roi.contains(x,y)==1) index = i;
}
if (index==-1) exit("no face detected at this position");
roiManager("Select", index);
getBoundingRect(x,y,w,h);
d = maxOf(w,h);
makeRectangle(x-d/2,y-d/2,2*d,2*d);
run("Duplicate...", "title=face");
run("Size...", "width=512 height=512 constrain average interpolation=Bicubic");
min = minOf(getWidth,getHeight);
if (min<512) {
run("Canvas Size...", "width=&min height=&min position=Center");
run("Size...", "width=512 height=512 constrain average interpolation=Bicubic");
}
run("Input/Output...", "jpeg=100");
saveAs("Jpeg","");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment