ImageProcessor shrink(ImageProcessor ip, ImageProcessor ip2, boolean hasEdgePixels) { if (hasEdgePixels) { int width = ip.getWidth(); int height = ip.getHeight(); for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) ip.putPixel(x, y, ip2.getPixel(x + 1, y + 1)); } return ip; }
boolean eraseOutsideRoi(ImageProcessor ip, Rectangle r, ImageProcessor mask) { int width = ip.getWidth(); int height = ip.getHeight(); ip.setRoi(r); if (excludeEdgeParticles && polygon != null) { ImageStatistics stats = ImageStatistics.getStatistics(ip, MIN_MAX, null); if (fillColor >= stats.min && fillColor <= stats.max) { double replaceColor = level1 - 1.0; if (replaceColor < 0.0 || replaceColor == fillColor) { replaceColor = level2 + 1.0; int maxColor = imageType == BYTE ? 255 : 65535; if (replaceColor > maxColor || replaceColor == fillColor) { IJ.error("Particle Analyzer", "Unable to remove edge particles"); return false; } } for (int y = minY; y < maxY; y++) { for (int x = minX; x < maxX; x++) { int v = ip.getPixel(x, y); if (v == fillColor) ip.putPixel(x, y, (int) replaceColor); } } } } ip.setValue(fillColor); if (mask != null) { mask = mask.duplicate(); mask.invert(); ip.fill(mask); } ip.setRoi(0, 0, r.x, height); ip.fill(); ip.setRoi(r.x, 0, r.width, r.y); ip.fill(); ip.setRoi(r.x, r.y + r.height, r.width, height - (r.y + r.height)); ip.fill(); ip.setRoi(r.x + r.width, 0, width - (r.x + r.width), height); ip.fill(); ip.resetRoi(); // IJ.log("erase: "+fillColor+" "+level1+" "+level2+" "+excludeEdgeParticles); // (new ImagePlus("ip2", ip.duplicate())).show(); return true; }