예제 #1
0
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    if (imp == null) {
      IJ.noImage();
      return;
    }

    ImageStack stack1 = imp.getStack();
    String fileName = imp.getTitle();
    int endslice = stack1.getSize();

    ImagePlus imp2 = duplicateStack(imp);
    imp2.show();
    String duplicateName = imp2.getTitle();
    // IJ.showMessage("Box",fileName);
    ImageStack stack2 = imp2.getStack();
    stack1.deleteSlice(1);
    stack2.deleteSlice(endslice);

    String calculatorstring =
        ("image1='"
            + fileName
            + "' operation=Subtract image2="
            + imp2.getTitle()
            + " create stack");

    IJ.run("Image Calculator...", calculatorstring);
    ImagePlus imp3 = WindowManager.getCurrentImage();
    imp3.setTitle(fileName + " DeltaF up");
    imp2.getWindow().close();
    imp.getWindow().close();
  }
예제 #2
0
 public void run(String arg) {
   imp = WindowManager.getCurrentImage();
   if (arg.equals("add")) {
     addToRoiManager(imp);
     return;
   }
   if (imp == null) {
     IJ.noImage();
     return;
   }
   if (arg.equals("all")) imp.setRoi(0, 0, imp.getWidth(), imp.getHeight());
   else if (arg.equals("none")) imp.killRoi();
   else if (arg.equals("restore")) imp.restoreRoi();
   else if (arg.equals("spline")) fitSpline();
   else if (arg.equals("circle")) fitCircle(imp);
   else if (arg.equals("ellipse")) createEllipse(imp);
   else if (arg.equals("hull")) convexHull(imp);
   else if (arg.equals("mask")) createMask(imp);
   else if (arg.equals("from")) createSelectionFromMask(imp);
   else if (arg.equals("inverse")) invert(imp);
   else if (arg.equals("toarea")) lineToArea(imp);
   else if (arg.equals("toline")) areaToLine(imp);
   else if (arg.equals("properties")) {
     setProperties("Properties ", imp.getRoi());
     imp.draw();
   } else if (arg.equals("band")) makeBand(imp);
   else if (arg.equals("tobox")) toBoundingBox(imp);
   else runMacro(arg);
 }
 public int setup(String arg, ImagePlus imp) {
   this.arg = arg;
   this.imp = imp;
   IJ.register(ParticleAnalyzer.class);
   if (imp == null) {
     IJ.noImage();
     return DONE;
   }
   if (imp.getBitDepth() == 24 && !isThresholdedRGB(imp)) {
     IJ.error(
         "Particle Analyzer",
         "RGB images must be thresholded using\n" + "Image>Adjust>Color Threshold.");
     return DONE;
   }
   if (!showDialog()) return DONE;
   int baseFlags = DOES_ALL + NO_CHANGES + NO_UNDO;
   int flags = IJ.setupDialog(imp, baseFlags);
   processStack = (flags & DOES_STACKS) != 0;
   slice = 0;
   saveRoi = imp.getRoi();
   if (saveRoi != null && saveRoi.getType() != Roi.RECTANGLE && saveRoi.isArea())
     polygon = saveRoi.getPolygon();
   imp.startTiming();
   nextFontSize = defaultFontSize;
   nextLineWidth = 1;
   return flags;
 }
예제 #4
0
  public boolean beadCalibration3d() {
    imp = IJ.getImage();
    if (imp == null) {
      IJ.noImage();
      return false;
    } else if (imp.getStackSize() == 1) {
      IJ.error("Stack required");
      return false;
    } else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16) {
      // In order to support 32bit images, pict[] must be changed to float[], and  getPixel(x, y);
      // requires a Float.intBitsToFloat() conversion
      IJ.error("8 or 16 bit greyscale image required");
      return false;
    }
    width = imp.getWidth();
    height = imp.getHeight();
    nslices = imp.getStackSize();
    imtitle = imp.getTitle();

    models[0] = "*None*";
    models[1] = "line";
    models[2] = "2nd degree polynomial";
    models[3] = "3rd degree polynomial";
    models[4] = "4th degree polynomial";

    GenericDialog gd = new GenericDialog("3D PALM calibration");
    gd.addNumericField("Maximum FWHM (in px)", prefs.get("QuickPALM.3Dcal_fwhm", 20), 0);
    gd.addNumericField(
        "Particle local threshold (% maximum intensity)", prefs.get("QuickPALM.pthrsh", 20), 0);
    gd.addNumericField("Z-spacing (nm)", prefs.get("QuickPALM.z-step", 10), 2);
    gd.addNumericField("Calibration Z-smoothing (radius)", prefs.get("QuickPALM.window", 1), 0);
    gd.addChoice("Model", models, prefs.get("QuickPALM.model", models[3]));
    gd.addCheckbox(
        "Show divergence of bead positions against model",
        prefs.get("QuickPALM.3Dcal_showDivergence", false));
    gd.addCheckbox("Show extra particle info", prefs.get("QuickPALM.3Dcal_showExtraInfo", false));
    gd.addMessage("\n\nDon't forget to save the table in the end...");
    gd.showDialog();
    if (gd.wasCanceled()) return false;
    fwhm = gd.getNextNumber();
    prefs.set("QuickPALM.QuickPALM.3Dcal_fwhm", fwhm);
    pthrsh = gd.getNextNumber() / 100;
    prefs.set("QuickPALM.pthrsh", pthrsh * 100);
    cal_z = gd.getNextNumber();
    prefs.set("QuickPALM.z-step", cal_z);
    window = (int) gd.getNextNumber();
    prefs.set("QuickPALM.window", window);
    model = gd.getNextChoice();
    prefs.set("QuickPALM.model", model);
    part_divergence = gd.getNextBoolean();
    prefs.set("QuickPALM.3Dcal_showDivergence", part_divergence);
    part_extrainfo = gd.getNextBoolean();
    prefs.set("QuickPALM.3Dcal_showExtraInfo", part_extrainfo);
    return true;
  }
