/** Do watershed segmentation based on the EDM of the * foreground objects (nonzero pixels) in an 8-bit image. * Particles are segmented by their shape; segmentation * lines added are background pixels (value = 0); */ public void toWatershed (ImageProcessor ip) { FloatProcessor floatEdm = makeFloatEDM(ip, 0, false); ByteProcessor maxIp = maxFinder.findMaxima(floatEdm, MAXFINDER_TOLERANCE, ImageProcessor.NO_THRESHOLD, MaximumFinder.SEGMENTED, false, true); if (maxIp != null) ip.copyBits(maxIp, 0, 0, Blitter.AND); }
edmLine(bPixels, fPixels, pointBufs, width, y*width, y, backgroundValue, yDist); if (y%progressInterval == 0) { if (Thread.currentThread().isInterrupted()) return null; addProgress(progressAddendum); edmLine(bPixels, fPixels, pointBufs, width, y*width, y, backgroundValue, yDist); if (y%progressInterval == 0) { if (Thread.currentThread().isInterrupted()) return null; addProgress(progressAddendum);
if (edgesAreBackground) distSqr = (x+1 < yDist) ? (x+1)*(x+1) : yDist*yDist; //distance from edge float dist2 = minDist2(points, pPrev, pDiag, x, y, distSqr); if (fPixels[offset] > dist2) fPixels[offset] = dist2; if (edgesAreBackground) distSqr = (width-x < yDist) ? (width-x)*(width-x) : yDist*yDist; float dist2 = minDist2(points, pPrev, pDiag, x, y, distSqr); if (fPixels[offset] > dist2) fPixels[offset] = dist2;
private static Roi shrink(Roi roi, int n) { Rectangle bounds = roi.getBounds(); int width = bounds.width + 2; int height = bounds.height + 2; ImageProcessor ip = new ByteProcessor(width, height); roi.setLocation(1, 1); ip.setColor(255); ip.fill(roi); roi.setLocation(bounds.x, bounds.y); boolean bb = Prefs.blackBackground; Prefs.blackBackground = true; new EDM().toEDM(ip); Prefs.blackBackground = bb; ip.setThreshold(n+1, 255, ImageProcessor.NO_LUT_UPDATE); Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2==null) return roi; Rectangle bounds2 = roi2.getBounds(); if (bounds2.width<=0 && bounds2.height<=0) return roi; roi2.setLocation(bounds.x+bounds2.x-1, bounds.y+bounds2.y-1); return roi2; }
public double getDiamaterMaximumInscribedCircle() { ImagePlus help = generateBlobImage(this); ImageProcessor ipHelp = help.getProcessor(); ipHelp.invert(); EDM dm = new EDM(); FloatProcessor fp = dm.makeFloatEDM (ipHelp, 0, false); MaximumFinder mf = new MaximumFinder(); ByteProcessor bp = mf.findMaxima(fp, 0.5, ImageProcessor.NO_THRESHOLD, MaximumFinder.SINGLE_POINTS, false, true); Polygon pl = mf.getMaxima(bp, 0, true); return fp.getf(pl.xpoints[0], pl.ypoints[0])*2*cal.getX(1); }
(background255 ? (byte)255 : 0); //all others do EDM of the foreground if (USES_WATERSHED[processType]) nPasses = 0; //watershed has its own progress bar FloatProcessor floatEdm = makeFloatEDM(ip, backgroundValue, false); } else if (processType != WATERSHED) { if (processType == VORONOI) floatEdm.multiply(-1); resetMasked(floatEdm, maxIp, processType == VORONOI ? -1 : 0);
public boolean dialogItemChanged (GenericDialog gd, AWTEvent e) { iterations = (int)gd.getNextNumber(); count = (int)gd.getNextNumber(); boolean bb = Prefs.blackBackground; Prefs.blackBackground = gd.getNextBoolean(); if ( Prefs.blackBackground!=bb) ThresholdAdjuster.update(); Prefs.padEdges = gd.getNextBoolean(); gd.setSmartRecording(EDM.getOutputType()==0); EDM.setOutputType(gd.getNextChoiceIndex()); gd.setSmartRecording(false); boolean isInvalid = gd.invalidNumber(); if (iterations<1) {iterations = 1; isInvalid = true;} if (iterations>MAX_ITERATIONS) {iterations = MAX_ITERATIONS; isInvalid = true;} if (count < 1) {count = 1; isInvalid = true;} if (count > 8) {count = 8; isInvalid = true;} if (isInvalid) return false; if (imp != null) { operation = gd.getNextChoice(); arg = operation.toLowerCase(); } return true; }
gd.addCheckbox("Black background", Prefs.blackBackground); gd.addCheckbox("Pad edges when eroding", Prefs.padEdges); gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]); if (imp != null) { gd.addChoice("Do:", operations, operation);
showOutput(); return DONE;
private static Roi shrink(Roi roi, int n) { Rectangle bounds = roi.getBounds(); int width = bounds.width + 2; int height = bounds.height + 2; ImageProcessor ip = new ByteProcessor(width, height); roi.setLocation(1, 1); ip.setColor(255); ip.fill(roi); roi.setLocation(bounds.x, bounds.y); boolean bb = Prefs.blackBackground; Prefs.blackBackground = true; new EDM().toEDM(ip); Prefs.blackBackground = bb; ip.setThreshold(n+1, 255, ImageProcessor.NO_LUT_UPDATE); Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2==null) return roi; Rectangle bounds2 = roi2.getBounds(); if (bounds2.width<=0 && bounds2.height<=0) return roi; roi2.setLocation(bounds.x+bounds2.x-1, bounds.y+bounds2.y-1); return roi2; }
(background255 ? (byte)255 : 0); //all others do EDM of the foreground if (USES_WATERSHED[processType]) nPasses = 0; //watershed has its own progress bar FloatProcessor floatEdm = makeFloatEDM(ip, backgroundValue, false); } else if (processType != WATERSHED) { if (processType == VORONOI) floatEdm.multiply(-1); resetMasked(floatEdm, maxIp, processType == VORONOI ? -1 : 0);
public boolean dialogItemChanged (GenericDialog gd, AWTEvent e) { iterations = (int)gd.getNextNumber(); count = (int)gd.getNextNumber(); boolean bb = Prefs.blackBackground; Prefs.blackBackground = gd.getNextBoolean(); if ( Prefs.blackBackground!=bb) ThresholdAdjuster.update(); Prefs.padEdges = gd.getNextBoolean(); gd.setSmartRecording(EDM.getOutputType()==0); EDM.setOutputType(gd.getNextChoiceIndex()); gd.setSmartRecording(false); boolean isInvalid = gd.invalidNumber(); if (iterations<1) {iterations = 1; isInvalid = true;} if (iterations>MAX_ITERATIONS) {iterations = MAX_ITERATIONS; isInvalid = true;} if (count < 1) {count = 1; isInvalid = true;} if (count > 8) {count = 8; isInvalid = true;} if (isInvalid) return false; if (imp != null) { operation = gd.getNextChoice(); arg = operation.toLowerCase(); } return true; }
gd.addCheckbox("Black background", Prefs.blackBackground); gd.addCheckbox("Pad edges when eroding", Prefs.padEdges); gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]); if (imp != null) { gd.addChoice("Do:", operations, operation);
showOutput(); return DONE;
/** Calculates a 16-bit grayscale Euclidean Distance Map for a binary 8-bit image. * Each foreground (nonzero) pixel in the binary image is assigned a value equal to * its distance from the nearest background (zero) pixel, multiplied by EDM.ONE. * For compatibility with previous versions of ImageJ only. */ public ShortProcessor make16bitEDM (ImageProcessor ip) { FloatProcessor floatEdm = makeFloatEDM(ip, 0, false); floatEdm.setMinAndMax(0, 65535./ONE); return (ShortProcessor)floatEdm.convertToShort(true); }
boolean saveBlackBackground = Prefs.blackBackground; Prefs.blackBackground = false; int saveType = EDM.getOutputType(); EDM.setOutputType(EDM.BYTE_OVERWRITE); IJ.run(edm, "Distance Map", ""); EDM.setOutputType(saveType); Prefs.blackBackground = saveBlackBackground; ip = edm.getProcessor();
edmLine(bPixels, fPixels, pointBufs, width, y*width, y, backgroundValue, yDist); if (y%progressInterval == 0) { if (Thread.currentThread().isInterrupted()) return null; addProgress(progressAddendum); edmLine(bPixels, fPixels, pointBufs, width, y*width, y, backgroundValue, yDist); if (y%progressInterval == 0) { if (Thread.currentThread().isInterrupted()) return null; addProgress(progressAddendum);
if (edgesAreBackground) distSqr = (x+1 < yDist) ? (x+1)*(x+1) : yDist*yDist; //distance from edge float dist2 = minDist2(points, pPrev, pDiag, x, y, distSqr); if (fPixels[offset] > dist2) fPixels[offset] = dist2; if (edgesAreBackground) distSqr = (width-x < yDist) ? (width-x)*(width-x) : yDist*yDist; float dist2 = minDist2(points, pPrev, pDiag, x, y, distSqr); if (fPixels[offset] > dist2) fPixels[offset] = dist2;