コード例 #1
0
ファイル: PolygonRoi.java プロジェクト: oeway/Eva-ImageJ
 /** Returns a copy of this PolygonRoi. */
 public synchronized Object clone() {
   PolygonRoi r = (PolygonRoi) super.clone();
   if (xpf != null) {
     r.xpf = new float[maxPoints];
     r.ypf = new float[maxPoints];
   } else {
     r.xp = new int[maxPoints];
     r.yp = new int[maxPoints];
   }
   r.xp2 = new int[maxPoints];
   r.yp2 = new int[maxPoints];
   for (int i = 0; i < nPoints; i++) {
     if (xpf != null) {
       r.xpf[i] = xpf[i];
       r.ypf[i] = ypf[i];
     } else {
       r.xp[i] = xp[i];
       r.yp[i] = yp[i];
     }
     r.xp2[i] = xp2[i];
     r.yp2[i] = yp2[i];
   }
   if (xSpline != null) {
     r.xSpline = new float[splinePoints];
     r.ySpline = new float[splinePoints];
     r.splinePoints = splinePoints;
     for (int i = 0; i < splinePoints; i++) {
       r.xSpline[i] = xSpline[i];
       r.ySpline[i] = ySpline[i];
     }
   }
   return r;
 }
コード例 #2
0
 public void mouseMoved(MouseEvent e) {
   // if (ij==null) return;
   int sx = e.getX();
   int sy = e.getY();
   int ox = offScreenX(sx);
   int oy = offScreenY(sy);
   flags = e.getModifiers();
   setCursor(sx, sy, ox, oy);
   IJ.setInputEvent(e);
   Roi roi = imp.getRoi();
   if (roi != null
       && (roi.getType() == Roi.POLYGON
           || roi.getType() == Roi.POLYLINE
           || roi.getType() == Roi.ANGLE)
       && roi.getState() == roi.CONSTRUCTING) {
     PolygonRoi pRoi = (PolygonRoi) roi;
     pRoi.handleMouseMove(ox, oy);
   } else {
     if (ox < imageWidth && oy < imageHeight) {
       ImageWindow win = imp.getWindow();
       // Cursor must move at least 12 pixels before text
       // displayed using IJ.showStatus() is overwritten.
       if ((sx - sx2) * (sx - sx2) + (sy - sy2) * (sy - sy2) > 144) showCursorStatus = true;
       if (win != null && showCursorStatus) win.mouseMoved(ox, oy);
     } else IJ.showStatus("");
   }
 }
コード例 #3
0
 void fitSpline() {
   Roi roi = imp.getRoi();
   if (roi == null) {
     IJ.error("Spline", "Selection required");
     return;
   }
   int type = roi.getType();
   boolean segmentedSelection = type == Roi.POLYGON || type == Roi.POLYLINE;
   if (!(segmentedSelection
       || type == Roi.FREEROI
       || type == Roi.TRACED_ROI
       || type == Roi.FREELINE)) {
     IJ.error("Spline", "Polygon or polyline selection required");
     return;
   }
   if (roi instanceof EllipseRoi) return;
   PolygonRoi p = (PolygonRoi) roi;
   if (!segmentedSelection) p = trimPolygon(p, p.getUncalibratedLength());
   String options = Macro.getOptions();
   if (options != null && options.indexOf("straighten") != -1) p.fitSplineForStraightening();
   else if (options != null && options.indexOf("remove") != -1) p.removeSplineFit();
   else p.fitSpline();
   imp.draw();
   LineWidthAdjuster.update();
 }
コード例 #4
0
 PolygonRoi trimFloatPolygon(PolygonRoi roi, double length) {
   FloatPolygon poly = roi.getFloatPolygon();
   float[] x = poly.xpoints;
   float[] y = poly.ypoints;
   int n = poly.npoints;
   x = smooth(x, n);
   y = smooth(y, n);
   float[] curvature = getCurvature(x, y, n);
   double threshold = rodbard(length);
   // IJ.log("trim: "+length+" "+threshold);
   double distance = Math.sqrt((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
   int i2 = 1;
   double x1, y1, x2 = 0, y2 = 0;
   for (int i = 1; i < n - 1; i++) {
     x1 = x[i];
     y1 = y[i];
     x2 = x[i + 1];
     y2 = y[i + 1];
     distance += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) + 1;
     distance += curvature[i] * 2;
     if (distance >= threshold) {
       x[i2] = (float) x2;
       y[i2] = (float) y2;
       i2++;
       distance = 0.0;
     }
   }
   int type = roi.getType() == Roi.FREELINE ? Roi.POLYLINE : Roi.POLYGON;
   if (type == Roi.POLYLINE && distance > 0.0) {
     x[i2] = (float) x2;
     y[i2] = (float) y2;
     i2++;
   }
   PolygonRoi p = new PolygonRoi(x, y, i2, type);
   if (roi.getStroke() != null) p.setStrokeWidth(roi.getStrokeWidth());
   p.setStrokeColor(roi.getStrokeColor());
   p.setName(roi.getName());
   imp.setRoi(p);
   return p;
 }
コード例 #5
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 PolygonRoi trimPolygon(PolygonRoi roi, double length) {
   int[] x = roi.getXCoordinates();
   int[] y = roi.getYCoordinates();
   int n = roi.getNCoordinates();
   x = smooth(x, n);
   y = smooth(y, n);
   float[] curvature = getCurvature(x, y, n);
   Rectangle r = roi.getBounds();
   double threshold = rodbard(length);
   // IJ.log("trim: "+length+" "+threshold);
   double distance = Math.sqrt((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
   x[0] += r.x;
   y[0] += r.y;
   int i2 = 1;
   int x1, y1, x2 = 0, y2 = 0;
   for (int i = 1; i < n - 1; i++) {
     x1 = x[i];
     y1 = y[i];
     x2 = x[i + 1];
     y2 = y[i + 1];
     distance += Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) + 1;
     distance += curvature[i] * 2;
     if (distance >= threshold) {
       x[i2] = x2 + r.x;
       y[i2] = y2 + r.y;
       i2++;
       distance = 0.0;
     }
   }
   int type = roi.getType() == Roi.FREELINE ? Roi.POLYLINE : Roi.POLYGON;
   if (type == Roi.POLYLINE && distance > 0.0) {
     x[i2] = x2 + r.x;
     y[i2] = y2 + r.y;
     i2++;
   }
   PolygonRoi p = new PolygonRoi(x, y, i2, type);
   imp.setRoi(p);
   return p;
 }
コード例 #6
0
 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);
 }