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 addImage() { ImagePlus imp = IJ.getImage(); int[] wList = WindowManager.getIDList(); if (wList == null || wList.length < 2) { IJ.error("Add Image...", "The command requires at least two open images."); return; } String[] titles = new String[wList.length]; for (int i = 0; i < wList.length; i++) { ImagePlus imp2 = WindowManager.getImage(wList[i]); titles[i] = imp2 != null ? imp2.getTitle() : ""; } int x = 0, y = 0; Roi roi = imp.getRoi(); if (roi != null && roi.isArea()) { Rectangle r = roi.getBounds(); x = r.x; y = r.y; } int index = 0; if (wList.length == 2) { ImagePlus i1 = WindowManager.getImage(wList[0]); ImagePlus i2 = WindowManager.getImage(wList[1]); if (i2.getWidth() < i1.getWidth() && i2.getHeight() < i1.getHeight()) index = 1; } else if (imp.getID() == wList[0]) index = 1; GenericDialog gd = new GenericDialog("Add Image..."); gd.addChoice("Image to add:", titles, titles[index]); gd.addNumericField("X location:", x, 0); gd.addNumericField("Y location:", y, 0); gd.addNumericField("Opacity (0-100%):", 100, 0); gd.addCheckbox("Create image selection", createImageRoi); gd.showDialog(); if (gd.wasCanceled()) return; index = gd.getNextChoiceIndex(); x = (int) gd.getNextNumber(); y = (int) gd.getNextNumber(); double opacity = gd.getNextNumber() / 100.0; createImageRoi = gd.getNextBoolean(); ImagePlus overlay = WindowManager.getImage(wList[index]); if (wList.length == 2) { ImagePlus i1 = WindowManager.getImage(wList[0]); ImagePlus i2 = WindowManager.getImage(wList[1]); if (i2.getWidth() < i1.getWidth() && i2.getHeight() < i1.getHeight()) { imp = i1; overlay = i2; } } if (overlay == imp) { IJ.error( "Add Image...", "Image to be added cannot be the same as\n\"" + imp.getTitle() + "\"."); return; } if (overlay.getWidth() > imp.getWidth() && overlay.getHeight() > imp.getHeight()) { IJ.error( "Add Image...", "Image to be added cannnot be larger than\n\"" + imp.getTitle() + "\"."); return; } if (createImageRoi && x == 0 && y == 0) { x = imp.getWidth() / 2 - overlay.getWidth() / 2; y = imp.getHeight() / 2 - overlay.getHeight() / 2; } roi = new ImageRoi(x, y, overlay.getProcessor()); roi.setName(overlay.getShortTitle()); if (opacity != 1.0) ((ImageRoi) roi).setOpacity(opacity); if (createImageRoi) imp.setRoi(roi); else { Overlay overlayList = imp.getOverlay(); if (overlayList == null) overlayList = new Overlay(); overlayList.add(roi); imp.setOverlay(overlayList); overlay2 = overlayList; Undo.setup(Undo.OVERLAY_ADDITION, imp); } }