// Added by Marcel Boeglin 2013.09.22 private Overlay projectHyperStackRois(Overlay overlay) { if (overlay == null) return null; int t1 = imp.getFrame(); int channels = projImage.getNChannels(); int slices = 1; int frames = projImage.getNFrames(); Overlay overlay2 = new Overlay(); Roi roi; int c, z, t; int size = channels * slices * frames; for (Roi r : overlay.toArray()) { c = r.getCPosition(); z = r.getZPosition(); t = r.getTPosition(); roi = (Roi) r.clone(); if (size == channels) { // current time frame if (z >= startSlice && z <= stopSlice && t == t1 || c == 0) { roi.setPosition(c); overlay2.add(roi); } } else if (size == frames * channels) { // all time frames if (z >= startSlice && z <= stopSlice) roi.setPosition(c, 1, t); else if (z == 0) roi.setPosition(c, 0, t); else continue; overlay2.add(roi); } } return overlay2; }
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); } } }
void drawAllROIs(Graphics g) { RoiManager rm = RoiManager.getInstance(); if (rm == null) { rm = Interpreter.getBatchModeRoiManager(); if (rm != null && rm.getList().getItemCount() == 0) rm = null; } if (rm == null) { // if (showAllList!=null) // overlay = showAllList; showAllROIs = false; repaint(); return; } initGraphics(g, null, showAllColor); Hashtable rois = rm.getROIs(); java.awt.List list = rm.getList(); boolean drawLabels = rm.getDrawLabels(); currentRoi = null; int n = list.getItemCount(); if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs"); if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n]; if (!drawLabels) showAllList = new Overlay(); else showAllList = null; if (imp == null) return; int currentImage = imp.getCurrentSlice(); int channel = 0, slice = 0, frame = 0; boolean hyperstack = imp.isHyperStack(); if (hyperstack) { channel = imp.getChannel(); slice = imp.getSlice(); frame = imp.getFrame(); } drawNames = Prefs.useNamesAsLabels; for (int i = 0; i < n; i++) { String label = list.getItem(i); Roi roi = (Roi) rois.get(label); if (roi == null) continue; if (showAllList != null) showAllList.add(roi); if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi; if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) { if (hyperstack && roi.getPosition() == 0) { int c = roi.getCPosition(); int z = roi.getZPosition(); int t = roi.getTPosition(); if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame)) drawRoi(g, roi, drawLabels ? i : -1); } else { int position = roi.getPosition(); if (position == 0) position = getSliceNumber(roi.getName()); if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1); } } else drawRoi(g, roi, drawLabels ? i : -1); } ((Graphics2D) g).setStroke(Roi.onePixelWide); drawNames = false; }
/** Return the ROI Manager "Show All" list as an overlay. */ public Overlay getShowAllList() { if (!showAllROIs) return null; if (showAllList != null) return showAllList; RoiManager rm = RoiManager.getInstance(); if (rm == null) return null; Roi[] rois = rm.getRoisAsArray(); if (rois.length == 0) return null; Overlay overlay = new Overlay(); for (int i = 0; i < rois.length; i++) overlay.add((Roi) rois[i].clone()); return overlay; }
/** @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); }
void addSelection() { ImagePlus imp = IJ.getImage(); String macroOptions = Macro.getOptions(); if (macroOptions != null && IJ.macroRunning() && macroOptions.indexOf("remove") != -1) { imp.setOverlay(null); return; } Roi roi = imp.getRoi(); if (roi == null && imp.getOverlay() != null) { GenericDialog gd = new GenericDialog("No Selection"); gd.addMessage("\"Overlay>Add\" requires a selection."); gd.setInsets(15, 40, 0); gd.addCheckbox("Remove existing overlay", false); gd.showDialog(); if (gd.wasCanceled()) return; if (gd.getNextBoolean()) imp.setOverlay(null); return; } if (roi == null) { IJ.error("This command requires a selection."); return; } roi = (Roi) roi.clone(); if (roi.getStrokeColor() == null) roi.setStrokeColor(Toolbar.getForegroundColor()); int width = Line.getWidth(); Rectangle bounds = roi.getBounds(); boolean tooWide = width > Math.max(bounds.width, bounds.height) / 3.0; if (roi.getStroke() == null && width > 1 && !tooWide) roi.setStrokeWidth(Line.getWidth()); Overlay overlay = imp.getOverlay(); if (overlay != null && overlay.size() > 0 && !roi.isDrawingTool()) { Roi roi2 = overlay.get(overlay.size() - 1); if (roi.getStroke() == null) roi.setStrokeWidth(roi2.getStrokeWidth()); if (roi.getFillColor() == null) roi.setFillColor(roi2.getFillColor()); } boolean points = roi instanceof PointRoi && ((PolygonRoi) roi).getNCoordinates() > 1; if (points) roi.setStrokeColor(Color.red); if (!IJ.altKeyDown() && !(roi instanceof Arrow)) { RoiProperties rp = new RoiProperties("Add to Overlay", roi); if (!rp.showDialog()) return; } String name = roi.getName(); boolean newOverlay = name != null && name.equals("new-overlay"); if (overlay == null || newOverlay) overlay = new Overlay(); overlay.add(roi); imp.setOverlay(overlay); overlay2 = overlay; if (points || (roi instanceof ImageRoi) || (roi instanceof Arrow)) imp.killRoi(); Undo.setup(Undo.OVERLAY_ADDITION, imp); }
// Added by Marcel Boeglin 2013.09.23 private Overlay projectStackRois(Overlay overlay) { if (overlay == null) return null; Overlay overlay2 = new Overlay(); Roi roi; int s; for (Roi r : overlay.toArray()) { s = r.getPosition(); roi = (Roi) r.clone(); if (s >= startSlice && s <= stopSlice || s == 0) { roi.setPosition(s); overlay2.add(roi); } } return overlay2; }
void fromRoiManager() { ImagePlus imp = IJ.getImage(); RoiManager rm = RoiManager.getInstance(); if (rm == null) { IJ.error("ROI Manager is not open"); return; } Roi[] rois = rm.getRoisAsArray(); if (rois.length == 0) { IJ.error("ROI Manager is empty"); return; } Overlay overlay = new Overlay(); for (int i = 0; i < rois.length; i++) overlay.add((Roi) rois[i].clone()); imp.setOverlay(overlay); ImageCanvas ic = imp.getCanvas(); if (ic != null) ic.setShowAllROIs(false); rm.setEditMode(imp, false); imp.killRoi(); }
// Added by Marcel Boeglin 2013.09.22 private Overlay projectRGBHyperStackRois(Overlay overlay) { if (overlay == null) return null; int frames = projImage.getNFrames(); int t1 = imp.getFrame(); Overlay overlay2 = new Overlay(); Roi roi; int c, z, t; for (Roi r : overlay.toArray()) { c = r.getCPosition(); z = r.getZPosition(); t = r.getTPosition(); roi = (Roi) r.clone(); if (z >= startSlice && z <= stopSlice || z == 0 || c == 0 || t == 0) { if (frames == 1 && t != t1 && t != 0) // current time frame continue; roi.setPosition(t); overlay2.add(roi); } } return overlay2; }
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); } }
/** @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); }