void drawOutline(ImageProcessor ip, Roi roi, int count) { if (showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS) { if (overlay == null) { overlay = new Overlay(); overlay.drawLabels(true); overlay.setLabelFont(new Font("SansSerif", Font.PLAIN, fontSize)); } Roi roi2 = (Roi) roi.clone(); roi2.setStrokeColor(Color.cyan); if (lineWidth != 1) roi2.setStrokeWidth(lineWidth); if (showChoice == OVERLAY_MASKS) roi2.setFillColor(Color.cyan); overlay.add(roi2); } else { Rectangle r = roi.getBounds(); int nPoints = ((PolygonRoi) roi).getNCoordinates(); int[] xp = ((PolygonRoi) roi).getXCoordinates(); int[] yp = ((PolygonRoi) roi).getYCoordinates(); int x = r.x, y = r.y; if (!inSituShow) ip.setValue(0.0); ip.moveTo(x + xp[0], y + yp[0]); for (int i = 1; i < nPoints; i++) ip.lineTo(x + xp[i], y + yp[i]); ip.lineTo(x + xp[0], y + yp[0]); if (showChoice != BARE_OUTLINES) { String s = ResultsTable.d2s(count, 0); ip.moveTo(r.x + r.width / 2 - ip.getStringWidth(s) / 2, r.y + r.height / 2 + fontSize / 2); if (!inSituShow) ip.setValue(1.0); ip.drawString(s); } } }
private void drawRoi(Roi roi, Graphics g) { if (roi == currentRoi) { Color lineColor = roi.getStrokeColor(); Color fillColor = roi.getFillColor(); float lineWidth = roi.getStrokeWidth(); roi.setStrokeColor(null); roi.setFillColor(null); boolean strokeSet = roi.getStroke() != null; if (strokeSet) roi.setStrokeWidth(1); roi.draw(g); roi.setStrokeColor(lineColor); if (strokeSet) roi.setStrokeWidth(lineWidth); roi.setFillColor(fillColor); currentRoi = null; } else roi.draw(g); }
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 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 drawRoi(Graphics g, Roi roi, int index) { int type = roi.getType(); ImagePlus imp2 = roi.getImage(); roi.setImage(imp); Color saveColor = roi.getStrokeColor(); if (saveColor == null) roi.setStrokeColor(defaultColor); if (roi instanceof TextRoi) ((TextRoi) roi).drawText(g); else roi.drawOverlay(g); roi.setStrokeColor(saveColor); if (index >= 0) { if (roi == currentRoi) g.setColor(Roi.getColor()); else g.setColor(defaultColor); drawRoiLabel(g, index, roi); } if (imp2 != null) roi.setImage(imp2); else roi.setImage(null); }
/** @deprecated replaced by ImagePlus.setOverlay(Shape, Color, BasicStroke) */ public void setDisplayList(Shape shape, Color color, BasicStroke stroke) { if (shape == null) { setOverlay(null); return; } Roi roi = new ShapeRoi(shape); roi.setStrokeColor(color); roi.setStroke(stroke); Overlay list = new Overlay(); list.add(roi); setOverlay(list); }
private void transferProperties(Roi roi1, Roi roi2) { if (roi1 == null || roi2 == null) return; roi2.setStrokeColor(roi1.getStrokeColor()); if (roi1.getStroke() != null) roi2.setStroke(roi1.getStroke()); roi2.setDrawOffset(roi1.getDrawOffset()); }
/** @deprecated replaced by ImagePlus.setOverlay(Roi, Color, int, Color) */ public void setDisplayList(Roi roi, Color color) { roi.setStrokeColor(color); Overlay list = new Overlay(); list.add(roi); setOverlay(list); }