use of ij.macro.MacroRunner in project imagej1 by imagej.
the class IJ method doWand.
/**
* This version of doWand adds an ImagePlus argument.
*/
public static int doWand(ImagePlus img, int x, int y, double tolerance, String mode) {
ImageProcessor ip = img.getProcessor();
if ((img.getType() == ImagePlus.GRAY32) && Double.isNaN(ip.getPixelValue(x, y)))
return 0;
int imode = Wand.LEGACY_MODE;
boolean smooth = false;
if (mode != null) {
if (mode.startsWith("4"))
imode = Wand.FOUR_CONNECTED;
else if (mode.startsWith("8"))
imode = Wand.EIGHT_CONNECTED;
smooth = mode.contains("smooth");
}
Wand w = new Wand(ip);
double t1 = ip.getMinThreshold();
if (t1 == ImageProcessor.NO_THRESHOLD || (ip.getLutUpdateMode() == ImageProcessor.NO_LUT_UPDATE && tolerance > 0.0)) {
w.autoOutline(x, y, tolerance, imode);
smooth = false;
} else
w.autoOutline(x, y, t1, ip.getMaxThreshold(), imode);
if (w.npoints > 0) {
Roi previousRoi = img.getRoi();
Roi roi = new PolygonRoi(w.xpoints, w.ypoints, w.npoints, Roi.TRACED_ROI);
img.deleteRoi();
img.setRoi(roi);
if (previousRoi != null)
// add/subtract ROI to previous one if shift/alt key down
roi.update(shiftKeyDown(), altKeyDown());
Roi roi2 = img.getRoi();
if (smooth && roi2 != null && roi2.getType() == Roi.TRACED_ROI) {
Rectangle bounds = roi2.getBounds();
if (bounds.width > 1 && bounds.height > 1) {
if (smoothMacro == null)
smoothMacro = BatchProcessor.openMacroFromJar("SmoothWandTool.txt");
if (EventQueue.isDispatchThread())
// run on separate thread
new MacroRunner(smoothMacro);
else
IJ.runMacro(smoothMacro);
}
}
}
return w.npoints;
}
Aggregations