MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / trimPolygon

Method trimPolygon

ij/src/main/java/ij/plugin/Selection.java:368–405  ·  view source on GitHub ↗
(PolygonRoi roi, double length)

Source from the content-addressed store, hash-verified

366 }
367
368 PolygonRoi trimPolygon(PolygonRoi roi, double length) {
369 int[] x = roi.getXCoordinates();
370 int[] y = roi.getYCoordinates();
371 int n = roi.getNCoordinates();
372 x = smooth(x, n);
373 y = smooth(y, n);
374 float[] curvature = getCurvature(x, y, n);
375 Rectangle r = roi.getBounds();
376 double threshold = rodbard(length);
377 double distance = Math.sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));
378 x[0] += r.x; y[0]+=r.y;
379 int i2 = 1;
380 int x1,y1,x2=0,y2=0;
381 for (int i=1; i<n-1; i++) {
382 x1=x[i]; y1=y[i]; x2=x[i+1]; y2=y[i+1];
383 distance += Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) + 1;
384 distance += curvature[i]*2;
385 if (distance>=threshold) {
386 x[i2] = x2 + r.x;
387 y[i2] = y2 + r.y;
388 i2++;
389 distance = 0.0;
390 }
391 }
392 int type = roi.getType()==Roi.FREELINE?Roi.POLYLINE:Roi.POLYGON;
393 if (type==Roi.POLYLINE && distance>0.0) {
394 x[i2] = x2 + r.x;
395 y[i2] = y2 + r.y;
396 i2++;
397 }
398 PolygonRoi p = new PolygonRoi(x, y, i2, type);
399 if (roi.getStroke()!=null)
400 p.setStrokeWidth(roi.getStrokeWidth());
401 p.setStrokeColor(roi.getStrokeColor());
402 p.setName(roi.getName());
403 imp.setRoi(p);
404 return p;
405 }
406
407 double rodbard(double x) {
408 // y = c*((a-x/(x-d))^(1/b)

Callers 1

fitSplineMethod · 0.95

Calls 15

smoothMethod · 0.95
getCurvatureMethod · 0.95
rodbardMethod · 0.95
getXCoordinatesMethod · 0.80
getYCoordinatesMethod · 0.80
getNCoordinatesMethod · 0.80
getStrokeMethod · 0.80
getStrokeWidthMethod · 0.80
getStrokeColorMethod · 0.80
getBoundsMethod · 0.65
getTypeMethod · 0.65
getNameMethod · 0.65

Tested by

no test coverage detected