Ejemplo n.º 1
0
 /**
  * Builds dialog to query users for projection parameters.
  *
  * @param start starting slice to display
  * @param stop last slice
  */
 protected GenericDialog buildControlDialog(int start, int stop) {
   GenericDialog gd = new GenericDialog("ZProjection", IJ.getInstance());
   gd.addNumericField("Start slice:", startSlice, 0 /*digits*/);
   gd.addNumericField("Stop slice:", stopSlice, 0 /*digits*/);
   gd.addChoice("Projection type", METHODS, METHODS[method]);
   if (isHyperstack && imp.getNFrames() > 1 && imp.getNSlices() > 1)
     gd.addCheckbox("All time frames", allTimeFrames);
   return gd;
 }
Ejemplo n.º 2
0
 /** Quit using a separate thread, hopefully avoiding thread deadlocks. */
 public void run() {
   quitting = true;
   boolean changes = false;
   int[] wList = WindowManager.getIDList();
   if (wList != null) {
     for (int i = 0; i < wList.length; i++) {
       ImagePlus imp = WindowManager.getImage(wList[i]);
       if (imp != null && imp.changes == true) {
         changes = true;
         break;
       }
     }
   }
   Frame[] frames = WindowManager.getNonImageWindows();
   if (frames != null) {
     for (int i = 0; i < frames.length; i++) {
       if (frames[i] != null && (frames[i] instanceof Editor)) {
         if (((Editor) frames[i]).fileChanged()) {
           changes = true;
           break;
         }
       }
     }
   }
   if (windowClosed
       && !changes
       && Menus.window.getItemCount() > Menus.WINDOW_MENU_ITEMS
       && !(IJ.macroRunning() && WindowManager.getImageCount() == 0)) {
     GenericDialog gd = new GenericDialog("ImageJ", this);
     gd.addMessage("Are you sure you want to quit ImageJ?");
     gd.showDialog();
     quitting = !gd.wasCanceled();
     windowClosed = false;
   }
   if (!quitting) return;
   if (!WindowManager.closeAllWindows()) {
     quitting = false;
     return;
   }
   // IJ.log("savePreferences");
   if (applet == null) {
     saveWindowLocations();
     Prefs.savePreferences();
   }
   IJ.cleanup();
   // setVisible(false);
   // IJ.log("dispose");
   dispose();
   if (exitWhenQuitting) System.exit(0);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 // Conversion Options
 void conversions() {
   double[] weights = ColorProcessor.getWeightingFactors();
   boolean weighted = !(weights[0] == 1d / 3d && weights[1] == 1d / 3d && weights[2] == 1d / 3d);
   // boolean weighted = !(Math.abs(weights[0]-1d/3d)<0.0001 && Math.abs(weights[1]-1d/3d)<0.0001
   // && Math.abs(weights[2]-1d/3d)<0.0001);
   GenericDialog gd = new GenericDialog("Conversion Options");
   gd.addCheckbox("Scale when converting", ImageConverter.getDoScaling());
   String prompt = "Weighted RGB conversions";
   if (weighted)
     prompt +=
         " (" + IJ.d2s(weights[0]) + "," + IJ.d2s(weights[1]) + "," + IJ.d2s(weights[2]) + ")";
   gd.addCheckbox(prompt, weighted);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   ImageConverter.setDoScaling(gd.getNextBoolean());
   Prefs.weightedColor = gd.getNextBoolean();
   if (!Prefs.weightedColor) ColorProcessor.setWeightingFactors(1d / 3d, 1d / 3d, 1d / 3d);
   else if (Prefs.weightedColor && !weighted)
     ColorProcessor.setWeightingFactors(0.299, 0.587, 0.114);
   return;
 }
Ejemplo n.º 5
0
 private void makeBand(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Make Band");
     return;
   }
   if (!roi.isArea()) {
     IJ.error("Make Band", "Area selection required");
     return;
   }
   Calibration cal = imp.getCalibration();
   double pixels = bandSize;
   double size = pixels * cal.pixelWidth;
   int decimalPlaces = 0;
   if ((int) size != size) decimalPlaces = 2;
   GenericDialog gd = new GenericDialog("Make Band");
   gd.addNumericField("Band Size:", size, decimalPlaces, 4, cal.getUnits());
   gd.showDialog();
   if (gd.wasCanceled()) return;
   size = gd.getNextNumber();
   if (Double.isNaN(size)) {
     IJ.error("Make Band", "invalid number");
     return;
   }
   int n = (int) Math.round(size / cal.pixelWidth);
   if (n > 255) {
     IJ.error("Make Band", "Cannot make bands wider that 255 pixels");
     return;
   }
   int width = imp.getWidth();
   int height = imp.getHeight();
   Rectangle r = roi.getBounds();
   ImageProcessor ip = roi.getMask();
   if (ip == null) {
     ip = new ByteProcessor(r.width, r.height);
     ip.invert();
   }
   ImageProcessor mask = new ByteProcessor(width, height);
   mask.insert(ip, r.x, r.y);
   ImagePlus edm = new ImagePlus("mask", mask);
   boolean saveBlackBackground = Prefs.blackBackground;
   Prefs.blackBackground = false;
   IJ.run(edm, "Distance Map", "");
   Prefs.blackBackground = saveBlackBackground;
   ip = edm.getProcessor();
   ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
   int xx = -1, yy = -1;
   for (int x = r.x; x < r.x + r.width; x++) {
     for (int y = r.y; y < r.y + r.height; y++) {
       if (ip.getPixel(x, y) < n) {
         xx = x;
         yy = y;
         break;
       }
     }
     if (xx >= 0 || yy >= 0) break;
   }
   int count = IJ.doWand(edm, xx, yy, 0, null);
   if (count <= 0) {
     IJ.error("Make Band", "Unable to make band");
     return;
   }
   ShapeRoi roi2 = new ShapeRoi(edm.getRoi());
   if (!(roi instanceof ShapeRoi)) roi = new ShapeRoi(roi);
   ShapeRoi roi1 = (ShapeRoi) roi;
   roi2 = roi2.not(roi1);
   imp.setRoi(roi2);
   bandSize = n;
 }
Ejemplo n.º 6
0
  // Input/Output options
  void io() {
    GenericDialog gd = new GenericDialog("I/O Options");
    gd.addNumericField("JPEG quality (0-100):", FileSaver.getJpegQuality(), 0, 3, "");
    gd.addNumericField("GIF and PNG transparent index:", Prefs.getTransparentIndex(), 0, 3, "");
    gd.addStringField(
        "File extension for tables (.txt, .xls or .csv):", Prefs.get("options.ext", ".csv"), 4);
    gd.addCheckbox("Use JFileChooser to open/save", Prefs.useJFileChooser);
    if (!IJ.isMacOSX())
      gd.addCheckbox("Use_file chooser to import sequences", Prefs.useFileChooser);
    gd.addCheckbox("Save TIFF and raw in Intel byte order", Prefs.intelByteOrder);
    gd.addCheckbox("Skip dialog when opening .raw files", Prefs.skipRawDialog);

    gd.setInsets(15, 20, 0);
    gd.addMessage("Results Table Options");
    gd.setInsets(3, 40, 0);
    gd.addCheckbox("Copy_column headers", Prefs.copyColumnHeaders);
    gd.setInsets(0, 40, 0);
    gd.addCheckbox("Copy_row numbers", !Prefs.noRowNumbers);
    gd.setInsets(0, 40, 0);
    gd.addCheckbox("Save_column headers", !Prefs.dontSaveHeaders);
    gd.setInsets(0, 40, 0);
    gd.addCheckbox("Save_row numbers", !Prefs.dontSaveRowNumbers);

    gd.showDialog();
    if (gd.wasCanceled()) return;
    int quality = (int) gd.getNextNumber();
    if (quality < 0) quality = 0;
    if (quality > 100) quality = 100;
    FileSaver.setJpegQuality(quality);
    int transparentIndex = (int) gd.getNextNumber();
    Prefs.setTransparentIndex(transparentIndex);
    String extension = gd.getNextString();
    if (!extension.startsWith(".")) extension = "." + extension;
    Prefs.set("options.ext", extension);
    Prefs.useJFileChooser = gd.getNextBoolean();
    if (!IJ.isMacOSX()) Prefs.useFileChooser = gd.getNextBoolean();
    Prefs.intelByteOrder = gd.getNextBoolean();
    Prefs.skipRawDialog = gd.getNextBoolean();
    Prefs.copyColumnHeaders = gd.getNextBoolean();
    Prefs.noRowNumbers = !gd.getNextBoolean();
    Prefs.dontSaveHeaders = !gd.getNextBoolean();
    Prefs.dontSaveRowNumbers = !gd.getNextBoolean();
    return;
  }
Ejemplo n.º 7
0
  // Miscellaneous Options
  void miscOptions() {
    String key = IJ.isMacintosh() ? "command" : "control";
    GenericDialog gd = new GenericDialog("Miscellaneous Options", IJ.getInstance());
    gd.addStringField("Divide by zero value:", "" + FloatBlitter.divideByZeroValue, 10);
    gd.addCheckbox("Use pointer cursor", Prefs.usePointerCursor);
    gd.addCheckbox("Hide \"Process Stack?\" dialog", IJ.hideProcessStackDialog);
    gd.addCheckbox("Require " + key + " key for shortcuts", Prefs.requireControlKey);
    gd.addCheckbox("Move isolated plugins to Misc. menu", Prefs.moveToMisc);
    if (!IJ.isMacOSX()) gd.addCheckbox("Run single instance listener", Prefs.runSocketListener);
    gd.addCheckbox("Enhanced line tool", Prefs.enhancedLineTool);
    gd.addCheckbox("Reverse CZT order of \">\" and \"<\"", Prefs.reverseNextPreviousOrder);
    gd.addCheckbox("Debug mode", IJ.debugMode);
    gd.addHelp(IJ.URL + "/docs/menus/edit.html#misc");
    gd.showDialog();
    if (gd.wasCanceled()) return;

    String divValue = gd.getNextString();
    if (divValue.equalsIgnoreCase("infinity") || divValue.equalsIgnoreCase("infinite"))
      FloatBlitter.divideByZeroValue = Float.POSITIVE_INFINITY;
    else if (divValue.equalsIgnoreCase("NaN")) FloatBlitter.divideByZeroValue = Float.NaN;
    else if (divValue.equalsIgnoreCase("max")) FloatBlitter.divideByZeroValue = Float.MAX_VALUE;
    else {
      Float f;
      try {
        f = new Float(divValue);
      } catch (NumberFormatException e) {
        f = null;
      }
      if (f != null) FloatBlitter.divideByZeroValue = f.floatValue();
    }
    IJ.register(FloatBlitter.class);

    Prefs.usePointerCursor = gd.getNextBoolean();
    IJ.hideProcessStackDialog = gd.getNextBoolean();
    Prefs.requireControlKey = gd.getNextBoolean();
    Prefs.moveToMisc = gd.getNextBoolean();
    if (!IJ.isMacOSX()) Prefs.runSocketListener = gd.getNextBoolean();
    Prefs.enhancedLineTool = gd.getNextBoolean();
    Prefs.reverseNextPreviousOrder = gd.getNextBoolean();
    IJ.setDebugMode(gd.getNextBoolean());
  }
Ejemplo n.º 8
0
 // DICOM options
 void dicom() {
   GenericDialog gd = new GenericDialog("DICOM Options");
   gd.addCheckbox("Open as 32-bit float", Prefs.openDicomsAsFloat);
   // gd.addCheckbox("Calculate voxel depth", Prefs.calculateDicomVoxelDepth);
   gd.addMessage("Orthogonal Views");
   gd.setInsets(5, 40, 0);
   gd.addCheckbox("Rotate YZ", Prefs.rotateYZ);
   gd.setInsets(0, 40, 0);
   gd.addCheckbox("Flip XZ", Prefs.flipXZ);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   Prefs.openDicomsAsFloat = gd.getNextBoolean();
   // Prefs.calculateDicomVoxelDepth = gd.getNextBoolean();
   Prefs.rotateYZ = gd.getNextBoolean();
   Prefs.flipXZ = gd.getNextBoolean();
 }
Ejemplo n.º 9
0
  private boolean showDialog() {
    String[] types = {"RAW", "JPEG", "ZLIB"};
    GenericDialog gd = new GenericDialog("Generate Bricks");
    gd.addChoice("FileType", types, filetype);
    gd.addNumericField("JPEG quality", jpeg_quality, 0);
    gd.addNumericField("Max file size (MB)", bdsizelimit, 0);

    int[] wlist = WindowManager.getIDList();
    if (wlist == null) return false;

    String[] titles = new String[wlist.length];
    for (int i = 0; i < wlist.length; i++) titles[i] = "";

    int tnum = 0;
    for (int i = 0; i < wlist.length; i++) {
      ImagePlus imp = WindowManager.getImage(wlist[i]);
      if (imp != null) {
        titles[tnum] = imp.getTitle();
        tnum++;
      }
    }
    gd.addChoice("Source image: ", titles, titles[0]);

    gd.showDialog();
    if (gd.wasCanceled()) return false;

    filetype = types[gd.getNextChoiceIndex()];
    jpeg_quality = (int) gd.getNextNumber();
    if (jpeg_quality > 100) jpeg_quality = 100;
    if (jpeg_quality < 0) jpeg_quality = 0;
    bdsizelimit = (int) gd.getNextNumber();

    int id = gd.getNextChoiceIndex();
    lvImgTitle = new ArrayList<String>();
    lvImgTitle.add(titles[id]);

    Prefs.set("filetype.string", filetype);
    Prefs.set("jpeg_quality.int", jpeg_quality);
    Prefs.set("bdsizelimit.int", bdsizelimit);

    return true;
  }
Ejemplo n.º 10
0
  public boolean analyseParticles(MyFunctions f) {
    GenericDialog gd = new GenericDialog("Analyse PALM/STORM Particles");
    gd.addNumericField("Minimum SNR", prefs.get("QuickPALM.snr", 5), 2);
    gd.addNumericField("Maximum FWHM (in px)", prefs.get("QuickPALM.fwhm", 4), 0);
    gd.addNumericField("Image plane pixel size (nm)", prefs.get("QuickPALM.pixelsize", 106), 2);
    gd.addCheckbox("Smart SNR", prefs.get("QuickPALM.smartsnr", true));
    gd.addCheckbox(
        "3D PALM (astigmatism) - will require calibration file",
        prefs.get("QuickPALM.is3d", false));
    gd.addCheckbox("Online rendering", prefs.get("QuickPALM.view", true));
    gd.addCheckbox("Attach to running acquisition", prefs.get("QuickPALM.attach", false));
    gd.addCheckbox("Stream particle info directly into file", prefs.get("QuickPALM.stream", true));
    gd.addMessage("\n");
    // -----------------------------------------
    gd.addMessage("-- Online rendering settings (used only if selected) --");
    gd.addMessage("\n");
    gd.addNumericField("Pixel size of rendered image (nm)", 30, 2);
    gd.addNumericField("Accumulate last (0 to accumulate all frames)", 0, 0);
    gd.addNumericField("Update every (frames)", 10, 0);
    // gd.addNumericField("Allow color saturation (%)", 50, 0);
    gd.addMessage("\n");
    // -----------------------------------------
    gd.addMessage("-- Attach to running acquisition settings (used only if selected) --");
    gd.addMessage("\n");
    gd.addStringField(
        "_Image name pattern (NN...NN represents the numerical change)",
        prefs.get("QuickPALM.pattern", "imgNNNNNNNNN.tif"),
        20);
    gd.addNumericField("Start NN...NN with", 0, 0);
    gd.addNumericField("In acquisition max. wait time for new image (ms)", 50, 0);
    gd.addMessage("\n");
    // -----------------------------------------
    gd.addMessage("-- Advanced settings (don't normally need to be changed) --");
    gd.addMessage("\n");
    gd.addNumericField("_Minimum symmetry (%)", prefs.get("QuickPALM.symmetry", 50), 0);
    gd.addNumericField(
        "Local threshold (% maximum intensity)", prefs.get("QuickPALM.lthreshold", 20), 0);
    gd.addNumericField("_Maximum iterations per frame", prefs.get("QuickPALM.maxiter", 1000), 0);
    gd.addNumericField(
        "Threads (each takes ~3*[frame size] in memory)", prefs.get("QuickPALM.nthreads", 50), 0);
    gd.addMessage("\n\nDon't forget to save the table in the end...");

    gd.showDialog();
    if (gd.wasCanceled()) return false;

    snr = (int) gd.getNextNumber();
    prefs.set("QuickPALM.snr", snr);
    fwhm = gd.getNextNumber();
    prefs.set("QuickPALM.fwhm", fwhm);
    pixelsize = gd.getNextNumber();
    prefs.set("QuickPALM.pixelsize", pixelsize);

    smartsnr = gd.getNextBoolean();
    prefs.set("QuickPALM.smartsnr", smartsnr);
    is3d = gd.getNextBoolean();
    prefs.set("QuickPALM.is3d", is3d);
    view = gd.getNextBoolean();
    prefs.set("QuickPALM.view", view);
    attach = gd.getNextBoolean();
    prefs.set("QuickPALM.attach", attach);

    if (gd.getNextBoolean()) {
      f.psave = new ParticleSaver();
      f.psave.setup();
      prefs.set("QuickPALM.stream", true);
    } else prefs.set("QuickPALM.stream", false);
    // --

    magn = pixelsize / gd.getNextNumber();
    viewer_accumulate = (int) gd.getNextNumber();
    viewer_update = (int) gd.getNextNumber();

    // --
    pattern = gd.getNextString().trim();
    prefs.set("QuickPALM.pattern", pattern);
    prefix = pattern.substring(0, pattern.indexOf("N"));
    sufix = pattern.substring(pattern.lastIndexOf("N") + 1, pattern.length());
    nimchars = pattern.split("N").length - 1;
    nimstart = (int) gd.getNextNumber();
    waittime = (int) gd.getNextNumber();

    // --

    symmetry = gd.getNextNumber() / 100;
    prefs.set("QuickPALM.symmetry", symmetry);
    pthrsh = gd.getNextNumber() / 100;
    prefs.set("QuickPALM.lthreshold", pthrsh * 100);
    maxpart = (int) gd.getNextNumber();
    prefs.set("QuickPALM.maxiter", maxpart);
    threads = (int) gd.getNextNumber();
    prefs.set("QuickPALM.nthreads", threads);

    return true;
  }
Ejemplo n.º 11
0
  public boolean reconstructDataset() {

    view_modes[0] = "3D color";
    view_modes[1] = "2D histogram";
    view_modes[2] = "2D particle intensity (16-bit)";
    view_modes[3] = "2D particle intensity (8-bit)";

    GenericDialog gd = new GenericDialog("Reconstruct PALM/STORM Dataset");
    gd.addNumericField(
        "Target pixel size for the rendered image (nm)",
        prefs.get("QuickPALM.viewer_tpixelsize", 30),
        2);
    gd.addNumericField("Original image width (px)", prefs.get("QuickPALM.viewer_owidth", 512), 2);
    gd.addNumericField("Original image height (px)", prefs.get("QuickPALM.viewer_oheight", 512), 2);
    gd.addChoice("View mode", view_modes, prefs.get("QuickPALM.view_mode", view_modes[1]));
    // gd.addNumericField("Allow image saturation (%)", prefs.get("QuickPALM.saturation", 50), 0);

    gd.addCheckbox(
        "Simulate sub-difraction spot (gaussian convolution - only 2D)",
        prefs.get("QuickPALM.viewer_doConvolve", true));
    // gd.addCheckbox("Make 3D stack", prefs.get("QuickPALM.viewer_do3d", false));
    // gd.addCheckbox("Make movie", prefs.get("QuickPALM.viewer_doMovie", false));
    gd.addCheckbox("Make 3D stack", false);
    gd.addCheckbox("Make movie", false);
    // gd.addCheckbox("Save only and don't show", prefs.get("QuickPALM.viewer_doSave", false));
    gd.addMessage("\n");

    // -----------------------------------------
    gd.addMessage("-- Simulate sub-difraction spot settings (used only if selected) --");
    gd.addNumericField("FWHM of the spot", prefs.get("QuickPALM.viewer_fwhm", 30), 2);
    gd.addMessage("\n");

    // -----------------------------------------
    gd.addMessage("-- Make 3D stack settings (used only if selected) --");
    gd.addNumericField("Z-spacing between slices (nm)", prefs.get("QuickPALM.viewer_zstep", 50), 2);
    gd.addNumericField(
        "Merge particle Z-position above (nm - 0 for full Z range)",
        prefs.get("QuickPALM.viewer_mergeabove", 0),
        2);
    gd.addNumericField(
        "Merge particle Z-position bellow (nm - 0 for full Z range)",
        prefs.get("QuickPALM.viewer_mergebellow", 0),
        2);
    gd.addMessage("\n");

    // -----------------------------------------
    gd.addMessage("-- Make movie settings (used only if selected) --");
    gd.addNumericField(
        "Make a reconstruction in every N frames", prefs.get("QuickPALM.viewer_update", 10), 0);
    gd.addNumericField(
        "Accumulate N neighboring frames for each reconstruction\n(set to 0 to accumulate all the preceding frames)",
        prefs.get("QuickPALM.viewer_accumulate", 100),
        0);

    gd.showDialog();
    if (gd.wasCanceled()) return false;

    viewer_tpixelsize = gd.getNextNumber();
    prefs.set("QuickPALM.viewer_tpixelsize", viewer_tpixelsize);
    viewer_owidth = (int) gd.getNextNumber();
    prefs.set("QuickPALM.viewer_owidth", viewer_owidth);
    viewer_oheight = (int) gd.getNextNumber();
    prefs.set("QuickPALM.viewer_oheight", viewer_oheight);
    view_mode = gd.getNextChoice();
    prefs.set("QuickPALM.view_mode", view_mode);

    viewer_doConvolve = gd.getNextBoolean();
    prefs.set("QuickPALM.viewer_doConvolve", viewer_doConvolve);
    viewer_do3d = gd.getNextBoolean();
    prefs.set("QuickPALM.viewer_do3d", viewer_do3d);
    viewer_doMovie = gd.getNextBoolean();
    prefs.set("QuickPALM.viewer_doMovie", viewer_doMovie);
    // viewer_doSave = gd.getNextBoolean();
    // prefs.set("QuickPALM.viewer_doSave", viewer_doSave);

    // -- Simulate sub-difraction spot
    viewer_fwhm = gd.getNextNumber();
    prefs.set("QuickPALM.viewer_fwhm", viewer_fwhm);

    // -- Show B&W
    // viewer_is8bit = gd.getNextBoolean();
    // prefs.set("QuickPALM.viewer_is8bit", viewer_is8bit);

    // -- Make 3D stack
    viewer_zstep = gd.getNextNumber();
    prefs.set("QuickPALM.viewer_zstep", viewer_zstep);
    viewer_mergeabove = gd.getNextNumber();
    prefs.set("QuickPALM.viewer_mergeabove", viewer_mergeabove);
    viewer_mergebellow = gd.getNextNumber();
    prefs.set("QuickPALM.viewer_mergebellow", viewer_mergebellow);

    // -- Make Movie
    viewer_update = (int) gd.getNextNumber();
    prefs.set("QuickPALM.viewer_update", viewer_update);
    viewer_accumulate = (int) gd.getNextNumber();
    prefs.set("QuickPALM.viewer_accumulate", viewer_accumulate);

    return true;
  }
Ejemplo n.º 12
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;
  }
Ejemplo n.º 13
0
  /** Ask for parameters and then execute. */
  public void run(String arg) {
    // 1 - Obtain the currently active image:
    ImagePlus imp = IJ.getImage();

    if (null == imp) {
      IJ.showMessage("There must be at least one image open");
      return;
    }

    if (imp.getBitDepth() != 8) {
      IJ.showMessage("Error", "Only 8-bit images are supported");
      return;
    }

    // 2 - Ask for parameters:
    GenericDialog gd = new GenericDialog("Auto Local Threshold");
    String[] methods = {
      "Try all",
      "Bernsen",
      "Contrast",
      "Mean",
      "Median",
      "MidGrey",
      "Niblack",
      "Otsu",
      "Phansalkar",
      "Sauvola"
    };
    gd.addMessage("Auto Local Threshold v1.5");
    gd.addChoice("Method", methods, methods[0]);
    gd.addNumericField("Radius", 15, 0);
    gd.addMessage("Special paramters (if different from default)");
    gd.addNumericField("Parameter_1", 0, 0);
    gd.addNumericField("Parameter_2", 0, 0);
    gd.addCheckbox("White objects on black background", true);
    if (imp.getStackSize() > 1) {
      gd.addCheckbox("Stack", false);
    }
    gd.addMessage("Thresholded result is always shown in white [255].");
    gd.showDialog();
    if (gd.wasCanceled()) return;

    // 3 - Retrieve parameters from the dialog
    String myMethod = gd.getNextChoice();
    int radius = (int) gd.getNextNumber();
    double par1 = (double) gd.getNextNumber();
    double par2 = (double) gd.getNextNumber();
    boolean doIwhite = gd.getNextBoolean();
    boolean doIstack = false;

    int stackSize = imp.getStackSize();
    if (stackSize > 1) doIstack = gd.getNextBoolean();

    // 4 - Execute!
    // long start = System.currentTimeMillis();
    if (myMethod.equals("Try all")) {
      ImageProcessor ip = imp.getProcessor();
      int xe = ip.getWidth();
      int ye = ip.getHeight();
      int ml = methods.length;
      ImagePlus imp2, imp3;
      ImageStack tstack = null, stackNew;
      if (stackSize > 1 && doIstack) {
        boolean doItAnyway = true;
        if (stackSize > 25) {
          YesNoCancelDialog d =
              new YesNoCancelDialog(
                  IJ.getInstance(),
                  "Auto Local Threshold",
                  "You might run out of memory.\n \nDisplay "
                      + stackSize
                      + " slices?\n \n \'No\' will process without display and\noutput results to the log window.");
          if (!d.yesPressed()) {
            //						doIlog=true; //will show in the log window
            doItAnyway = false;
          }
          if (d.cancelPressed()) return;
        }

        for (int j = 1; j <= stackSize; j++) {
          imp.setSlice(j);
          ip = imp.getProcessor();
          tstack = new ImageStack(xe, ye);
          for (int k = 1; k < ml; k++) tstack.addSlice(methods[k], ip.duplicate());
          imp2 = new ImagePlus("Auto Threshold", tstack);
          imp2.updateAndDraw();

          for (int k = 1; k < ml; k++) {
            imp2.setSlice(k);
            Object[] result = exec(imp2, methods[k], radius, par1, par2, doIwhite);
          }
          // if (doItAnyway){
          CanvasResizer cr = new CanvasResizer();
          stackNew = cr.expandStack(tstack, (xe + 2), (ye + 18), 1, 1);
          imp3 = new ImagePlus("Auto Threshold", stackNew);
          imp3.updateAndDraw();
          MontageMaker mm = new MontageMaker();
          mm.makeMontage(imp3, 3, 3, 1.0, 1, (ml - 1), 1, 0, true); // 3 columns and 3 rows
        }
        imp.setSlice(1);
        // if (doItAnyway)
        IJ.run("Images to Stack", "method=[Copy (center)] title=Montage");
        return;
      } else { // single image try all
        tstack = new ImageStack(xe, ye);
        for (int k = 1; k < ml; k++) tstack.addSlice(methods[k], ip.duplicate());
        imp2 = new ImagePlus("Auto Threshold", tstack);
        imp2.updateAndDraw();

        for (int k = 1; k < ml; k++) {
          imp2.setSlice(k);
          // IJ.log("analyzing slice with "+methods[k]);
          Object[] result = exec(imp2, methods[k], radius, par1, par2, doIwhite);
        }
        // imp2.setSlice(1);
        CanvasResizer cr = new CanvasResizer();
        stackNew = cr.expandStack(tstack, (xe + 2), (ye + 18), 1, 1);
        imp3 = new ImagePlus("Auto Threshold", stackNew);
        imp3.updateAndDraw();
        MontageMaker mm = new MontageMaker();
        mm.makeMontage(imp3, 3, 3, 1.0, 1, (ml - 1), 1, 0, true);
        return;
      }
    } else { // selected a method
      if (stackSize > 1 && doIstack) { // whole stack
        //				if (doIstackHistogram) {// one global histogram
        //					Object[] result = exec(imp, myMethod, noWhite, noBlack, doIwhite, doIset, doIlog,
        // doIstackHistogram );
        //				}
        //				else{ // slice by slice
        for (int k = 1; k <= stackSize; k++) {
          imp.setSlice(k);
          Object[] result = exec(imp, myMethod, radius, par1, par2, doIwhite);
        }
        //				}
        imp.setSlice(1);
      } else { // just one slice
        Object[] result = exec(imp, myMethod, radius, par1, par2, doIwhite);
      }
      // 5 - If all went well, show the image:
      // not needed here as the source image is binarised
    }
  }
Ejemplo n.º 14
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;
  }