Esempio n. 1
0
 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
   iterations = (int) gd.getNextNumber();
   count = (int) gd.getNextNumber();
   boolean bb = Prefs.blackBackground;
   Prefs.blackBackground = gd.getNextBoolean();
   if (Prefs.blackBackground != bb) ThresholdAdjuster.update();
   Prefs.padEdges = gd.getNextBoolean();
   EDM.setOutputType(gd.getNextChoiceIndex());
   boolean isInvalid = gd.invalidNumber();
   if (iterations < 1) {
     iterations = 1;
     isInvalid = true;
   }
   if (iterations > MAX_ITERATIONS) {
     iterations = MAX_ITERATIONS;
     isInvalid = true;
   }
   if (count < 1) {
     count = 1;
     isInvalid = true;
   }
   if (count > 8) {
     count = 8;
     isInvalid = true;
   }
   if (isInvalid) return false;
   if (imp != null) {
     operation = gd.getNextChoice();
     arg = operation.toLowerCase();
   }
   return true;
 }
Esempio n. 2
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;
  }
Esempio n. 3
0
 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
   angle = gd.getNextNumber();
   // only check for invalid input to "angle", don't care about gridLines
   if (gd.invalidNumber()) {
     if (gd.wasOKed()) IJ.error("Angle is invalid.");
     return false;
   }
   gridLines = (int) gd.getNextNumber();
   interpolationMethod = gd.getNextChoiceIndex();
   if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean();
   if (canEnlarge) enlarge = gd.getNextBoolean();
   return true;
 }
Esempio n. 4
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);
 }
Esempio n. 5
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;
  }
  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;
  }
Esempio n. 7
0
  public void run(String arg) {
    int[] wList = WindowManager.getIDList();
    if (wList == null) {
      IJ.error("No images are open.");
      return;
    }

    double thalf = 0.5;
    boolean keep;

    GenericDialog gd = new GenericDialog("Bleach correction");

    gd.addNumericField("t½:", thalf, 1);
    gd.addCheckbox("Keep source stack:", true);
    gd.showDialog();
    if (gd.wasCanceled()) return;

    long start = System.currentTimeMillis();
    thalf = gd.getNextNumber();
    keep = gd.getNextBoolean();
    if (keep) IJ.run("Duplicate...", "title='Bleach corrected' duplicate");
    ImagePlus imp1 = WindowManager.getCurrentImage();
    int d1 = imp1.getStackSize();
    double v1, v2;
    int width = imp1.getWidth();
    int height = imp1.getHeight();
    ImageProcessor ip1, ip2, ip3;

    int slices = imp1.getStackSize();
    ImageStack stack1 = imp1.getStack();
    ImageStack stack2 = imp1.getStack();
    int currentSlice = imp1.getCurrentSlice();

    for (int n = 1; n <= slices; n++) {
      ip1 = stack1.getProcessor(n);
      ip3 = stack1.getProcessor(1);
      ip2 = stack2.getProcessor(n);
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          v1 = ip1.getPixelValue(x, y);
          v2 = ip3.getPixelValue(x, y);

          // =B8/(EXP(-C$7*A8))
          v1 = (v1 / Math.exp(-n * thalf));
          ip2.putPixelValue(x, y, v1);
        }
      }
      IJ.showProgress((double) n / slices);
      IJ.showStatus(n + "/" + slices);
    }

    // stack2.show();
    imp1.updateAndDraw();
  }
 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
   checkc2 = gd.getNextBoolean();
   double[] params = new double[10];
   int[] fixes = new int[10];
   for (int i = 0; i < params.length; i++) {
     params[i] = gd.getNextNumber();
     if (gd.getNextBoolean()) {
       fixes[i] = 1;
     } else {
       fixes[i] = 0;
     }
   }
   gd.getNextBoolean();
   gd.getNextNumber();
   gd.getNextNumber();
   NLLSfit_v2 fitclass = new NLLSfit_v2(this, 0);
   double[] stats = new double[2];
   float[] fit = fitclass.fitdata(params, fixes, null, tempdata, null, stats, true);
   pw.updateSeries(fit, series, false);
   c2 = (float) stats[1];
   return true;
 }
Esempio n. 9
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();
 }
Esempio n. 10
0
 public boolean showDialog(ImageStack stack) {
   hyperstack = imp.isHyperStack();
   boolean showCheckbox = false;
   if (hyperstack && imp.getNSlices() > 1 && imp.getNFrames() > 1) showCheckbox = true;
   else if (hyperstack && imp.getNSlices() > 1) reduceSlices = true;
   int n = stack.getSize();
   GenericDialog gd = new GenericDialog("Reduce Size");
   gd.addNumericField("Reduction Factor:", factor, 0);
   if (showCheckbox) gd.addCheckbox("Reduce in Z-Dimension", false);
   gd.showDialog();
   if (gd.wasCanceled()) return false;
   factor = (int) gd.getNextNumber();
   if (showCheckbox) reduceSlices = gd.getNextBoolean();
   return true;
 }
 boolean showoptions(double[] params, int[] fixes) {
   // GenericDialog gd=new NonBlockingGenericDialog("Options");
   GenericDialog gd = new GenericDialog("Options");
   gd.addCheckbox("Check Chi Squared", checkc2);
   for (int i = 0; i < 10; i++) {
     gd.addNumericField("P" + (i + 1), params[i], 5, 10, null);
     gd.addCheckbox("Fix?", (fixes[i] == 1));
   }
   gd.addCheckbox("Get_Errors", false);
   gd.addCheckbox("Set_Constraints", false);
   gd.addNumericField("Iterations", iterations, 0, 10, null);
   gd.addNumericField("chi squared", c2, 5, 10, null);
   gd.addDialogListener(this);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return false;
   }
   checkc2 = gd.getNextBoolean();
   for (int i = 0; i < 10; i++) {
     params[i] = gd.getNextNumber();
     if (gd.getNextBoolean()) {
       fixes[i] = 1;
     } else {
       fixes[i] = 0;
     }
   }
   boolean geterrors = gd.getNextBoolean();
   boolean setconstraints = gd.getNextBoolean();
   for (int i = 0; i < 10; i++) {
     if (function.indexOf("P" + (i + 1)) < 0) {
       fixes[i] = 1;
     }
   }
   if (geterrors) {
     if (!get_errors(params, fixes)) {
       return false;
     }
   }
   if (setconstraints) constraints = get_constraints(params);
   return true;
 }
 public double[][] get_constraints(double[] params) {
   // here we populate the constraints
   GenericDialog gd = new GenericDialog("Constraints");
   for (int i = 0; i < 10; i++) {
     if (constraints == null) {
       gd.addNumericField("P" + (i + 1) + "_upper", params[i], 5, 10, null);
       gd.addNumericField("P" + (i + 1) + "_lower", params[i], 5, 10, null);
     } else {
       gd.addNumericField("P" + (i + 1) + "_upper", constraints[1][i], 5, 10, null);
       gd.addNumericField("P" + (i + 1) + "_lower", constraints[0][i], 5, 10, null);
     }
   }
   gd.showDialog();
   if (gd.wasCanceled()) {
     return null;
   }
   double[][] constraints = new double[2][10];
   for (int i = 0; i < 10; i++) {
     constraints[1][i] = gd.getNextNumber();
     constraints[0][i] = gd.getNextNumber();
   }
   return constraints;
 }
