void interpolate() { Roi roi = imp.getRoi(); if (roi == null) { noRoi("Interpolate"); return; } if (roi.getType() == Roi.POINT) return; if (IJ.isMacro() && Macro.getOptions() == null) Macro.setOptions("interval=1"); GenericDialog gd = new GenericDialog("Interpolate"); gd.addNumericField("Interval:", 1.0, 1, 4, "pixel"); gd.addCheckbox("Smooth", IJ.isMacro() ? false : smooth); gd.showDialog(); if (gd.wasCanceled()) return; double interval = gd.getNextNumber(); smooth = gd.getNextBoolean(); Undo.setup(Undo.ROI, imp); FloatPolygon poly = roi.getInterpolatedPolygon(interval, smooth); int t = roi.getType(); int type = roi.isLine() ? Roi.FREELINE : Roi.FREEROI; if (t == Roi.POLYGON && interval > 1.0) type = Roi.POLYGON; if ((t == Roi.RECTANGLE || t == Roi.OVAL || t == Roi.FREEROI) && interval >= 5.0) type = Roi.POLYGON; if ((t == Roi.LINE || t == Roi.FREELINE) && interval >= 5.0) type = Roi.POLYLINE; if (t == Roi.POLYLINE && interval >= 1.0) type = Roi.POLYLINE; ImageCanvas ic = imp.getCanvas(); if (poly.npoints <= 150 && ic != null && ic.getMagnification() >= 12.0) type = roi.isLine() ? Roi.POLYLINE : Roi.POLYGON; Roi p = new PolygonRoi(poly, type); if (roi.getStroke() != null) p.setStrokeWidth(roi.getStrokeWidth()); p.setStrokeColor(roi.getStrokeColor()); p.setName(roi.getName()); transferProperties(roi, p); imp.setRoi(p); }
void createEllipse(ImagePlus imp) { IJ.showStatus("Fitting ellipse"); Roi roi = imp.getRoi(); if (roi == null) { noRoi("Fit Ellipse"); return; } if (roi.isLine()) { IJ.error("Fit Ellipse", "\"Fit Ellipse\" does not work with line selections"); return; } ImageProcessor ip = imp.getProcessor(); ip.setRoi(roi); int options = Measurements.CENTROID + Measurements.ELLIPSE; ImageStatistics stats = ImageStatistics.getStatistics(ip, options, null); double dx = stats.major * Math.cos(stats.angle / 180.0 * Math.PI) / 2.0; double dy = -stats.major * Math.sin(stats.angle / 180.0 * Math.PI) / 2.0; double x1 = stats.xCentroid - dx; double x2 = stats.xCentroid + dx; double y1 = stats.yCentroid - dy; double y2 = stats.yCentroid + dy; double aspectRatio = stats.minor / stats.major; imp.killRoi(); imp.setRoi(new EllipseRoi(x1, y1, x2, y2, aspectRatio)); }
void lineToArea(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi == null || !roi.isLine()) { IJ.error("Line to Area", "Line selection required"); return; } Undo.setup(Undo.ROI, imp); Roi roi2 = null; if (roi.getType() == Roi.LINE) { double width = roi.getStrokeWidth(); if (width <= 1.0) roi.setStrokeWidth(1.0000001); FloatPolygon p = roi.getFloatPolygon(); roi.setStrokeWidth(width); roi2 = new PolygonRoi(p, Roi.POLYGON); roi2.setDrawOffset(roi.getDrawOffset()); } else { ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight()); ip2.setColor(255); roi.drawPixels(ip2); // new ImagePlus("ip2", ip2.duplicate()).show(); ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); roi2 = tts.convert(ip2); } transferProperties(roi, roi2); roi2.setStrokeWidth(0); Color c = roi2.getStrokeColor(); if (c != null) // remove any transparency roi2.setStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue())); imp.setRoi(roi2); Roi.previousRoi = (Roi) roi.clone(); }
void lineToArea(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi == null || !roi.isLine()) { IJ.error("Line to Area", "Line selection required"); return; } if (roi.getType() == Roi.LINE && roi.getStrokeWidth() == 1) { IJ.error("Line to Area", "Straight line width must be > 1"); return; } ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight()); ip2.setColor(255); if (roi.getType() == Roi.LINE) ip2.fillPolygon(roi.getPolygon()); else { roi.drawPixels(ip2); // BufferedImage bi = new BufferedImage(imp.getWidth(), imp.getHeight(), // BufferedImage.TYPE_BYTE_GRAY); // Graphics g = bi.getGraphics(); // Roi roi2 = (Roi)roi.clone(); // roi2.setStrokeColor(Color.white); // roi2.drawOverlay(g); // ip2 = new ByteProcessor(bi); } // new ImagePlus("ip2", ip2.duplicate()).show(); ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); Roi roi2 = tts.convert(ip2); imp.setRoi(roi2); Roi.previousRoi = (Roi) roi.clone(); }
void lineWidth() { int width = (int) IJ.getNumber("Line Width:", Line.getWidth()); if (width == IJ.CANCELED) return; Line.setWidth(width); LineWidthAdjuster.update(); ImagePlus imp = WindowManager.getCurrentImage(); if (imp != null && imp.isProcessor()) { ImageProcessor ip = imp.getProcessor(); ip.setLineWidth(Line.getWidth()); Roi roi = imp.getRoi(); if (roi != null && roi.isLine()) imp.draw(); } }
void lineToArea(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi == null || !roi.isLine()) { IJ.error("Line to Area", "Line selection required"); return; } ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight()); ip2.setColor(255); if (roi.getType() == Roi.LINE && roi.getStrokeWidth() > 1) ip2.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip2); // new ImagePlus("ip2", ip2.duplicate()).show(); ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); Roi roi2 = tts.convert(ip2); imp.setRoi(roi2); Roi.previousRoi = (Roi) roi.clone(); }