예제 #5
0
 public void run(String arg) {
   imp = WindowManager.getCurrentImage();
   if (imp == null) {
     IJ.noImage();
     return;
   }
   ImageStack stack = imp.getStack();
   int size = stack.getSize();
   if (size == 1 || (imp.getNChannels() == size && imp.isComposite())) {
     IJ.error("Stack or hyperstack required");
     return;
   }
   if (!showDialog(stack)) return;
   if (hyperstack) reduceHyperstack(imp, factor, reduceSlices);
   else reduceStack(imp, factor);
 }
예제 #6
0
 public void run(String arg) {
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp == null) {
     IJ.noImage();
     return;
   }
   if (imp.getStackSize() > 1) {
     IJ.error("This command requires a montage");
     return;
   }
   GenericDialog gd = new GenericDialog("Stack Maker");
   gd.addNumericField("Images_per_row: ", w, 0);
   gd.addNumericField("Images_per_column: ", h, 0);
   gd.addNumericField("Border width: ", b, 0);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   w = (int) gd.getNextNumber();
   h = (int) gd.getNextNumber();
   b = (int) gd.getNextNumber();
   ImageStack stack = makeStack(imp.getProcessor(), w, h, b);
   new ImagePlus("Stack", stack).show();
 }
예제 #7
0
  public boolean showDialog() {

    String bgChoice = "NoBg";
    int[] wList = WindowManager.getIDList();
    if (wList == null) {
      IJ.noImage();
      return false;
    }

    String[] sampleTitles = new String[wList.length];
    for (int i = 0; i < wList.length; i++) {
      ImagePlus imp = WindowManager.getImage(wList[i]);
      sampleTitles[i] = imp != null ? imp.getTitle() : "";
    }
    String[] bgTitles = new String[wList.length + 1];
    bgTitles[0] = "NoBg";
    for (int i = 1; i < wList.length + 1; i++) {
      bgTitles[i] = sampleTitles[i - 1];
    }
    for (int i = 1; i < (wList.length + 1); i++) {
      if (bgTitles[i] == bgStackTitle) bgChoice = bgStackTitle;
    }
    String sampleChoice = sampleTitles[0];
    for (int i = 1; i < (wList.length); i++) {
      if (sampleTitles[i] == sampleStackTitle) sampleChoice = sampleStackTitle;
    }

    String[] mirrors = new String[2];
    mirrors[0] = "No";
    mirrors[1] = "Yes";

    GenericDialog gd = new GenericDialog("PolScope 5Frame Calc");
    gd.addChoice("Sample:", sampleTitles, sampleChoice);
    gd.addChoice("Background:", bgTitles, bgChoice);
    gd.addChoice("Mirror:", mirrors, mirror);
    gd.addNumericField("Wavelength: ", wavelength, 1, 8, " nm");
    gd.addNumericField("Swing: ", swing, 3, 8, " wavelength");
    gd.addNumericField("Ret. Ceiling: ", retCeiling, 1, 8, " nm");
    gd.addNumericField("Orient. Ref.: ", azimRef, 1, 8, " degree");
    gd.showDialog();
    if (gd.wasCanceled()) return false;
    int index1 = gd.getNextChoiceIndex();
    int index2 = gd.getNextChoiceIndex();
    int index3 = gd.getNextChoiceIndex();
    wavelength = (float) gd.getNextNumber();
    swing = (float) gd.getNextNumber();
    retCeiling = (float) gd.getNextNumber();
    azimRef = (float) gd.getNextNumber();

    imp1 = WindowManager.getImage(wList[index1]);
    sampleStackTitle = sampleTitles[index1];
    bgStackTitle = bgTitles[index2];
    if (bgStackTitle == "NoBg") {
      imp2 =
          WindowManager.getImage(
              wList[
                  index1]); // only to assign a valid ImagePlus to imp2 which is not used when NoBg
    } else {
      imp2 = WindowManager.getImage(wList[index2 - 1]);
    }
    mirror = mirrors[index3];

    return true;
  }