Esempio n. 13
0
  public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
    int width = imp.getWidth();
    int height = imp.getHeight();
    type = gd.getNextChoice();
    areaPerPoint = gd.getNextNumber();
    color = gd.getNextChoice();
    randomOffset = gd.getNextBoolean();

    double minArea = (width * height) / 50000.0;
    if (type.equals(types[1]) && minArea < 144.0) minArea = 144.0;
    else if (minArea < 16) minArea = 16.0;
    if (areaPerPoint / (pixelWidth * pixelHeight) < minArea) {
      String err = "\"Area per Point\" too small";
      if (gd.wasOKed()) IJ.error("Grid", err);
      else IJ.showStatus(err);
      return true;
    }
    double tileSize = Math.sqrt(areaPerPoint);
    tileWidth = tileSize / pixelWidth;
    tileHeight = tileSize / pixelHeight;
    if (randomOffset) {
      xstart = (int) (random.nextDouble() * tileWidth);
      ystart = (int) (random.nextDouble() * tileHeight);
    } else {
      xstart = (int) (tileWidth / 2.0 + 0.5);
      ystart = (int) (tileHeight / 2.0 + 0.5);
    }
    linesV = (int) ((width - xstart) / tileWidth) + 1;
    linesH = (int) ((height - ystart) / tileHeight) + 1;
    if (gd.invalidNumber()) return true;
    if (type.equals(types[0])) drawLines();
    else if (type.equals(types[1])) drawCrosses();
    else if (type.equals(types[2])) drawPoints();
    else showGrid(null);
    return true;
  }
Esempio n. 14
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;
 }
Esempio n. 15
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;
  }
