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; }
private String addMean(int column, String line, int start) { if (start == -1) { line += "\tNaN"; summaryHdr += "\t" + ResultsTable.getDefaultHeading(column); } else { float[] c = column >= 0 ? rt.getColumn(column) : null; if (c != null) { ImageProcessor ip = new FloatProcessor(c.length, 1, c, null); if (ip == null) return line; ip.setRoi(start, 0, ip.getWidth() - start, 1); ip = ip.crop(); ImageStatistics stats = new FloatStatistics(ip); if (stats == null) return line; line += n(stats.mean); } else line += "\tNaN"; summaryHdr += "\t" + rt.getColumnHeading(column); } return line; }
void drawRoiFilledParticle(ImageProcessor ip, Roi roi, ImageProcessor mask, int count) { int grayLevel = (count < 65535) ? count : 65535; ip.setValue((double) grayLevel); ip.setRoi(roi.getBounds()); ip.fill(mask); }
void drawFilledParticle(ImageProcessor ip, Roi roi, ImageProcessor mask) { // IJ.write(roi.getBounds()+" "+mask.length); ip.setRoi(roi.getBounds()); ip.fill(mask); }
void analyzeParticle(int x, int y, ImagePlus imp, ImageProcessor ip) { // Wand wand = new Wand(ip); ImageProcessor ip2 = redirectIP != null ? redirectIP : ip; wand.autoOutline(x, y, level1, level2, wandMode); if (wand.npoints == 0) { IJ.log("wand error: " + x + " " + y); return; } Roi roi = new PolygonRoi(wand.xpoints, wand.ypoints, wand.npoints, roiType); Rectangle r = roi.getBounds(); if (r.width > 1 && r.height > 1) { PolygonRoi proi = (PolygonRoi) roi; pf.setPolygon(proi.getXCoordinates(), proi.getYCoordinates(), proi.getNCoordinates()); ip2.setMask(pf.getMask(r.width, r.height)); if (floodFill) ff.particleAnalyzerFill(x, y, level1, level2, ip2.getMask(), r); } ip2.setRoi(r); ip.setValue(fillColor); ImageStatistics stats = getStatistics(ip2, measurements, calibration); boolean include = true; if (excludeEdgeParticles) { if (r.x == minX || r.y == minY || r.x + r.width == maxX || r.y + r.height == maxY) include = false; if (polygon != null) { Rectangle bounds = roi.getBounds(); int x1 = bounds.x + wand.xpoints[wand.npoints - 1]; int y1 = bounds.y + wand.ypoints[wand.npoints - 1]; int x2, y2; for (int i = 0; i < wand.npoints; i++) { x2 = bounds.x + wand.xpoints[i]; y2 = bounds.y + wand.ypoints[i]; if (!polygon.contains(x2, y2)) { include = false; break; } if ((x1 == x2 && ip.getPixel(x1, y1 - 1) == fillColor) || (y1 == y2 && ip.getPixel(x1 - 1, y1) == fillColor)) { include = false; break; } x1 = x2; y1 = y2; } } } ImageProcessor mask = ip2.getMask(); if (minCircularity > 0.0 || maxCircularity < 1.0) { double perimeter = roi.getLength(); double circularity = perimeter == 0.0 ? 0.0 : 4.0 * Math.PI * (stats.pixelCount / (perimeter * perimeter)); if (circularity > 1.0) circularity = 1.0; // IJ.log(circularity+" "+perimeter+" "+stats.area); if (circularity < minCircularity || circularity > maxCircularity) include = false; } if (stats.pixelCount >= minSize && stats.pixelCount <= maxSize && include) { particleCount++; if (roiNeedsImage) roi.setImage(imp); stats.xstart = x; stats.ystart = y; saveResults(stats, roi); if (showChoice != NOTHING) drawParticle(drawIP, roi, stats, mask); } if (redirectIP != null) ip.setRoi(r); ip.fill(mask); }