예제 #8
0
  /*------------------------------------------------------------------*/
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    this.imp = imp;
    if (imp == null) {
      IJ.noImage();
      return;
    }
    if ((1 < imp.getStackSize()) && (imp.getType() == imp.COLOR_256)) {
      IJ.error("Stack of color images not supported (use grayscale)");
      return;
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isRGB()) {
        IJ.error("RGB color images not supported (use grayscale)");
        return;
      }
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isHSB()) {
        IJ.error("HSB color images not supported (use grayscale)");
        return;
      }
    }
    if (imp.getType() == imp.COLOR_256) {
      IJ.error("Indexed color images not supported (use grayscale)");
      return;
    }
    if (imp.getType() == imp.COLOR_RGB) {
      IJ.error("Color images not supported (use grayscale)");
      return;
    }

    differentialsDialog dialog =
        new differentialsDialog(IJ.getInstance(), "Differentials", true, operation);
    GUI.center(dialog);
    dialog.setVisible(true);
    cancel = dialog.getCancel();
    operation = dialog.getOperation();
    dialog.dispose();
    if (cancel) {
      return;
    }

    imp.startTiming();
    if (1 < imp.getStackSize()) {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new StackConverter(imp).convertToGray32();
      }
    } else {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new ImageConverter(imp).convertToGray32();
      }
    }
    ImageStack stack = imp.getStack();
    stackSize = stack.getSize();
    Undo.reset();

    setupProgressBar();
    resetProgressBar();

    for (int i = 1; (i <= stackSize); i++) {
      ImageProcessor ip = stack.getProcessor(i);
      doIt(ip);
      imp.getProcessor().resetMinAndMax();
      imp.setSlice(i);
      imp.updateAndRepaintWindow();
    }
    imp.getProcessor().resetMinAndMax();
    imp.setSlice(1);
    imp.updateAndRepaintWindow();
    cleanUpProgressBar();
    IJ.showTime(imp, imp.getStartTime(), "Differentials: ");
    ImageWindow win = imp.getWindow();
    if (win != null) {
      win.running = false;
    }
  } /* end run */
예제 #9
0
  public void run(String arg) {
    imp = IJ.getImage();
    int stackSize = imp.getStackSize();
    if (imp == null) {
      IJ.noImage();
      return;
    }

    //  Make sure input image is a stack.
    if (stackSize == 1) {
      IJ.error("Z Project", "Stack required");
      return;
    }

    //  Check for inverting LUT.
    if (imp.getProcessor().isInvertedLut()) {
      if (!IJ.showMessageWithCancel("ZProjection", lutMessage)) return;
    }

    // Set default bounds.
    int channels = imp.getNChannels();
    int frames = imp.getNFrames();
    int slices = imp.getNSlices();
    isHyperstack =
        imp.isHyperStack()
            || (ij.macro.Interpreter.isBatchMode()
                && ((frames > 1 && frames < stackSize) || (slices > 1 && slices < stackSize)));
    boolean simpleComposite = channels == stackSize;
    if (simpleComposite) isHyperstack = false;
    startSlice = 1;
    if (isHyperstack) {
      int nSlices = imp.getNSlices();
      if (nSlices > 1) stopSlice = nSlices;
      else stopSlice = imp.getNFrames();
    } else stopSlice = stackSize;

    // Build control dialog
    GenericDialog gd = buildControlDialog(startSlice, stopSlice);
    gd.showDialog();
    if (gd.wasCanceled()) return;

    if (!imp.lock()) return; // exit if in use
    long tstart = System.currentTimeMillis();
    setStartSlice((int) gd.getNextNumber());
    setStopSlice((int) gd.getNextNumber());
    method = gd.getNextChoiceIndex();
    Prefs.set(METHOD_KEY, method);
    if (isHyperstack) {
      allTimeFrames = imp.getNFrames() > 1 && imp.getNSlices() > 1 ? gd.getNextBoolean() : false;
      doHyperStackProjection(allTimeFrames);
    } else if (imp.getType() == ImagePlus.COLOR_RGB) doRGBProjection(true);
    else doProjection(true);

    if (arg.equals("") && projImage != null) {
      long tstop = System.currentTimeMillis();
      projImage.setCalibration(imp.getCalibration());
      if (simpleComposite) IJ.run(projImage, "Grays", "");
      projImage.show("ZProjector: " + IJ.d2s((tstop - tstart) / 1000.0, 2) + " seconds");
    }

    imp.unlock();
    IJ.register(ZProjector.class);
    return;
  }