Esempio n. 16
0
  public void run(String arg) {
    GenericDialog gd = new GenericDialog("Options");
    double sfreq = 20000.0;
    gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null);
    String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"};
    gd.addChoice("PSF Type?", psfchoice, psfchoice[0]);
    String[] filetypechoice = {
      "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File"
    };
    gd.addChoice("File Type?", filetypechoice, filetypechoice[0]);
    boolean ch2green = true;
    gd.addCheckbox("Ch2 is green?", ch2green);
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    sfreq = gd.getNextNumber();
    int psfflag = gd.getNextChoiceIndex();
    int fileflag = gd.getNextChoiceIndex();
    ch2green = gd.getNextBoolean();
    int nfiles = 0;
    Object[] histograms = null;
    int xmax = 0;
    int ymax = 0;
    String[] names = null;
    if (fileflag < 2) {
      jdataio ioclass = new jdataio();
      File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance());
      if (filearray.length == 0) {
        return;
      }
      String dir = filearray[0].getAbsolutePath();
      int sepindex = dir.lastIndexOf(File.separator);
      String newdir = dir.substring(0, sepindex + 1);
      OpenDialog.setDefaultDirectory(newdir);
      nfiles = filearray.length / 2;
      if (nfiles > 25) {
        nfiles = 25;
      }
      histograms = new Object[nfiles];
      names = organize_c3_files(filearray);
      for (int i = 0; i < nfiles; i++) {
        try {
          int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0);
          int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0);
          int length3 = (int) (((double) filearray[2 * i].length()) / 2.0);
          int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0);
          InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i]));
          InputStream instream2 =
              new BufferedInputStream(new FileInputStream(filearray[2 * i + 1]));
          if (fileflag == 0) {
            int[] pmdata = new int[length1];
            int[] pmdata2 = new int[length2];
            if (!ioclass.skipstreambytes(instream, 128)) {
              showioerror();
              instream.close();
              return;
            }
            if (!ioclass.skipstreambytes(instream2, 128)) {
              showioerror();
              instream2.close();
              return;
            }
            if (!ioclass.readintelintfile(instream, length1, pmdata)) {
              showioerror();
              instream.close();
              return;
            }
            if (!ioclass.readintelintfile(instream2, length2, pmdata2)) {
              showioerror();
              instream2.close();
              return;
            }
            if (ch2green) {
              histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000);
            } else {
              histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000);
            }
          } else {
            float[] tmdata = new float[length3];
            float[] tmdata2 = new float[length4];
            if (!ioclass.readintelshortfile(instream, length3, tmdata)) {
              showioerror();
              instream.close();
              return;
            }
            if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) {
              showioerror();
              instream2.close();
              return;
            }
            if (ch2green) {
              histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata);
            } else {
              histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2);
            }
          }
          if (((float[][]) histograms[i]).length > xmax) {
            xmax = ((float[][]) histograms[i]).length;
          }
          if (((float[][]) histograms[i])[0].length > ymax) {
            ymax = ((float[][]) histograms[i])[0].length;
          }
          instream.close();
          instream2.close();
        } catch (IOException e) {
          showioerror();
          return;
        }
      }
    } else {
      if (fileflag == 2) {
        ImageWindow iw = WindowManager.getCurrentWindow();
        float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues");
        float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues");
        sfreq = 1.0 / ((double) tempxvals[0][1]);
        nfiles = trajectories.length / 2;
        if (nfiles > 25) {
          nfiles = 25;
        }
        names = new String[nfiles + 1];
        names[nfiles] = "avg";
        histograms = new Object[nfiles];
        for (int i = 0; i < nfiles; i++) {
          names[i] = "trajectory " + (i + 1);
          if (ch2green) {
            histograms[i] =
                (new pmodeconvert())
                    .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]);
          } else {
            histograms[i] =
                (new pmodeconvert())
                    .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]);
          }
          if (((float[][]) histograms[i]).length > xmax) {
            xmax = ((float[][]) histograms[i]).length;
          }
          if (((float[][]) histograms[i])[0].length > ymax) {
            ymax = ((float[][]) histograms[i])[0].length;
          }
        }
      } else {
        // here we read tab delimited lines from files
        jdataio ioclass = new jdataio();
        File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance());
        if (filearray.length == 0) {
          return;
        }
        String dir = filearray[0].getAbsolutePath();
        int sepindex = dir.lastIndexOf(File.separator);
        String newdir = dir.substring(0, sepindex + 1);
        OpenDialog.setDefaultDirectory(newdir);
        nfiles = filearray.length;
        if (nfiles > 25) {
          nfiles = 25;
        }
        histograms = new Object[nfiles];
        names = new String[nfiles + 1];
        names[nfiles] = "avg";
        for (int i = 0; i < nfiles; i++) {
          try {
            names[i] = filearray[i].getName();
            BufferedReader d = new BufferedReader(new FileReader(filearray[i]));
            String[] lines = new String[256];
            int counter = 0;
            do {
              lines[counter] = d.readLine();
              counter++;
            } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256);
            int numcolumns = 0;
            for (int j = 0; j < counter - 1; j++) {
              int temp = getncolumns(lines[j]);
              if (temp > numcolumns) {
                numcolumns = temp;
              }
            }
            float[][] temphist2 = null;
            if (ch2green) {
              temphist2 = new float[numcolumns][counter - 1];
            } else {
              temphist2 = new float[counter - 1][numcolumns];
            }
            for (int k = 0; k < counter - 1; k++) {
              float[] temp = tab_delim2float(lines[k]);
              for (int j = 0; j < numcolumns; j++) {
                if (ch2green) {
                  temphist2[j][k] = temp[j];
                } else {
                  temphist2[k][j] = temp[j];
                }
              }
            }
            histograms[i] = temphist2;
            d.close();
          } catch (IOException e) {
            showioerror();
            return;
          }
        }
        for (int i = 0; i < nfiles; i++) {
          if (((float[][]) histograms[i]).length > xmax) {
            xmax = ((float[][]) histograms[i]).length;
          }
          if (((float[][]) histograms[i])[0].length > ymax) {
            ymax = ((float[][]) histograms[i])[0].length;
          }
        }
      }
    }
    // note that here x is green and y is red
    float[][][] pch = new float[nfiles][xmax][ymax];
    for (int i = 0; i < nfiles; i++) {
      for (int j = 0; j < ((float[][]) histograms[i]).length; j++) {
        for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) {
          pch[i][j][k] = ((float[][]) histograms[i])[j][k];
        }
      }
    }

    final PCH2DFitWindow cw = new PCH2DFitWindow();
    cw.init(names, pch, psfflag);

    final Frame f = new Frame("PCH 2D Analysis");
    f.setLocation(10, 10);
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            f.dispose();
          }
        });

    f.add(cw);
    f.pack();
    f.setResizable(false);
    Insets ins = f.getInsets();
    cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65;
    cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right;
    f.setSize(cw.totalSize);
    f.setVisible(true);
    cw.requestFocus();
  }
Esempio n. 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);
    }
  }
Esempio n. 18
0
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    Calibration cal = imp.getCalibration();
    GenericDialog gd = new GenericDialog("Options");
    int subsize = 32;
    gd.addNumericField("Subregion Size (pixels)?", subsize, 0);
    int stepsize = 16;
    gd.addNumericField("Step Size?", stepsize, 0);
    int shift = 3;
    gd.addNumericField("STICS temporal Shift?", shift, 0);
    float xoffset = 0.0f;
    gd.addNumericField("X_Offset", xoffset, 5, 15, null);
    float yoffset = 0.0f;
    gd.addNumericField("Y_Offset", yoffset, 5, 15, null);
    float multiplier = 8.0f;
    gd.addNumericField("Velocity Multiplier", multiplier, 5, 15, null);
    float ftime = 1.0f;
    gd.addNumericField("Frame_Time(min)", ftime, 5, 15, null);
    float scaling = (float) cal.pixelWidth;
    gd.addNumericField("Pixel_Size(um)", scaling, 5, 15, null);
    boolean norm = true;
    gd.addCheckbox("Normalize_Vector_lengths?", norm);
    boolean centered = true;
    gd.addCheckbox("Center_Vectors?", centered);
    float magthresh = 0.0f;
    gd.addNumericField("Magnitude_Threshhold?", magthresh, 5, 15, null);
    int rlength = 10;
    gd.addNumericField("Running_avg_length", rlength, 0);
    int inc = 5;
    gd.addNumericField("Start_frame_increment", inc, 0);
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    subsize = (int) gd.getNextNumber();
    stepsize = (int) gd.getNextNumber();
    shift = (int) gd.getNextNumber();
    xoffset = (float) gd.getNextNumber();
    yoffset = (float) gd.getNextNumber();
    multiplier = (float) gd.getNextNumber();
    ftime = (float) gd.getNextNumber();
    scaling = (float) gd.getNextNumber();
    norm = gd.getNextBoolean();
    centered = gd.getNextBoolean();
    magthresh = (float) gd.getNextNumber();
    rlength = (int) gd.getNextNumber();
    inc = (int) gd.getNextNumber();

    int width = imp.getWidth();
    int xregions = 1 + (int) (((float) width - (float) subsize) / (float) stepsize);
    int newwidth = xregions * subsize;
    int height = imp.getHeight();
    int yregions = 1 + (int) (((float) height - (float) subsize) / (float) stepsize);
    int newheight = yregions * subsize;
    ImageStack stack = imp.getStack();
    int slices = imp.getNSlices();
    int channels = imp.getNChannels();
    int frames = imp.getNFrames();
    if (frames == 1) {
      frames = slices;
      slices = 1;
    }

    Roi roi = imp.getRoi();
    if (roi == null) {
      roi = new Roi(0, 0, width, height);
    }

    STICS_map map = new STICS_map(subsize, stepsize);
    Object[] tseries = jutils.get3DTSeries(stack, 0, 0, frames, slices, channels);
    map.update_STICS_map(tseries, width, height, 0, rlength, roi.getPolygon(), shift);
    FloatProcessor fp =
        map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh);
    ImageStack vector_stack = new ImageStack(fp.getWidth(), fp.getHeight());
    vector_stack.addSlice("", fp);
    float[][] vel = map.get_scaled_velocities(scaling, ftime, stepsize);
    ImageStack velstack = new ImageStack(map.xregions, map.yregions);
    velstack.addSlice("", vel[0]);
    velstack.addSlice("", vel[1]);
    int velframes = 2;
    IJ.showStatus("frame " + 0 + " calculated");
    for (int i = inc; i < (frames - rlength); i += inc) {
      map.update_STICS_map(tseries, width, height, i, rlength, roi.getPolygon(), shift);
      FloatProcessor fp2 =
          map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh);
      vector_stack.addSlice("", fp2);
      vel = map.get_scaled_velocities(scaling, ftime, stepsize);
      velstack.addSlice("", vel[0]);
      velstack.addSlice("", vel[1]);
      velframes += 2;
      IJ.showStatus("frame " + i + " calculated");
    }
    (new ImagePlus("STICS Vectors", vector_stack)).show();
    ImagePlus imp3 = new ImagePlus("Velocities", velstack);
    imp3.setOpenAsHyperStack(true);
    imp3.setDimensions(2, 1, velframes / 2);
    new CompositeImage(imp3, CompositeImage.COLOR).show();
  }
Esempio n. 19
0
  private void geterrors() {
    GenericDialog gd = new GenericDialog("Options");
    float conf = 0.67f;
    gd.addNumericField("Confidence Limit", (int) (conf * 100.0f), 5, 10, null);
    gd.addChoice("Error Parameter", paramsnames, paramsnames[0]);
    double spacing = 0.01;
    gd.addNumericField("Chi^2 plot spacing (% of value)?", spacing * 100.0, 2, 10, null);
    boolean globalerror = false;
    gd.addCheckbox("Global Fit Error?", globalerror);
    int dataset = 0;
    gd.addNumericField("Data Set (for Global Error)", dataset, 0);
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    conf = 0.01f * (float) gd.getNextNumber();
    int paramindex = (int) gd.getNextChoiceIndex();
    spacing = 0.01 * gd.getNextNumber();
    globalerror = gd.getNextBoolean();
    dataset = (int) gd.getNextNumber();

    if (globalerror) {
      support_plane_errors erclass = new support_plane_errors(this, 0.0001, 50, true, 0.1);
      int[] erindeces = {paramindex, dataset};
      // need to set up all the matrices
      int nsel = 0;
      int nparams = 11;
      for (int i = 0; i < ncurves; i++) {
        if (include[i]) {
          nsel++;
        }
      }
      double[][] params = new double[nsel][nparams];
      String[][] tempformulas = new String[nsel][nparams];
      double[][][] constraints = new double[2][nsel][nparams];
      int[][] vflmatrix = new int[nsel][nparams];

      float[][] tempdata = new float[nsel][xpts * ypts];
      float[][] tempweights = new float[nsel][xpts * ypts];

      int nfit = 0;
      int counter = 0;
      for (int i = 0; i < ncurves; i++) {
        if (include[i]) {
          for (int j = 0; j < nparams; j++) {
            params[counter][j] = globalparams[i][j];
            tempformulas[counter][j] = globalformulas[i][j];
            constraints[0][counter][j] = globalconstraints[0][i][j];
            constraints[1][counter][j] = globalconstraints[1][i][j];
            vflmatrix[counter][j] = globalvflmatrix[i][j];
            if (vflmatrix[counter][j] == 0 || (j == 0 && vflmatrix[counter][j] == 2)) {
              nfit++;
            }
          }
          for (int j = 0; j < xpts; j++) {
            for (int k = 0; k < ypts; k++) {
              tempdata[counter][j + k * xpts] = (float) ((double) pch[i][j][k] / (double) nmeas[i]);
              tempweights[counter][j + k * xpts] = weights[i][j][k];
            }
          }
          counter++;
        }
      }
      int dofnum = xpts * ypts * nsel - (nfit - 1) - 1;
      int dofden = xpts * ypts * nsel - nfit - 1;
      // double flim=FLimit(dofnum,dofden,(double)conf);
      double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf);
      IJ.log("FLimit = " + (float) flim);
      if (flim == Double.NaN && flim < 1.0) {
        IJ.showMessage("Invalid Limiting F Value");
        return;
      }
      double truespacing = Math.abs(params[erindeces[1]][erindeces[0]] * spacing);
      double[][] c2plot =
          erclass.geterrorsglobal(
              params,
              vflmatrix,
              tempformulas,
              paramsnames,
              constraints,
              tempdata,
              tempweights,
              flim,
              truespacing,
              erindeces);
      IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]);
      int templength = c2plot[0].length;
      float[][] c2plotf = new float[2][templength - 1];
      for (int i = 0; i < (templength - 1); i++) {
        c2plotf[0][i] = (float) c2plot[0][i + 1];
        c2plotf[1][i] = (float) c2plot[1][i + 1];
      }
      new PlotWindow4(
              "c2 plot",
              paramsnames[paramindex] + "[" + dataset + "]",
              "Chi^2",
              c2plotf[0],
              c2plotf[1])
          .draw();
    } else {
      support_plane_errors erclass = new support_plane_errors(this, 0.0001, 50, false, 0.1);
      int errindex = paramindex;

      float[] tempdata = new float[xpts * ypts];
      float[] tempweights = new float[xpts * ypts];
      for (int i = 0; i < xpts; i++) {
        for (int j = 0; j < ypts; j++) {
          tempdata[i + j * xpts] = (float) ((double) avg[i][j] / (double) nmeas[ncurves]);
          tempweights[i + j * xpts] = avgweights[i][j];
        }
      }

      int nfit = 0;
      for (int i = 0; i < 7; i++) {
        if (avgfixes[i] == 0) {
          nfit++;
        }
      }
      int dofnum = xpts * ypts - (nfit - 1) - 1;
      int dofden = xpts * ypts - nfit - 1;
      double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf);
      IJ.log("FLimit = " + (float) flim);
      if (flim == Double.NaN && flim < 1.0) {
        IJ.showMessage("Invalid Limiting F Value");
        return;
      }
      double truespacing = Math.abs(avgparams[errindex] * spacing);
      double[][] c2plot =
          erclass.geterrors(
              avgparams,
              avgfixes,
              avgconstraints,
              tempdata,
              tempweights,
              flim,
              truespacing,
              errindex);
      IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]);
      int templength = c2plot[0].length;
      float[][] c2plotf = new float[2][templength - 1];
      for (int i = 0; i < (templength - 1); i++) {
        c2plotf[0][i] = (float) c2plot[0][i + 1];
        c2plotf[1][i] = (float) c2plot[1][i + 1];
      }
      new PlotWindow4("c2 plot", paramsnames[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw();
    }
  }
 public void run(String arg) {
   String[] labels = {
     "Masked_Chromosomes", "Unmixed_Image", "Spectral_Image(optional)", "Spectra(optional)"
   };
   ImagePlus[] imps = jutils.selectImages(true, 4, labels);
   if (imps == null) {
     return;
   }
   if (imps[0] == null) {
     return;
   }
   float[] mask = (float[]) imps[0].getStack().getPixels(2);
   findblobs3 fb = new findblobs3(imps[0].getWidth(), imps[0].getHeight());
   float[] objects = fb.dofindblobs(mask, 0.5f);
   WaitForUserDialog dg =
       new WaitForUserDialog(
           "Optional Input", "Place RoiManager Points on Chromosome Segments (if desired)");
   dg.show();
   if (!dg.escPressed()) {
     RoiManager rman = RoiManager.getInstance();
     while (rman != null && rman.getCount() > 1) {
       Roi[] rois = rman.getRoisAsArray();
       int[] ids = new int[rois.length];
       for (int i = 0; i < rois.length; i++) {
         Rectangle r = rois[i].getBounds();
         ids[i] = (int) objects[r.x + fb.width * r.y];
       }
       objects = fb.link_objects(objects, ids);
       rman.reset();
       dg =
           new WaitForUserDialog(
               "Optional Input",
               "Place More RoiManager Points on Chromosome Segments (if desired)");
       dg.show();
       if (dg.escPressed()) break;
     }
   }
   int[] areas = fb.get_areas(objects);
   int[] temprank = jsort.get_javasort_order(areas);
   int[] arearank = jsort.get_javasort_order(temprank);
   for (int i = 0; i < fb.nobjects; i++) {
     arearank[i] = fb.nobjects - arearank[i] - 1;
   }
   // if the spectra are available, get them
   float[][][] spectra = null;
   Object[] data = null;
   if (imps[1] != null && imps[2] != null && imps[3] != null) {
     ImageWindow iw = imps[3].getWindow();
     if (iw.getClass().getName().equals("jguis.PlotWindow4")) {
       float[][] yvals = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues");
       data = jutils.stack2array(imps[2].getStack());
       Object[] coef = jutils.stack2array(imps[1].getStack());
       spectra = new float[fb.nobjects][2][];
       for (int i = 0; i < fb.nobjects; i++) {
         spectra[i][0] = fb.get_object_spectrum(objects, (i + 1), data, "Sum");
         spectra[i][1] = new float[yvals[0].length];
         float[] tempcoef = fb.get_object_spectrum(objects, (i + 1), coef, "Sum");
         for (int j = 0; j < yvals[0].length; j++) {
           for (int k = 0; k < 5; k++) {
             spectra[i][1][j] += tempcoef[k] * yvals[k][j];
           }
         }
       }
     }
   }
   CompositeImage imp = (CompositeImage) imps[0];
   imp.setPosition(1, 1, 1);
   LUT graylut = jutils.get_lut_for_color(Color.white);
   imp.setChannelColorModel(graylut);
   imp.setPosition(2, 1, 1);
   LUT redlut = jutils.get_lut_for_color(Color.red);
   imp.setChannelColorModel(redlut);
   imp.setPosition(1, 1, 1);
   imp.updateAndRepaintWindow();
   SkyPanel_v3 sp = new SkyPanel_v3();
   int skychan = 6;
   if (imps[1] != null) skychan = imps[1].getNChannels();
   // assume that the sky image has 6 channels and that the second is the unknown green
   // shift the unknown green to the end
   ImagePlus skyimp = null;
   if (imps[1] != null) {
     Object[] skystack = jutils.stack2array(imps[1].getStack());
     // Object[]
     // skystack2={skystack[0],skystack[2],skystack[3],skystack[4],skystack[5],skystack[1]};
     Object[] skystack2 = null;
     if (skychan == 6)
       skystack2 = new Object[] {skystack[0], skystack[2], skystack[3], skystack[4], skystack[5]};
     else
       skystack2 = new Object[] {skystack[0], skystack[1], skystack[2], skystack[3], skystack[4]};
     skyimp =
         new ImagePlus(
             "rearranged", jutils.array2stack(skystack2, imps[1].getWidth(), imps[1].getHeight()));
   }
   int nch = 5;
   if (skyimp != null) nch = skyimp.getStack().getSize();
   GenericDialog gd2 = new GenericDialog("Options");
   gd2.addNumericField("Area Accuracy (percent)", 30, 0);
   for (int i = 0; i < nch; i++) {
     gd2.addNumericField("Ch_" + (i + 1) + "_Contr_Thresh", 0.35, 5, 15, null);
   }
   // gd2.addNumericField("Contribution Threshold",0.35,5,15,null);
   gd2.addCheckbox("Mouse?", false);
   gd2.addNumericField("Box_Width", 150, 0);
   gd2.addNumericField("Box_Height", 100, 0);
   gd2.showDialog();
   if (gd2.wasCanceled()) {
     return;
   }
   sp.areathresh = (float) gd2.getNextNumber();
   sp.objthresh2 = new float[nch];
   for (int i = 0; i < nch; i++) sp.objthresh2[i] = (float) gd2.getNextNumber();
   // sp.objthresh=(float)gd2.getNextNumber();
   boolean mouse = gd2.getNextBoolean();
   int bwidth = (int) gd2.getNextNumber();
   int bheight = (int) gd2.getNextNumber();
   int[] colorindices = {4, 1, 2, 6, 3};
   GenericDialog gd3 = new GenericDialog("Color Options");
   for (int i = 0; i < 5; i++)
     gd3.addChoice(
         "Ch" + (i + 1) + " Color",
         SkyPanel_v3.colornames,
         SkyPanel_v3.colornames[colorindices[i]]);
   gd3.showDialog();
   if (gd3.wasCanceled()) return;
   for (int i = 0; i < 5; i++) colorindices[i] = gd3.getNextChoiceIndex();
   sp.colorindices = colorindices;
   sp.nch = 5;
   sp.dapilast = false;
   sp.cellwidth = bwidth;
   sp.cellheight = bheight;
   sp.init(imps[0], skyimp, objects, areas, arearank, fb, true, spectra, data, mouse);
   SkyPanel_v3.launch_frame(sp);
 }
  public void run(String arg) {
    int wOld, hOld, wNew, hNew;
    boolean fIsStack = false;

    ImagePlus imp = IJ.getImage();
    wOld = imp.getWidth();
    hOld = imp.getHeight();

    ImageStack stackOld = imp.getStack();
    if ((stackOld != null) && (stackOld.getSize() > 1)) fIsStack = true;

    String[] sPositions = {
      "Top-Left", "Top-Center", "Top-Right",
      "Center-Left", "Center", "Center-Right",
      "Bottom-Left", "Bottom-Center", "Bottom-Right"
    };

    String strTitle = fIsStack ? "Resize Stack Canvas" : "Resize Image Canvas";
    GenericDialog gd = new GenericDialog(strTitle);
    gd.addNumericField("Width:", wOld, 0, 5, "pixels");
    gd.addNumericField("Height:", hOld, 0, 5, "pixels");
    gd.addChoice("Position:", sPositions, sPositions[4]);
    gd.addCheckbox("Zero Fill", zeroFill);
    gd.showDialog();
    if (gd.wasCanceled()) return;

    wNew = (int) gd.getNextNumber();
    hNew = (int) gd.getNextNumber();
    int iPos = gd.getNextChoiceIndex();
    zeroFill = gd.getNextBoolean();
    Prefs.set("resizer.zero", zeroFill);

    int xOff, yOff;
    int xC = (wNew - wOld) / 2; // offset for centered
    int xR = (wNew - wOld); // offset for right
    int yC = (hNew - hOld) / 2; // offset for centered
    int yB = (hNew - hOld); // offset for bottom

    switch (iPos) {
      case 0: // TL
        xOff = 0;
        yOff = 0;
        break;
      case 1: // TC
        xOff = xC;
        yOff = 0;
        break;
      case 2: // TR
        xOff = xR;
        yOff = 0;
        break;
      case 3: // CL
        xOff = 0;
        yOff = yC;
        break;
      case 4: // C
        xOff = xC;
        yOff = yC;
        break;
      case 5: // CR
        xOff = xR;
        yOff = yC;
        break;
      case 6: // BL
        xOff = 0;
        yOff = yB;
        break;
      case 7: // BC
        xOff = xC;
        yOff = yB;
        break;
      case 8: // BR
        xOff = xR;
        yOff = yB;
        break;
      default: // center
        xOff = xC;
        yOff = yC;
        break;
    }

    if (fIsStack) {
      ImageStack stackNew = expandStack(stackOld, wNew, hNew, xOff, yOff);
      imp.setStack(null, stackNew);
    } else {
      if (!IJ.macroRunning()) Undo.setup(Undo.COMPOUND_FILTER, imp);
      ImageWindow win = imp.getWindow();
      if (win != null && (win instanceof PlotWindow)) ((PlotWindow) win).getPlot().setFrozen(true);
      ImageProcessor newIP = expandImage(imp.getProcessor(), wNew, hNew, xOff, yOff);
      imp.setProcessor(null, newIP);
      if (!IJ.macroRunning()) Undo.setup(Undo.COMPOUND_FILTER_DONE, imp);
    }
    Overlay overlay = imp.getOverlay();
    if (overlay != null) overlay.translate(xOff, yOff);
  }
Esempio n. 22
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;
  }
 public boolean get_errors(double[] params, int[] fixes) {
   GenericDialog gd = new GenericDialog("Error Options");
   String[] methods = {"Support Plane", "Monte Carlo"};
   gd.addChoice("Method", methods, methods[0]);
   float conf = 0.67f;
   gd.addNumericField("SP_Confidence Limit (%)", (int) (conf * 100.0f), 5, 10, null);
   String[] labels = {"P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10"};
   gd.addChoice("SP_Parameter", labels, labels[0]);
   double spacing = 0.01;
   gd.addNumericField("SP_Chi^2_plot_spacing (% of value)?", spacing * 100.0, 2, 10, null);
   int ntrials = 100;
   gd.addNumericField("MC_#_Trials", ntrials, 0);
   gd.showDialog();
   if (gd.wasCanceled()) {
     return false;
   }
   int methodindex = gd.getNextChoiceIndex();
   conf = 0.01f * (float) gd.getNextNumber();
   int paramindex = gd.getNextChoiceIndex();
   spacing = 0.01 * gd.getNextNumber();
   ntrials = (int) gd.getNextNumber();
   if (methodindex == 0) {
     support_plane_errors_v2 erclass = new support_plane_errors_v2(this, 0.0001, 50, false, 0.1);
     int errindex = paramindex;
     int nfit = 0;
     for (int i = 0; i < labels.length; i++) {
       if (fixes[i] == 0) {
         nfit++;
       }
     }
     int npts = tempdata.length;
     int dofnum = npts - (nfit - 1) - 1;
     int dofden = npts - nfit - 1;
     double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf);
     IJ.log("FLimit = " + (float) flim);
     if (flim == Double.NaN && flim < 1.0) {
       IJ.showMessage("Invalid Limiting F Value");
       return false;
     }
     double truespacing = Math.abs(params[errindex] * spacing);
     double[][] c2plot =
         erclass.geterrors(
             params, fixes, constraints, tempdata, weights, flim, truespacing, errindex);
     IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]);
     IJ.log(
         "upper error = "
             + (c2plot[1][0] - params[errindex])
             + " lower error = "
             + (params[errindex] - c2plot[0][0]));
     int templength = c2plot[0].length;
     float[][] c2plotf = new float[2][templength - 1];
     for (int i = 0; i < (templength - 1); i++) {
       c2plotf[0][i] = (float) c2plot[0][i + 1];
       c2plotf[1][i] = (float) c2plot[1][i + 1];
     }
     new PlotWindow4("c2 plot", labels[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw();
   } else {
     StringBuffer sb = new StringBuffer();
     sb.append("Trial\t");
     for (int i = 0; i < labels.length; i++) {
       if (fixes[i] == 0) sb.append(labels[i] + "\t");
     }
     sb.append("chi^2");
     tw = new TextWindow("Monte Carlo Results", sb.toString(), "", 400, 400);
     redirect = true;
     monte_carlo_errors_v2 erclass = new monte_carlo_errors_v2(this, 0.0001, 50, false, 0.1);
     double[][] errors = erclass.geterrors(params, fixes, constraints, tempdata, weights, ntrials);
     sb = new StringBuffer();
     sb.append("StDev\t");
     for (int i = 0; i < errors.length; i++) {
       float[] ferr = new float[errors[0].length];
       for (int j = 0; j < ferr.length; j++) ferr[j] = (float) errors[i][j];
       float stdev = jstatistics.getstatistic("StDev", ferr, null);
       sb.append("" + stdev);
       if (i < (errors.length - 1)) sb.append("\t");
     }
     tw.append(sb.toString());
     redirect = false;
   }
   return true;
 }
Esempio n. 24
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
    }
  }
Esempio n. 25
0
	public void run(String arg) {

  int[] wList = WindowManager.getIDList();
        if (wList==null) {
            IJ.error("No images are open.");
            return;
        }
	double kernel=3;
	double kernelsum = 0;
	double kernelvarsum =0;
	double kernalvar = 0;
	double sigmawidth = 2;
	int kernelindex, minpixnumber;
	String[] kernelsize =  { "3�,"5�, "7�, "9�};

	GenericDialog gd = new GenericDialog("Sigma Filter");
	gd.addChoice("Kernel size", kernelsize, kernelsize[0]);
	gd.addNumericField("Sigma width",sigmawidth , 2);
	gd.addNumericField("Minimum number of pixels", 1, 0);

	gd.addCheckbox("Keep source:",true);
	gd.addCheckbox("Do all stack:",true);
	gd.addCheckbox("Modified Lee's FIlter:",true);
	       	
	gd.showDialog();
       	if (gd.wasCanceled()) return ;
	kernelindex =  gd.getNextChoiceIndex();
          	sigmawidth = gd.getNextNumber();
          	minpixnumber = ((int)gd.getNextNumber());
          	boolean keep = gd.getNextBoolean();
	boolean doallstack = gd.getNextBoolean();
	boolean modified = gd.getNextBoolean();
	if (kernelindex==0) kernel = 3;
	if (kernelindex==1) kernel = 5;
	if (kernelindex==2) kernel = 7;
	if (kernelindex==3) kernel = 9;
    	long start = System.currentTimeMillis();
	
if (minpixnumber> (kernel*kernel)){
	      IJ.showMessage("Sigma filter", "There must be more pixels in the kernel than+\n" + "the minimum number to be included");
            return;
        }
	double v, midintensity;
	int   x, y, ix, iy;
	double sum = 0;
	double backupsum =0;
	int count = 0;
	int n = 0;
	if (keep) {IJ.run("Select All"); IJ.run("Duplicate...", "title='Sigma filtered' duplicate");}

	int radius = (int)(kernel-1)/2;
	ImagePlus imp = WindowManager.getCurrentImage();
	ImageStack stack1 = imp.getStack();
	int width = imp.getWidth();
	int height = imp.getHeight();
	int nslices = stack1.getSize();
	int cslice = imp.getCurrentSlice();
	double status = width*height*nslices;
	
	ImageProcessor  ip = imp.getProcessor();
	int sstart = 1;
	if (!doallstack) {sstart = cslice; nslices=sstart;status = status/nslices;};

 for (int i=sstart; i<=nslices; i++) {
                imp.setSlice(i);
                    
for (x=radius;x<width+radius;x++)	{
		for (y=radius;y<height+radius;y++)	{
			
			midintensity = ip.getPixelValue(x,y);
			count = 0;
			sum = 0;
			kernelsum =0;
			kernalvar =0;
			kernelvarsum =0;
			backupsum = 0;

		//calculate mean of kernel value
			for (ix=0;ix<kernel;ix++)	{
					for (iy=0;iy<kernel;iy++)	{
							v = ip.getPixelValue(x+ix-radius,y+iy-radius);
							kernelsum = kernelsum+v;
								}
						}
			double sigmacalcmean = (kernelsum/(kernel*kernel));

		//calculate variance of kernel
			for (ix=0;ix<kernel;ix++)	{
					for (iy=0;iy<kernel;iy++)	{
							v = ip.getPixelValue(x+ix-radius,y+iy-radius);
							kernalvar = (v-sigmacalcmean)*(v-sigmacalcmean);
							kernelvarsum = kernelvarsum + kernalvar;
								}
						}
			//double variance = kernelvarsum/kernel;
			double sigmacalcvar = kernelvarsum/((kernel*kernel)-1);

			//calcuate sigma range = sqrt(variance/(mean^2)) � sigmawidth
			double sigmarange  = sigmawidth*(Math.sqrt((sigmacalcvar) /(sigmacalcmean*sigmacalcmean)));
			//calulate sigma top value and bottom value
			double sigmatop = midintensity*(1+sigmarange);
			double sigmabottom = midintensity*(1-sigmarange);
			//calculate mean of values that differ are in sigma range.
			for (ix=0;ix<kernel;ix++)	{
					for (iy=0;iy<kernel;iy++)	{
							v = ip.getPixelValue(x+ix-radius,y+iy-radius);
							if ((v>=sigmabottom)&&(v<=sigmatop)){
								sum = sum+v;
								count = count+1;   }
								backupsum = v+ backupsum;
										}		
						}
//if there are too few pixels in the kernal that are within sigma range, the 
//mean of the entire kernal is taken. My modification of Lee's filter is to exclude the central value 
//from the calculation of the mean as I assume it to be spuriously high or low 
			if (!(count>(minpixnumber)))
				{sum = (backupsum-midintensity);
				count = (int)((kernel*kernel)-1);
				if (!modified)
					{sum = (backupsum);
					count  = (int)(kernel*kernel);}
				}
			
			double val =  (sum/count);
			ip.putPixelValue(x,y, val);
			n = n+1;
	double percentage = (((double)n/status)*100);
			 IJ.showStatus(IJ.d2s(percentage,0) +"% done");		
			
}

	//		IJ.showProgress(i, status);
					}}
			imp.updateAndDraw();
 			IJ.showStatus(IJ.d2s((System.currentTimeMillis()-start)/1000.0, 2)+" seconds");        }      
