public Roi seam2roi(int[] seam, boolean vertical) { int[] other = new int[vertical ? h : w]; for (int i = 0; i < other.length; i++) other[i] = i; return new PolygonRoi(vertical ? seam : other, vertical ? other : seam, seam.length, PolygonRoi.FREELINE); } }
/** * Creates an ImageJ 1.x {@link PolygonRoi} and wraps it as an ImgLib2 * {@link Polygon2D} or {@link Polyline}. * * @param xPoints x coordinates of the vertices * @param yPoints y coordinates of the vertices * @param nPoints number of vertices * @param type denotes if PolygonRoi behaves as {@link Roi#POLYGON} or * {@link Roi#POLYLINE} */ public AbstractPolygonRoiWrapper(final float[] xPoints, final float[] yPoints, final int nPoints, final int type) { poly = new PolygonRoi(xPoints, yPoints, nPoints, type); }
/** * Creates an ImageJ 1.x {@link PolygonRoi} and wraps it as an ImgLib2 * {@link Polygon2D} or {@link Polyline}. * * @param xPoints x coordinates of the vertices * @param yPoints y coordinates of the vertices * @param nPoints number of vertices * @param type denotes if PolygonRoi behaves as {@link Roi#POLYGON} or * {@link Roi#POLYLINE} */ public AbstractPolygonRoiWrapper(final int[] xPoints, final int[] yPoints, final int nPoints, final int type) { poly = new PolygonRoi(xPoints, yPoints, nPoints, type); }
/** * Creates an ImageJ 1.x {@link PolygonRoi} and wraps it as an ImgLib2 * {@link Mask}. The length of {@code xPoints} will be used to determine the * number of vertices this {@code Mask} has. * * @param xPoints x coordinates of the vertices * @param yPoints y coordinates of the vertices * @param type denotes if PolygonRoi behaves as {@link Roi#POLYGON} or * {@link Roi#POLYLINE} */ public AbstractPolygonRoiWrapper(final float[] xPoints, final float[] yPoints, final int type) { poly = new PolygonRoi(xPoints, yPoints, type); }
/** * Returns the convex hull of the blob. * @return The convex hull as polygon */ public Polygon getConvexHull() { PolygonRoi roi = new PolygonRoi(outerContour, Roi.POLYGON); Polygon hull = roi.getConvexHull(); if(hull==null){ return getOuterContour(); } return hull; }
/** * @return Outer contour as traced roi */ public Roi getOuterContourAsROI(){ Polygon p = getOuterContour(); int n = p.npoints; float[] x = new float[p.npoints]; float[] y = new float[p.npoints]; for (int j=0; j<n; j++) { x[j] = p.xpoints[j]+0.5f; y[j] = p.ypoints[j]+0.5f; } Roi roi = new PolygonRoi(x,y,n,Roi.TRACED_ROI); Roi.setColor(Color.green); return roi; }
/** * Calculates the min feret diameter of the outer contour * @return The feret diameter of the outer contour. */ public double getMinFeretDiameter() { PolygonRoi proi = new PolygonRoi(outerContour, PolygonRoi.POLYLINE); ImagePlus imp = new ImagePlus(); imp.setCalibration(cal); proi.setImage(imp); return proi.getFeretValues()[2]; }
/** * Calculates the feret diameter of the outer contour * @return The feret diameter of the outer contour. */ public double getFeretDiameter() { PolygonRoi proi = new PolygonRoi(outerContour, PolygonRoi.POLYLINE); ImagePlus imp = new ImagePlus(); imp.setCalibration(cal); proi.setImage(imp); return proi.getFeretsDiameter(); }
public ImageProcessor rotateLine(ImagePlus imp, int width) { Roi roi = imp.getRoi(); if (roi==null || roi.getType()!=Roi.LINE) throw new IllegalArgumentException("Straight line selection expected"); Polygon p = ((Line)roi).getPoints(); imp.setRoi(new PolygonRoi(p.xpoints, p.ypoints, 2, Roi.POLYLINE)); ImageProcessor ip2 = imp.getBitDepth()==24?straightenRGB(imp, width):straightenLine(imp, width); imp.setRoi(roi); return ip2; }
public ImageProcessor rotateLine(ImagePlus imp, int width) { Roi roi = imp.getRoi(); if (roi==null || roi.getType()!=Roi.LINE) throw new IllegalArgumentException("Straight line selection expected"); Polygon p = ((Line)roi).getPoints(); imp.setRoi(new PolygonRoi(p.xpoints, p.ypoints, 2, Roi.POLYLINE)); ImageProcessor ip2 = imp.getBitDepth()==24?straightenRGB(imp, width):straightenLine(imp, width); imp.setRoi(roi); return ip2; }
protected PolygonRoi flipROI(PolygonRoi roi) { if (roi.isSplineFit()) { roi = (PolygonRoi)roi.clone(); roi.removeSplineFit(); } Polygon polygon = roi.getPolygon(); for (int i = 0; i < polygon.npoints / 2; i++) { int dummy = polygon.xpoints[i]; polygon.xpoints[i] = polygon.xpoints[polygon.npoints - 1 - i]; polygon.xpoints[polygon.npoints - 1 - i] = dummy; dummy = polygon.ypoints[i]; polygon.ypoints[i] = polygon.ypoints[polygon.npoints - 1 - i]; polygon.ypoints[polygon.npoints - 1 - i] = dummy; } return new PolygonRoi(polygon, roi.getType()); }
private Roi createAngleRoi(final AngleOverlay overlay) { double[] pt = new double[overlay.numDimensions()]; overlay.getPoint1(pt); float xb = (float) pt[0]; float yb = (float) pt[1]; overlay.getCenter(pt); float xc = (float) pt[0]; float yc = (float) pt[1]; overlay.getPoint2(pt); float xe = (float) pt[0]; float ye = (float) pt[1]; float[] xpoints = new float[]{xb,xc,xe}; float[] ypoints = new float[]{yb,yc,ye}; Roi roi = new PolygonRoi(xpoints, ypoints, 3, Roi.ANGLE); assignPropertiesToRoi(roi, overlay); return roi; }
@Override public PolygonRoi convert(final Polygon2D mask) { final float[] x = new float[mask.numVertices()]; final float[] y = new float[mask.numVertices()]; for (int i = 0; i < mask.numVertices(); i++) { final RealLocalizable v = mask.vertex(i); x[i] = (float) v.getDoublePosition(0); y[i] = (float) v.getDoublePosition(1); } return new PolygonRoi(x, y, mask.numVertices(), Roi.POLYGON); }
@Override public PolygonRoi convert(final Polyline mask) { final float[] x = new float[mask.numVertices()]; final float[] y = new float[mask.numVertices()]; for (int i = 0; i < mask.numVertices(); i++) { final RealLocalizable v = mask.vertex(i); x[i] = (float) v.getDoublePosition(0); y[i] = (float) v.getDoublePosition(1); } return new PolygonRoi(x, y, mask.numVertices(), Roi.POLYLINE); }
/** delete a particle (set from value 255 to current fill value). * Position x,y must be within the particle */ void deleteParticle(int x, int y, ByteProcessor ip, Wand wand) { wand.autoOutline(x, y, 255, 255); if (wand.npoints==0) { IJ.log("wand error selecting edge particle at x, y = "+x+", "+y); return; } Roi roi = new PolygonRoi(wand.xpoints, wand.ypoints, wand.npoints, Roi.TRACED_ROI); ip.snapshot(); //prepare for reset outside of mask ip.setRoi(roi); ip.fill(); ip.reset(ip.getMask()); }
/** delete a particle (set from value 255 to current fill value). * Position x,y must be within the particle */ void deleteParticle(int x, int y, ByteProcessor ip, Wand wand) { wand.autoOutline(x, y, 255, 255); if (wand.npoints==0) { IJ.log("wand error selecting edge particle at x, y = "+x+", "+y); return; } Roi roi = new PolygonRoi(wand.xpoints, wand.ypoints, wand.npoints, Roi.TRACED_ROI); ip.snapshot(); //prepare for reset outside of mask ip.setRoi(roi); ip.fill(); ip.reset(ip.getMask()); }
/** delete a particle (set from value 255 to current fill value). * Position x,y must be within the particle */ void deleteParticle(int x, int y, ByteProcessor ip, Wand wand) { wand.autoOutline(x, y, 255, 255); if (wand.npoints==0) { IJ.log("wand error selecting edge particle at x, y = "+x+", "+y); return; } Roi roi = new PolygonRoi(wand.xpoints, wand.ypoints, wand.npoints, Roi.TRACED_ROI); ip.snapshot(); //prepare for reset outside of mask ip.setRoi(roi); ip.fill(); ip.reset(ip.getMask()); }
private Roi createPolygonRoi(final PolygonOverlay overlay) { final PolygonRegionOfInterest region = overlay.getRegionOfInterest(); final int vertexCount = region.getVertexCount(); if (vertexCount == 1) return createPointRoi(overlay); if (vertexCount == 2) return createLineRoi(overlay); final float[] x = new float[vertexCount]; final float[] y = new float[vertexCount]; for (int v = 0; v < vertexCount; v++) { final RealLocalizable vertex = region.getVertex(v); x[v] = vertex.getFloatPosition(0); y[v] = vertex.getFloatPosition(1); } final Roi roi = new PolygonRoi(x, y, vertexCount, Roi.POLYGON); assignPropertiesToRoi(roi, overlay); return roi; }
private void fillPolygon(ImageProcessor ip, Polygon p, boolean internContour) { PolygonRoi proi = new PolygonRoi(p, PolygonRoi.POLYGON); Rectangle r = proi.getBounds(); PolygonFiller pf = new PolygonFiller(); pf.setPolygon(proi.getXCoordinates(), proi.getYCoordinates(), proi.getNCoordinates()); ip.setRoi(r); ImageProcessor objectMask = pf.getMask(r.width, r.height); ip.fill(objectMask); if(!internContour){ ip.drawPolygon(p); } }
public static void main(String[] args) { PolygonRoiPublic roi = new PolygonRoiPublic(new int[] { 800, 800}, new int[] { 500, 500 }, 2, PolygonRoi.POLYLINE); //roi.addHandle(800, 500); roi.addHandle(100, 200); roi.addHandle(100, 500); roi.addHandle(800, 250); IJ.getImage().setRoi(roi); //IJ.getImage().setRoi((PolygonRoi)roi.clone()); PolygonRoi poly = new PolygonRoi(getXCoordinates(roi), getYCoordinates(roi), getNCoordinates(roi), PolygonRoi.POLYLINE); poly.fitSpline(); //IJ.getImage().setRoi(poly); }