Skip to content

Instantly share code, notes, and snippets.

@mutterer
Last active January 4, 2024 17:42
Show Gist options
  • Save mutterer/4d3c831ca6a7e698f77eba0261b086c5 to your computer and use it in GitHub Desktop.
Save mutterer/4d3c831ca6a7e698f77eba0261b086c5 to your computer and use it in GitHub Desktop.
Better Wand Tool
macro "Better Wand Tool - C000T0f10BT7f10WTff10T" {
if (!isOpen("ROI Manager")) run("ROI Manager...");
smoothness= call('ij.Prefs.get','bwt.selectSmoothness',3);
getCursorLoc(x, y, z, flags);
id=getImageID;
setBatchMode(1);
run("Select None");
run("Duplicate...","title=a");
run("Gaussian Blur...", "radius="+smoothness);
id2=getImageID;
while (flags&16!=0) {
selectImage(id);
getCursorLoc(x1, y1, z, flags);
selectImage(id2);
doWand(x, y, 0.5*sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)), "8-connected");
getSelectionCoordinates(xpoints, ypoints);
selectImage(id);
Overlay.clear;
makeSelection("freehand", xpoints, ypoints);
Overlay.addSelection("green")
Overlay.show;
wait(20);
}
roiManager('add');
roiManager("show all with labels");
roiManager('select',roiManager('count')-1);
}
macro "Better Wand Tool Options" {
smoothness = call('ij.Prefs.get','bwt.selectSmoothness',3);
Dialog.create("Options");
Dialog.addNumber("Smoothness factor", smoothness);
Dialog.show();
smoothness= Dialog.getNumber();
call('ij.Prefs.set','bwt.selectSmoothness',smoothness);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment