/* Wraps everything into a Cell Manager Class*/
 private CellManager toCellManager(ImagePlus imp, ArrayList<PolygonRoi> rois, ImagePlus av_imp) {
   CellManager cm = new CellManager(av_imp, imp, this.ovr);
   Iterator itr = rois.iterator();
   ArrayList<Double> av_sig = new ArrayList<>();
   PolygonRoi roi;
   while (itr.hasNext()) {
     roi = (PolygonRoi) itr.next();
     av_sig = Activity_Analysis.getAverageSignal(imp, roi);
     CalciumSignal ca_sig = new CalciumSignal(av_sig, this.dt_r);
     ovr.add(roi);
     ca_sig.DeltaF();
     cm.addCell(ca_sig, roi);
   }
   //            catch(Exception e){
   //                IJ.showMessage(e.getMessage());
   //            }
   //        }
   ovr.setLabelColor(Color.WHITE);
   //        ovr.setFillColor(Color.GREEN);
   ovr.setStrokeColor(Color.getHSBColor(100, 30, 87));
   av_imp.setOverlay(ovr);
   av_imp.show();
   IJ.run("In [+]", "");
   IJ.run("In [+]", "");
   return cm;
 }
Example #2
0
 // 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);
     }
   }
 }
 /** @deprecated replaced by ImagePlus.setOverlay(ij.gui.Overlay) */
 public void setDisplayList(Vector list) {
   if (list != null) {
     Overlay list2 = new Overlay();
     list2.setVector(list);
     setOverlay(list2);
   } else setOverlay(null);
   if (overlay != null)
     overlay.drawLabels(overlay.size() > 0 && overlay.get(0).getStrokeColor() == null);
   else customRoi = false;
   repaint();
 }
 /** 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);
 }
Example #7
0
 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);
 }
Example #8
0
 // 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;
 }
Example #9
0
 @Override
 protected void paintComponent(Graphics g) {
   BufferedImage image = theImage.getImage();
   if (image != null) {
     Graphics2D gg = (Graphics2D) g.create();
     overlay.paint(gg, image, theImage.getImageTransform());
     gg.dispose();
   }
 }
Example #10
0
 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;
 }
Example #11
0
 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();
 }
Example #12
0
 private boolean deleteOverlayRoi(ImagePlus imp) {
   if (imp == null) return false;
   Overlay overlay = null;
   ImageCanvas ic = imp.getCanvas();
   if (ic != null) overlay = ic.getShowAllList();
   if (overlay == null) overlay = imp.getOverlay();
   if (overlay == null) return false;
   Roi roi = imp.getRoi();
   for (int i = 0; i < overlay.size(); i++) {
     Roi roi2 = overlay.get(i);
     if (roi2 == roi) {
       overlay.remove(i);
       imp.deleteRoi();
       ic = imp.getCanvas();
       if (ic != null) ic.roiManagerSelect(roi, true);
       return true;
     }
   }
   return false;
 }
Example #13
0
 // 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;
 }
Example #14
0
 void toRoiManager() {
   ImagePlus imp = IJ.getImage();
   Overlay overlay = imp.getOverlay();
   if (overlay == null) {
     IJ.error("Overlay required");
     return;
   }
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) {
     if (Macro.getOptions() != null && Interpreter.isBatchMode())
       rm = Interpreter.getBatchModeRoiManager();
     if (rm == null) {
       Frame frame = WindowManager.getFrame("ROI Manager");
       if (frame == null) IJ.run("ROI Manager...");
       frame = WindowManager.getFrame("ROI Manager");
       if (frame == null || !(frame instanceof RoiManager)) return;
       rm = (RoiManager) frame;
     }
   }
   rm.runCommand("reset");
   for (int i = 0; i < overlay.size(); i++) rm.add(imp, overlay.get(i), i);
   rm.setEditMode(imp, true);
   if (rm.getCount() == overlay.size()) imp.setOverlay(null);
 }
Example #15
0
 void drawOverlay(Graphics g) {
   if (imp != null && imp.getHideOverlay()) return;
   Color labelColor = overlay.getLabelColor();
   if (labelColor == null) labelColor = Color.white;
   initGraphics(g, labelColor, Roi.getColor());
   int n = overlay.size();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " ROI display list");
   int currentImage = imp != null ? imp.getCurrentSlice() : -1;
   if (imp.getStackSize() == 1) currentImage = -1;
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = overlay.getDrawNames();
   boolean drawLabels = drawNames || overlay.getDrawLabels();
   for (int i = 0; i < n; i++) {
     if (overlay == null) break;
     Roi roi = overlay.get(i);
     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 + LIST_OFFSET : -1);
     } else {
       int position = roi.getPosition();
       if (position == 0 || position == currentImage)
         drawRoi(g, roi, drawLabels ? i + LIST_OFFSET : -1);
     }
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
Example #16
0
 void initGraphics(Graphics g, Color textColor, Color defaultColor) {
   if (smallFont == null) {
     smallFont = new Font("SansSerif", Font.PLAIN, 9);
     largeFont = new Font("SansSerif", Font.PLAIN, 12);
   }
   if (textColor != null) {
     labelColor = textColor;
     if (overlay != null && overlay.getDrawBackgrounds())
       bgColor =
           new Color(
               255 - labelColor.getRed(), 255 - labelColor.getGreen(), 255 - labelColor.getBlue());
     else bgColor = null;
   } else {
     int red = defaultColor.getRed();
     int green = defaultColor.getGreen();
     int blue = defaultColor.getBlue();
     if ((red + green + blue) / 3 < 128) labelColor = Color.white;
     else labelColor = Color.black;
     bgColor = defaultColor;
   }
   this.defaultColor = defaultColor;
   g.setColor(defaultColor);
 }
Example #17
0
  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);
    }
  }
Example #18
0
 /** Use ImagePlus.setOverlay(ij.gui.Overlay). */
 public void setOverlay(Overlay overlay) {
   this.overlay = overlay;
   if (overlay != null) font = overlay.getLabelsFont();
   repaint();
 }
