public void run(String arg) {
   ImagePlus[] imps = jutils.selectImages(false, 2, new String[] {"Histogram", "Image"});
   if (imps == null) return;
   ImageWindow iw = imps[0].getWindow();
   int[] indices = (int[]) jutils.runReflectionMethod(iw, "getroiindices", null);
   if (indices == null) {
     IJ.error("Select Roi First");
     return;
   }
   int width = imps[1].getWidth();
   int height = imps[1].getHeight();
   int[] mask = new int[width * height];
   // for(int i=0;i<mask.length;i++) mask[i]=0xff000000;
   for (int i = 0; i < indices.length; i++) mask[indices[i]] = 0xffff0000;
   ColorProcessor cp = new ColorProcessor(width, height, mask);
   ImageRoi roi = new ImageRoi(0, 0, cp);
   roi.setZeroTransparent(true);
   imps[1].setOverlay(new Overlay(roi));
 }
Esempio n. 2
0
 void runMacro(String arg, ImagePlus imp) {
   boolean rotate = arg.equals("rotate");
   Roi roi = imp.getRoi();
   if (rotate && IJ.macroRunning()) {
     String options = Macro.getOptions();
     if (options != null
         && (options.indexOf("grid=") != -1 || options.indexOf("interpolat") != -1)) {
       IJ.run("Rotate... ", options); // run Image>Transform>Rotate
       return;
     }
   }
   if (roi == null) {
     noRoi(rotate ? "Rotate" : "Enlarge");
     return;
   }
   double dangle = Tools.parseDouble(angle);
   if (Double.isNaN(dangle)) {
     dangle = 15;
     angle = "" + dangle;
   }
   if (rotate && (roi instanceof ImageRoi)) {
     dangle = IJ.getNumber("Angle (degrees):", dangle);
     ((ImageRoi) roi).rotate(dangle);
     imp.draw();
     angle = "" + dangle;
     return;
   }
   Undo.setup(Undo.ROI, imp);
   roi = (Roi) roi.clone();
   if (rotate) {
     String value = IJ.runMacroFile("ij.jar:RotateSelection", angle);
     Roi roi2 = imp.getRoi();
     transferProperties(roi, roi2);
     imp.setRoi(roi2);
     if (value != null) angle = value;
   } else if (arg.equals("enlarge")) (new RoiEnlarger()).run("");
 }
Esempio n. 3
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);
    }
  }