Esempio n. 26
0
  public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
    if (IJ.isMacOSX()) IJ.wait(50);
    Calibration cal = imp.getCalibration();
    width = gd.getNextNumber();
    height = gd.getNextNumber();
    xRoi = gd.getNextNumber();
    yRoi = gd.getNextNumber();
    if (stackSize > 1) iSlice = (int) gd.getNextNumber();
    oval = gd.getNextBoolean();
    square = gd.getNextBoolean();
    centered = gd.getNextBoolean();
    if (cal.scaled()) scaledUnits = gd.getNextBoolean();
    if (gd.invalidNumber() || width <= 0 || height <= 0) return false;
    //
    Vector numFields = gd.getNumericFields();
    Vector checkboxes = gd.getCheckboxes();
    boolean newWidth = false, newHeight = false, newXY = false;
    if (e != null && e.getSource() == checkboxes.get(SQUARE) && square) {
      width = 0.5 * (width + height); // make square: same width&height
      height = width;
      newWidth = true;
      newHeight = true;
    }
    if (e != null && e.getSource() == checkboxes.get(CENTERED)) {
      double shiftBy = centered ? 0.5 : -0.5; // 'centered' changed:
      xRoi += shiftBy * width; // shift x, y to keep roi the same
      yRoi += shiftBy * height;
      newXY = true;
    }
    if (square && width != height && e != null) { // in 'square' mode, synchronize width&height
      if (e.getSource() == numFields.get(WIDTH)) {
        height = width;
        newHeight = true;
      } else if (e.getSource() == numFields.get(HEIGHT)) {
        width = height;
        newWidth = true;
      }
    }
    if (e != null && cal.scaled() && e.getSource() == checkboxes.get(SCALED_UNITS)) {
      double xFactor = scaledUnits ? cal.pixelWidth : 1. / cal.pixelWidth;
      double yFactor = scaledUnits ? cal.pixelHeight : 1. / cal.pixelHeight;
      width *= xFactor; // transform everything to keep roi the same
      height *= yFactor;
      xRoi *= xFactor;
      yRoi *= yFactor;
      newWidth = true;
      newHeight = true;
      newXY = true;
    }
    int digits = (scaledUnits || (int) width != width) ? 2 : 0;
    if (newWidth) ((TextField) (numFields.get(WIDTH))).setText(IJ.d2s(width, digits));
    if (newHeight) ((TextField) (numFields.get(HEIGHT))).setText(IJ.d2s(height, digits));
    digits = (scaledUnits || (int) xRoi != xRoi || (int) yRoi != yRoi) ? 2 : 0;
    if (newXY) {
      ((TextField) (numFields.get(X_ROI))).setText(IJ.d2s(xRoi, digits));
      ((TextField) (numFields.get(Y_ROI))).setText(IJ.d2s(yRoi, digits));
    }

    if (stackSize > 1 && iSlice > 0 && iSlice <= stackSize) imp.setSlice(iSlice);
    if (!newWidth && !newHeight && !newXY) // don't draw if an update will come immediately
    drawRoi();
    return true;
  }
Esempio n. 27
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;
  }
Esempio n. 28
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;
  }