Example #19
0
  String getInfo(ImagePlus imp, ImageProcessor ip) {
    String s = new String("\n");
    s += "Title: " + imp.getTitle() + "\n";
    Calibration cal = imp.getCalibration();
    int stackSize = imp.getStackSize();
    int channels = imp.getNChannels();
    int slices = imp.getNSlices();
    int frames = imp.getNFrames();
    int digits = imp.getBitDepth() == 32 ? 4 : 0;
    if (cal.scaled()) {
      String unit = cal.getUnit();
      String units = cal.getUnits();
      s +=
          "Width:  "
              + IJ.d2s(imp.getWidth() * cal.pixelWidth, 2)
              + " "
              + units
              + " ("
              + imp.getWidth()
              + ")\n";
      s +=
          "Height:  "
              + IJ.d2s(imp.getHeight() * cal.pixelHeight, 2)
              + " "
              + units
              + " ("
              + imp.getHeight()
              + ")\n";
      if (slices > 1)
        s += "Depth:  " + IJ.d2s(slices * cal.pixelDepth, 2) + " " + units + " (" + slices + ")\n";
      double xResolution = 1.0 / cal.pixelWidth;
      double yResolution = 1.0 / cal.pixelHeight;
      int places = Tools.getDecimalPlaces(xResolution, yResolution);
      if (xResolution == yResolution)
        s += "Resolution:  " + IJ.d2s(xResolution, places) + " pixels per " + unit + "\n";
      else {
        s += "X Resolution:  " + IJ.d2s(xResolution, places) + " pixels per " + unit + "\n";
        s += "Y Resolution:  " + IJ.d2s(yResolution, places) + " pixels per " + unit + "\n";
      }
    } else {
      s += "Width:  " + imp.getWidth() + " pixels\n";
      s += "Height:  " + imp.getHeight() + " pixels\n";
      if (stackSize > 1) s += "Depth:  " + slices + " pixels\n";
    }
    if (stackSize > 1)
      s +=
          "Voxel size: "
              + d2s(cal.pixelWidth)
              + "x"
              + d2s(cal.pixelHeight)
              + "x"
              + d2s(cal.pixelDepth)
              + " "
              + cal.getUnit()
              + "\n";
    else
      s +=
          "Pixel size: "
              + d2s(cal.pixelWidth)
              + "x"
              + d2s(cal.pixelHeight)
              + " "
              + cal.getUnit()
              + "\n";

    s += "ID: " + imp.getID() + "\n";
    String zOrigin = stackSize > 1 || cal.zOrigin != 0.0 ? "," + d2s(cal.zOrigin) : "";
    s += "Coordinate origin:  " + d2s(cal.xOrigin) + "," + d2s(cal.yOrigin) + zOrigin + "\n";
    int type = imp.getType();
    switch (type) {
      case ImagePlus.GRAY8:
        s += "Bits per pixel: 8 ";
        String lut = "LUT";
        if (imp.getProcessor().isColorLut()) lut = "color " + lut;
        else lut = "grayscale " + lut;
        if (imp.isInvertedLut()) lut = "inverting " + lut;
        s += "(" + lut + ")\n";
        if (imp.getNChannels() > 1) s += displayRanges(imp);
        else s += "Display range: " + (int) ip.getMin() + "-" + (int) ip.getMax() + "\n";
        break;
      case ImagePlus.GRAY16:
      case ImagePlus.GRAY32:
        if (type == ImagePlus.GRAY16) {
          String sign = cal.isSigned16Bit() ? "signed" : "unsigned";
          s += "Bits per pixel: 16 (" + sign + ")\n";
        } else s += "Bits per pixel: 32 (float)\n";
        if (imp.getNChannels() > 1) s += displayRanges(imp);
        else {
          s += "Display range: ";
          double min = ip.getMin();
          double max = ip.getMax();
          if (cal.calibrated()) {
            min = cal.getCValue((int) min);
            max = cal.getCValue((int) max);
          }
          s += IJ.d2s(min, digits) + " - " + IJ.d2s(max, digits) + "\n";
        }
        break;
      case ImagePlus.COLOR_256:
        s += "Bits per pixel: 8 (color LUT)\n";
        break;
      case ImagePlus.COLOR_RGB:
        s += "Bits per pixel: 32 (RGB)\n";
        break;
    }
    double interval = cal.frameInterval;
    double fps = cal.fps;
    if (stackSize > 1) {
      ImageStack stack = imp.getStack();
      int slice = imp.getCurrentSlice();
      String number = slice + "/" + stackSize;
      String label = stack.getShortSliceLabel(slice);
      if (label != null && label.length() > 0) label = " (" + label + ")";
      else label = "";
      if (interval > 0.0 || fps != 0.0) {
        s += "Frame: " + number + label + "\n";
        if (fps != 0.0) {
          String sRate =
              Math.abs(fps - Math.round(fps)) < 0.00001 ? IJ.d2s(fps, 0) : IJ.d2s(fps, 5);
          s += "Frame rate: " + sRate + " fps\n";
        }
        if (interval != 0.0)
          s +=
              "Frame interval: "
                  + ((int) interval == interval ? IJ.d2s(interval, 0) : IJ.d2s(interval, 5))
                  + " "
                  + cal.getTimeUnit()
                  + "\n";
      } else s += "Image: " + number + label + "\n";
      if (imp.isHyperStack()) {
        if (channels > 1) s += "  Channel: " + imp.getChannel() + "/" + channels + "\n";
        if (slices > 1) s += "  Slice: " + imp.getSlice() + "/" + slices + "\n";
        if (frames > 1) s += "  Frame: " + imp.getFrame() + "/" + frames + "\n";
      }
      if (imp.isComposite()) {
        if (!imp.isHyperStack() && channels > 1) s += "  Channels: " + channels + "\n";
        String mode = ((CompositeImage) imp).getModeAsString();
        s += "  Composite mode: \"" + mode + "\"\n";
      }
    }

    if (ip.getMinThreshold() == ImageProcessor.NO_THRESHOLD) s += "No Threshold\n";
    else {
      double lower = ip.getMinThreshold();
      double upper = ip.getMaxThreshold();
      int dp = digits;
      if (cal.calibrated()) {
        lower = cal.getCValue((int) lower);
        upper = cal.getCValue((int) upper);
        dp = cal.isSigned16Bit() ? 0 : 4;
      }
      s += "Threshold: " + IJ.d2s(lower, dp) + "-" + IJ.d2s(upper, dp) + "\n";
    }
    ImageCanvas ic = imp.getCanvas();
    double mag = ic != null ? ic.getMagnification() : 1.0;
    if (mag != 1.0) s += "Magnification: " + IJ.d2s(mag, 2) + "\n";

    if (cal.calibrated()) {
      s += " \n";
      int curveFit = cal.getFunction();
      s += "Calibration Function: ";
      if (curveFit == Calibration.UNCALIBRATED_OD) s += "Uncalibrated OD\n";
      else if (curveFit == Calibration.CUSTOM) s += "Custom lookup table\n";
      else s += CurveFitter.fList[curveFit] + "\n";
      double[] c = cal.getCoefficients();
      if (c != null) {
        s += "  a: " + IJ.d2s(c[0], 6) + "\n";
        s += "  b: " + IJ.d2s(c[1], 6) + "\n";
        if (c.length >= 3) s += "  c: " + IJ.d2s(c[2], 6) + "\n";
        if (c.length >= 4) s += "  c: " + IJ.d2s(c[3], 6) + "\n";
        if (c.length >= 5) s += "  c: " + IJ.d2s(c[4], 6) + "\n";
      }
      s += "  Unit: \"" + cal.getValueUnit() + "\"\n";
    } else s += "Uncalibrated\n";

    FileInfo fi = imp.getOriginalFileInfo();
    if (fi != null) {
      if (fi.url != null && !fi.url.equals("")) s += "URL: " + fi.url + "\n";
      else if (fi.directory != null && fi.fileName != null)
        s += "Path: " + fi.directory + fi.fileName + "\n";
    }

    ImageWindow win = imp.getWindow();
    if (win != null) {
      Point loc = win.getLocation();
      Dimension screen = IJ.getScreenSize();
      s +=
          "Screen location: "
              + loc.x
              + ","
              + loc.y
              + " ("
              + screen.width
              + "x"
              + screen.height
              + ")\n";
    }

    Overlay overlay = imp.getOverlay();
    if (overlay != null) {
      String hidden = imp.getHideOverlay() ? " (hidden)" : " ";
      int n = overlay.size();
      String elements = n == 1 ? " element" : " elements";
      s += "Overlay: " + n + elements + (imp.getHideOverlay() ? " (hidden)" : "") + "\n";
    } else s += "No Overlay\n";

    Roi roi = imp.getRoi();
    if (roi == null) {
      if (cal.calibrated()) s += " \n";
      s += "No Selection\n";
    } else if (roi instanceof EllipseRoi) {
      s += "\nElliptical Selection\n";
      double[] p = ((EllipseRoi) roi).getParams();
      double dx = p[2] - p[0];
      double dy = p[3] - p[1];
      double major = Math.sqrt(dx * dx + dy * dy);
      s += "  Major: " + IJ.d2s(major, 2) + "\n";
      s += "  Minor: " + IJ.d2s(major * p[4], 2) + "\n";
      s += "  X1: " + IJ.d2s(p[0], 2) + "\n";
      s += "  Y1: " + IJ.d2s(p[1], 2) + "\n";
      s += "  X2: " + IJ.d2s(p[2], 2) + "\n";
      s += "  Y2: " + IJ.d2s(p[3], 2) + "\n";
      s += "  Aspect ratio: " + IJ.d2s(p[4], 2) + "\n";
    } else {
      s += " \n";
      s += roi.getTypeAsString() + " Selection";
      String points = null;
      if (roi instanceof PointRoi) {
        int npoints = ((PolygonRoi) roi).getNCoordinates();
        String suffix = npoints > 1 ? "s)" : ")";
        points = " (" + npoints + " point" + suffix;
      }
      String name = roi.getName();
      if (name != null) {
        s += " (\"" + name + "\")";
        if (points != null) s += "\n " + points;
      } else if (points != null) s += points;
      s += "\n";
      Rectangle r = roi.getBounds();
      if (roi instanceof Line) {
        Line line = (Line) roi;
        s += "  X1: " + IJ.d2s(line.x1d * cal.pixelWidth) + "\n";
        s += "  Y1: " + IJ.d2s(yy(line.y1d, imp) * cal.pixelHeight) + "\n";
        s += "  X2: " + IJ.d2s(line.x2d * cal.pixelWidth) + "\n";
        s += "  Y2: " + IJ.d2s(yy(line.y2d, imp) * cal.pixelHeight) + "\n";
      } else if (cal.scaled()) {
        s += "  X: " + IJ.d2s(cal.getX(r.x)) + " (" + r.x + ")\n";
        s += "  Y: " + IJ.d2s(cal.getY(r.y, imp.getHeight())) + " (" + r.y + ")\n";
        s += "  Width: " + IJ.d2s(r.width * cal.pixelWidth) + " (" + r.width + ")\n";
        s += "  Height: " + IJ.d2s(r.height * cal.pixelHeight) + " (" + r.height + ")\n";
      } else {
        s += "  X: " + r.x + "\n";
        s += "  Y: " + yy(r.y, imp) + "\n";
        s += "  Width: " + r.width + "\n";
        s += "  Height: " + r.height + "\n";
      }
    }

    return s;
  }
Example #20
0
 /** @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);
 }
Example #21
0
 /** @deprecated replaced by ImagePlus.getOverlay() */
 public Vector getDisplayList() {
   if (overlay == null) return null;
   Vector displayList = new Vector();
   for (int i = 0; i < overlay.size(); i++) displayList.add(overlay.get(i));
   return displayList;
 }