/** * 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; }
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; }
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); }
// 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; }
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; }
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; }
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; }
/** 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 } }