/** * Wraps an ImageJ 1.x {@link PolygonRoi} as an ImgLib2 {@link Mask}. * * @param poly the {@code PolygonRoi} to be wrapped */ public AbstractPolygonRoiWrapper(final PolygonRoi poly) { if (poly.isSplineFit()) throw new IllegalArgumentException( "Cannot wrap spline fit PolygonRois"); this.poly = poly; }
/** * Wraps an ImageJ 1.x {@link PolygonRoi} as an ImgLib2 {@link Polygon2D}. * * @param poly the {@code PolygonRoi} to be wrapped */ public PolygonRoiWrapper(final PolygonRoi poly) { super(poly); if (poly.getType() != Roi.POLYGON) throw new IllegalArgumentException( "Cannot wrap " + poly.getTypeAsString() + " as Polygon2D"); if (poly.isSplineFit()) throw new IllegalArgumentException("Cannot wrap " + "spline fitted polygons"); }
/** * Wraps an ImageJ 1.x {@link PolygonRoi} as an ImgLib2 {@link Polyline}. * * @param poly the {@code PolygonRoi} to be wrapped */ public PolylineRoiWrapper(final PolygonRoi poly) { super(poly); if (poly.getType() != Roi.POLYLINE) throw new IllegalArgumentException( "Cannot wrap " + poly.getTypeAsString() + " as Polyline"); if (poly.getStrokeWidth() != 0) throw new IllegalArgumentException( "Cannot wrap polylines with non-zero width"); if (poly.isSplineFit()) throw new IllegalArgumentException("Cannot wrap " + "spline fitted polylines"); }
boolean isSplineFit() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) return false; Roi roi = imp.getRoi(); if (roi==null) return false; if (!(roi instanceof PolygonRoi)) return false; return ((PolygonRoi)roi).isSplineFit(); }
boolean isSplineFit() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) return false; Roi roi = imp.getRoi(); if (roi==null) return false; if (!(roi instanceof PolygonRoi)) return false; return ((PolygonRoi)roi).isSplineFit(); }
/** * Wraps an ImageJ 1.x {@link PolygonRoi} as an ImgLib2 {@link Polyline}. * * @param poly the {@code PolygonRoi} to be wrapped */ public UnmodifiablePolylineRoiWrapper(final PolygonRoi poly) { super(poly); if (poly.getType() != Roi.FREELINE && poly.getType() != Roi.ANGLE) throw new IllegalArgumentException("Cannot wrap " + poly .getTypeAsString() + " as Polyline"); if (poly.getStrokeWidth() != 0) throw new IllegalArgumentException( "Cannot wrap polylines with non-zero width"); if (poly.isSplineFit()) throw new IllegalArgumentException("Cannot wrap " + "spline fitted polylines"); }
@Override public boolean supportedType(final PolygonRoi src) { final boolean supportedType = src.getType() == Roi.POLYGON || src .getType() == Roi.TRACED_ROI || src.getType() == Roi.FREEROI; // EllipseRoi and RotatedRectRoi are both PolygonRois & FREEROI return supportedType && !src.isSplineFit() && !(src instanceof RotatedRectRoi) && !(src instanceof EllipseRoi); } }
protected Polygon getPolygon(int sliceIndex) { PolygonRoi roi = rois[sliceIndex]; if (roi.isSplineFit()) { roi = (PolygonRoi)roi.clone(); roi.removeSplineFit(); } return roi.getPolygon(); }
protected static Polygon getPolygon(Roi[] rois, int sliceIndex) { if (rois[sliceIndex] == null || !(rois[sliceIndex] instanceof PolygonRoi)) return null; PolygonRoi roi = (PolygonRoi)rois[sliceIndex]; if (roi.isSplineFit()) { roi = (PolygonRoi)roi.clone(); roi.removeSplineFit(); } return roi.getPolygon(); }
public void adjustmentValueChanged(AdjustmentEvent event) { int sliceNumber = Integer.parseInt(textField.getText()); image.setSlice(sliceNumber); PolygonRoi roi = rois[sliceNumber - 1]; if (roi != null && !roi.isSplineFit()) roi.fitSpline(); if (roi == null) image.killRoi(); else image.setRoi(roi); } }
@Override public boolean supportedType(final PolygonRoi src) { final boolean supportedType = src.getType() == Roi.POLYLINE || src .getType() == Roi.ANGLE || src.getType() == Roi.FREELINE; return supportedType && src.getStrokeWidth() == 0 && !src.isSplineFit(); }
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()); }
public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange()==ItemEvent.SELECTED; ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {checkbox.setState(false); return;}; Roi roi = imp.getRoi(); int type = roi!=null?roi.getType():null; if (roi==null || !(roi instanceof PolygonRoi) || type==Roi.FREEROI || type==Roi.FREELINE || type==Roi.ANGLE) { checkbox.setState(false); return; }; PolygonRoi poly = (PolygonRoi)roi; boolean splineFit = poly.isSplineFit(); if (selected && !splineFit) { poly.fitSpline(); Prefs.splineFitLines = true; imp.draw(); } else if (!selected && splineFit) { poly.removeSplineFit(); Prefs.splineFitLines = false; imp.draw(); } }
public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange()==ItemEvent.SELECTED; ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {checkbox.setState(false); return;}; Roi roi = imp.getRoi(); int type = roi!=null?roi.getType():null; if (roi==null || !(roi instanceof PolygonRoi) || type==Roi.FREEROI || type==Roi.FREELINE || type==Roi.ANGLE) { checkbox.setState(false); return; }; PolygonRoi poly = (PolygonRoi)roi; boolean splineFit = poly.isSplineFit(); if (selected && !splineFit) { poly.fitSpline(); Prefs.splineFitLines = true; imp.draw(); } else if (!selected && splineFit) { poly.removeSplineFit(); Prefs.splineFitLines = false; imp.draw(); } }
double[] getWideLineProfile(ImagePlus imp, int lineWidth) { Roi roi = (Roi)imp.getRoi().clone(); ImageProcessor ip2 = (new Straightener()).straightenLine(imp, lineWidth); int width = ip2.getWidth(); int height = ip2.getHeight(); if (ip2 instanceof FloatProcessor) return getColumnAverageProfile(new Rectangle(0,0,width,height),ip2); profile = new double[width]; double[] aLine; ip2.setInterpolate(false); for (int y=0; y<height; y++) { aLine = ip2.getLine(0, y, width-1, y); for (int i=0; i<width; i++) profile[i] += aLine[i]; } for (int i=0; i<width; i++) profile[i] /= height; imp.setRoi(roi); if (roi.getType()==Roi.POLYLINE&& !((PolygonRoi)roi).isSplineFit()) { ((PolygonRoi)roi).fitSpline(); imp.draw(); } return profile; }
protected static float[] getProfile(ImageProcessor ip, PolygonRoi roi, boolean fitSpline, int lineWidth) { if (fitSpline && !roi.isSplineFit()) { roi = (PolygonRoi)roi.clone(); roi.fitSpline(); } ImagePlus dummy = new ImagePlus("dummy", ip); dummy.setRoi(roi); Straightener straightener = new Straightener(); ip = straightener.straightenLine(dummy, lineWidth); int w = ip.getWidth(); float[] result = new float[w]; // need to average explicitely for (int j = 0; j < w; j++) { float value = ip.getf(j, 0); for (int k = 1; k < lineWidth; k++) value += ip.getf(j, k); result[j] = value / lineWidth; } return result; } }
ignoreClipRect = true; updateClipRect(); if ((lineWidth>1 && isLine()) || ignoreClipRect || ((this instanceof PolygonRoi)&&((PolygonRoi)this).isSplineFit())) imp.draw(); else
double[] getWideLineProfile(ImagePlus imp, int lineWidth) { Roi roi = (Roi)imp.getRoi().clone(); ImageProcessor ip2 = (new Straightener()).straightenLine(imp, lineWidth); int width = ip2.getWidth(); int height = ip2.getHeight(); if (ip2 instanceof FloatProcessor) return getColumnAverageProfile(new Rectangle(0,0,width,height),ip2); profile = new double[width]; double[] aLine; ip2.setInterpolate(false); for (int y=0; y<height; y++) { aLine = ip2.getLine(0, y, width-1, y); for (int i=0; i<width; i++) profile[i] += aLine[i]; } for (int i=0; i<width; i++) profile[i] /= height; imp.setRoi(roi); if (roi.getType()==Roi.POLYLINE&& !((PolygonRoi)roi).isSplineFit()) { ((PolygonRoi)roi).fitSpline(); imp.draw(); } return profile; }
void areaToLine(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) { IJ.error("Area to Line", "Area selection required"); return; } Undo.setup(Undo.ROI, imp); Polygon p = roi.getPolygon(); if (p==null) return; int type1 = roi.getType(); if (type1==Roi.COMPOSITE) { IJ.error("Area to Line", "Composite selections cannot be converted to lines."); return; } int type2 = Roi.POLYLINE; if (type1==Roi.OVAL||type1==Roi.FREEROI||type1==Roi.TRACED_ROI ||((roi instanceof PolygonRoi)&&((PolygonRoi)roi).isSplineFit())) type2 = Roi.FREELINE; Roi roi2 = new PolygonRoi(p.xpoints, p.ypoints, p.npoints, type2); transferProperties(roi, roi2); imp.setRoi(roi2); }
void areaToLine(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) { IJ.error("Area to Line", "Area selection required"); return; } Undo.setup(Undo.ROI, imp); Polygon p = roi.getPolygon(); if (p==null) return; int type1 = roi.getType(); if (type1==Roi.COMPOSITE) { IJ.error("Area to Line", "Composite selections cannot be converted to lines."); return; } int type2 = Roi.POLYLINE; if (type1==Roi.OVAL||type1==Roi.FREEROI||type1==Roi.TRACED_ROI ||((roi instanceof PolygonRoi)&&((PolygonRoi)roi).isSplineFit())) type2 = Roi.FREELINE; Roi roi2 = new PolygonRoi(p.xpoints, p.ypoints, p.npoints, type2); transferProperties(roi, roi2); imp.setRoi(roi2); }