/** * Creates a dialog box, allowing the user to enter the requested width, height, x & y * coordinates, slice number for a Region Of Interest, option for oval, and option for whether x & * y coordinates to be centered. */ void showDialog() { Calibration cal = imp.getCalibration(); int digits = 0; if (scaledUnits && cal.scaled()) digits = 2; Roi roi = imp.getRoi(); if (roi == null) drawRoi(); GenericDialog gd = new GenericDialog("Specify"); gd.addNumericField("Width:", width, digits); gd.addNumericField("Height:", height, digits); gd.addNumericField("X coordinate:", xRoi, digits); gd.addNumericField("Y coordinate:", yRoi, digits); if (stackSize > 1) gd.addNumericField("Slice:", iSlice, 0); gd.addCheckbox("Oval", oval); gd.addCheckbox("Constrain square/circle", square); gd.addCheckbox("Centered", centered); if (cal.scaled()) { boolean unitsMatch = cal.getXUnit().equals(cal.getYUnit()); String units = unitsMatch ? cal.getUnits() : cal.getXUnit() + " x " + cal.getYUnit(); gd.addCheckbox("Scaled units (" + units + ")", scaledUnits); } fields = gd.getNumericFields(); gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) { if (roi == null) imp.deleteRoi(); else // *ALWAYS* restore initial ROI when cancelled imp.setRoi(roi); } }
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { this.pfr = pfr; String macroOptions = Macro.getOptions(); if (macroOptions != null) { if (macroOptions.indexOf(" interpolate") != -1) macroOptions.replaceAll(" interpolate", " interpolation=Bilinear"); else if (macroOptions.indexOf(" interpolation=") == -1) macroOptions = macroOptions + " interpolation=None"; Macro.setOptions(macroOptions); } gd = new GenericDialog("Rotate", IJ.getInstance()); gd.addNumericField("Angle (degrees):", angle, (int) angle == angle ? 1 : 2); gd.addNumericField("Grid Lines:", gridLines, 0); gd.addChoice("Interpolation:", methods, methods[interpolationMethod]); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with Background Color", fillWithBackground); if (canEnlarge) gd.addCheckbox("Enlarge Image to Fit Result", enlarge); else enlarge = false; gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); gd.showDialog(); drawGridLines(0); if (gd.wasCanceled()) { return DONE; } if (!enlarge) flags |= KEEP_PREVIEW; // standard filter without enlarge else if (imp.getStackSize() == 1) flags |= NO_CHANGES; // undoable as a "compound filter" return IJ.setupDialog(imp, flags); }
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { if (doOptions) { this.imp = imp; this.pfr = pfr; GenericDialog gd = new GenericDialog("Binary Options"); gd.addNumericField("Iterations (1-" + MAX_ITERATIONS + "):", iterations, 0, 3, ""); gd.addNumericField("Count (1-8):", count, 0, 3, ""); gd.addCheckbox("Black background", Prefs.blackBackground); gd.addCheckbox("Pad edges when eroding", Prefs.padEdges); gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]); if (imp != null) { gd.addChoice("Do:", operations, operation); gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); previewing = true; } gd.addHelp(IJ.URL + "/docs/menus/process.html#options"); gd.showDialog(); previewing = false; if (gd.wasCanceled()) return DONE; if (imp == null) { // options dialog only, no do/preview dialogItemChanged(gd, null); // read dialog result return DONE; } return operation.equals(NO_OPERATION) ? DONE : IJ.setupDialog(imp, flags); } else { // no dialog, 'arg' is operation type if (!((ByteProcessor) imp.getProcessor()).isBinary()) { IJ.error("8-bit binary (black and white only) image required."); return DONE; } return IJ.setupDialog(imp, flags); } }
private void openDirectory(File f, String path) { if (path == null) return; if (!(path.endsWith(File.separator) || path.endsWith("/"))) path += File.separator; String[] names = f.list(); names = (new FolderOpener()).trimFileList(names); if (names == null) return; String msg = "Open all " + names.length + " images in \"" + f.getName() + "\" as a stack?"; GenericDialog gd = new GenericDialog("Open Folder"); gd.setInsets(10, 5, 0); gd.addMessage(msg); gd.setInsets(15, 35, 0); gd.addCheckbox("Convert to RGB", convertToRGB); gd.setInsets(0, 35, 0); gd.addCheckbox("Use Virtual Stack", virtualStack); gd.enableYesNoCancel(); gd.showDialog(); if (gd.wasCanceled()) return; if (gd.wasOKed()) { convertToRGB = gd.getNextBoolean(); virtualStack = gd.getNextBoolean(); String options = " sort"; if (convertToRGB) options += " convert_to_rgb"; if (virtualStack) options += " use"; IJ.run("Image Sequence...", "open=[" + path + "]" + options); DirectoryChooser.setDefaultDirectory(path); } else { for (int k = 0; k < names.length; k++) { IJ.redirectErrorMessages(); if (!names[k].startsWith(".")) (new Opener()).open(path + names[k]); } } IJ.register(DragAndDrop.class); }
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; }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); gd.addCheckbox("Add_Titles", true); gd.addCheckbox("Close Original", false); gd.showDialog(); if (gd.wasCanceled()) { return; } boolean addtitles = gd.getNextBoolean(); boolean closeorig = gd.getNextBoolean(); // first get the table window Frame[] niframes = WindowManager.getNonImageWindows(); boolean first = true; TextWindow tw2 = null; int ncols = 0; String[] col_labels = null; for (int i = 0; i < niframes.length; i++) { if (niframes[i] instanceof TextWindow && !niframes[i].getTitle().equals("Log")) { TextWindow tw = (TextWindow) niframes[i]; TextPanel tp = tw.getTextPanel(); List<List<String>> listtable = table_tools.table2listtable(tp); if (listtable.size() == 0) { col_labels = table_tools.getcollabels(tp); ncols = col_labels.length; ArrayList<String> temp = new ArrayList<String>(); for (int j = 0; j < ncols; j++) temp.add(""); listtable.add(temp); } if (first) { col_labels = table_tools.getcollabels(tp); ncols = col_labels.length; String headings = tp.getColumnHeadings(); if (addtitles) { String[] titles = repeated(tw.getTitle(), listtable.size()); table_tools.add_listtable_column(listtable, titles, 0); headings = "name\t" + headings; } tw2 = new TextWindow( "Combined Table", headings, table_tools.print_listtable(listtable), 400, 200); first = false; } else { if (addtitles) { String[] titles = repeated(tw.getTitle(), listtable.size()); table_tools.add_listtable_column(listtable, titles, 0); } tw2.append(table_tools.print_listtable(listtable)); } if (closeorig) tw.close(); } } }
// DICOM options void dicom() { GenericDialog gd = new GenericDialog("DICOM Options"); gd.addCheckbox("Open as 32-bit float", Prefs.openDicomsAsFloat); // gd.addCheckbox("Calculate voxel depth", Prefs.calculateDicomVoxelDepth); gd.addMessage("Orthogonal Views"); gd.setInsets(5, 40, 0); gd.addCheckbox("Rotate YZ", Prefs.rotateYZ); gd.setInsets(0, 40, 0); gd.addCheckbox("Flip XZ", Prefs.flipXZ); gd.showDialog(); if (gd.wasCanceled()) return; Prefs.openDicomsAsFloat = gd.getNextBoolean(); // Prefs.calculateDicomVoxelDepth = gd.getNextBoolean(); Prefs.rotateYZ = gd.getNextBoolean(); Prefs.flipXZ = gd.getNextBoolean(); }
void showDialog() { int width = imp.getWidth(); int height = imp.getHeight(); Calibration cal = imp.getCalibration(); int places; if (cal.scaled()) { pixelWidth = cal.pixelWidth; pixelHeight = cal.pixelHeight; units = cal.getUnits(); places = 2; } else { pixelWidth = 1.0; pixelHeight = 1.0; units = "pixels"; places = 0; } if (areaPerPoint == 0.0) areaPerPoint = (width * cal.pixelWidth * height * cal.pixelHeight) / 81.0; // default to 9x9 grid ImageWindow win = imp.getWindow(); GenericDialog gd = new GenericDialog("Grid..."); gd.addChoice("Grid Type:", types, type); gd.addNumericField("Area per Point:", areaPerPoint, places, 6, units + "^2"); gd.addChoice("Color:", colors, color); gd.addCheckbox("Random Offset", randomOffset); gd.addDialogListener(this); gd.showDialog(); if (gd.wasCanceled()) showGrid(null); }
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); }
/** * 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; }
void checkForCalibrationConflict(ImagePlus imp, Calibration cal) { Calibration gcal = imp.getGlobalCalibration(); if (gcal == null || !showConflictMessage || IJ.isMacro()) return; if (cal.pixelWidth == gcal.pixelWidth && cal.getUnit().equals(gcal.getUnit())) return; GenericDialog gd = new GenericDialog(imp.getTitle()); gd.addMessage("The calibration of this image conflicts\nwith the current global calibration."); gd.addCheckbox("Disable_Global Calibration", true); gd.addCheckbox("Disable_these Messages", false); gd.showDialog(); if (gd.wasCanceled()) return; boolean disable = gd.getNextBoolean(); if (disable) { imp.setGlobalCalibration(null); imp.setCalibration(cal); WindowManager.repaintImageWindows(); } boolean dontShow = gd.getNextBoolean(); if (dontShow) showConflictMessage = false; }
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(); }
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; }
// Conversion Options void conversions() { double[] weights = ColorProcessor.getWeightingFactors(); boolean weighted = !(weights[0] == 1d / 3d && weights[1] == 1d / 3d && weights[2] == 1d / 3d); // boolean weighted = !(Math.abs(weights[0]-1d/3d)<0.0001 && Math.abs(weights[1]-1d/3d)<0.0001 // && Math.abs(weights[2]-1d/3d)<0.0001); GenericDialog gd = new GenericDialog("Conversion Options"); gd.addCheckbox("Scale when converting", ImageConverter.getDoScaling()); String prompt = "Weighted RGB conversions"; if (weighted) prompt += " (" + IJ.d2s(weights[0]) + "," + IJ.d2s(weights[1]) + "," + IJ.d2s(weights[2]) + ")"; gd.addCheckbox(prompt, weighted); gd.showDialog(); if (gd.wasCanceled()) return; ImageConverter.setDoScaling(gd.getNextBoolean()); Prefs.weightedColor = gd.getNextBoolean(); if (!Prefs.weightedColor) ColorProcessor.setWeightingFactors(1d / 3d, 1d / 3d, 1d / 3d); else if (Prefs.weightedColor && !weighted) ColorProcessor.setWeightingFactors(0.299, 0.587, 0.114); return; }
boolean init_functions() { GenericDialog gd = new GenericDialog("Fitting Options"); gd.addStringField("Extra Definitions", exdef, 50); gd.addCheckbox("Weight Using Plot Errors", false); gd.addStringField("Weighting Equation (y is for data)", weightfunction, 50); gd.addStringField("Fit_Equation", function, 50); gd.showDialog(); if (gd.wasCanceled()) { return false; } exdef = gd.getNextString(); boolean errweights = gd.getNextBoolean(); weightfunction = gd.getNextString(); function = gd.getNextString(); // first initialize the weights weights = new float[tempdata.length]; if (errweights || weightfunction.equals("") || weightfunction == null || weightfunction == "1.0") { if (errweights) { for (int i = 0; i < tempdata.length; i++) weights[i] = 1.0f / (errs[i] * errs[i]); } else { for (int i = 0; i < tempdata.length; i++) weights[i] = 1.0f; } } else { for (int i = 0; i < tempdata.length; i++) { String script = "y =" + tempdata[i] + "; " + "x =" + tempx[i] + "; " + "retval=" + weightfunction + ";"; Double temp = new Double(0.0); try { temp = (Double) engine.eval(script); } catch (Exception e) { IJ.log(e.getMessage()); } if (!(temp.isInfinite() || temp.isNaN())) { weights[i] = temp.floatValue(); } } } // now compile the function script try { String script1 = exdef + "; retval=" + function + ";"; cs = ce.compile(script1); } catch (Exception e) { IJ.log(e.toString()); return false; } return true; }
void addSelection() { ImagePlus imp = IJ.getImage(); String macroOptions = Macro.getOptions(); if (macroOptions != null && IJ.macroRunning() && macroOptions.indexOf("remove") != -1) { imp.setOverlay(null); return; } Roi roi = imp.getRoi(); if (roi == null && imp.getOverlay() != null) { GenericDialog gd = new GenericDialog("No Selection"); gd.addMessage("\"Overlay>Add\" requires a selection."); gd.setInsets(15, 40, 0); gd.addCheckbox("Remove existing overlay", false); gd.showDialog(); if (gd.wasCanceled()) return; if (gd.getNextBoolean()) imp.setOverlay(null); return; } if (roi == null) { IJ.error("This command requires a selection."); return; } roi = (Roi) roi.clone(); if (roi.getStrokeColor() == null) roi.setStrokeColor(Toolbar.getForegroundColor()); int width = Line.getWidth(); Rectangle bounds = roi.getBounds(); boolean tooWide = width > Math.max(bounds.width, bounds.height) / 3.0; if (roi.getStroke() == null && width > 1 && !tooWide) roi.setStrokeWidth(Line.getWidth()); Overlay overlay = imp.getOverlay(); if (overlay != null && overlay.size() > 0 && !roi.isDrawingTool()) { Roi roi2 = overlay.get(overlay.size() - 1); if (roi.getStroke() == null) roi.setStrokeWidth(roi2.getStrokeWidth()); if (roi.getFillColor() == null) roi.setFillColor(roi2.getFillColor()); } boolean points = roi instanceof PointRoi && ((PolygonRoi) roi).getNCoordinates() > 1; if (points) roi.setStrokeColor(Color.red); if (!IJ.altKeyDown() && !(roi instanceof Arrow)) { RoiProperties rp = new RoiProperties("Add to Overlay", roi); if (!rp.showDialog()) return; } String name = roi.getName(); boolean newOverlay = name != null && name.equals("new-overlay"); if (overlay == null || newOverlay) overlay = new Overlay(); overlay.add(roi); imp.setOverlay(overlay); overlay2 = overlay; if (points || (roi instanceof ImageRoi) || (roi instanceof Arrow)) imp.killRoi(); Undo.setup(Undo.OVERLAY_ADDITION, imp); }
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; }
// 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; }
// Miscellaneous Options void miscOptions() { String key = IJ.isMacintosh() ? "command" : "control"; GenericDialog gd = new GenericDialog("Miscellaneous Options", IJ.getInstance()); gd.addStringField("Divide by zero value:", "" + FloatBlitter.divideByZeroValue, 10); gd.addCheckbox("Use pointer cursor", Prefs.usePointerCursor); gd.addCheckbox("Hide \"Process Stack?\" dialog", IJ.hideProcessStackDialog); gd.addCheckbox("Require " + key + " key for shortcuts", Prefs.requireControlKey); gd.addCheckbox("Move isolated plugins to Misc. menu", Prefs.moveToMisc); if (!IJ.isMacOSX()) gd.addCheckbox("Run single instance listener", Prefs.runSocketListener); gd.addCheckbox("Enhanced line tool", Prefs.enhancedLineTool); gd.addCheckbox("Reverse CZT order of \">\" and \"<\"", Prefs.reverseNextPreviousOrder); gd.addCheckbox("Debug mode", IJ.debugMode); gd.addHelp(IJ.URL + "/docs/menus/edit.html#misc"); gd.showDialog(); if (gd.wasCanceled()) return; String divValue = gd.getNextString(); if (divValue.equalsIgnoreCase("infinity") || divValue.equalsIgnoreCase("infinite")) FloatBlitter.divideByZeroValue = Float.POSITIVE_INFINITY; else if (divValue.equalsIgnoreCase("NaN")) FloatBlitter.divideByZeroValue = Float.NaN; else if (divValue.equalsIgnoreCase("max")) FloatBlitter.divideByZeroValue = Float.MAX_VALUE; else { Float f; try { f = new Float(divValue); } catch (NumberFormatException e) { f = null; } if (f != null) FloatBlitter.divideByZeroValue = f.floatValue(); } IJ.register(FloatBlitter.class); Prefs.usePointerCursor = gd.getNextBoolean(); IJ.hideProcessStackDialog = gd.getNextBoolean(); Prefs.requireControlKey = gd.getNextBoolean(); Prefs.moveToMisc = gd.getNextBoolean(); if (!IJ.isMacOSX()) Prefs.runSocketListener = gd.getNextBoolean(); Prefs.enhancedLineTool = gd.getNextBoolean(); Prefs.reverseNextPreviousOrder = gd.getNextBoolean(); IJ.setDebugMode(gd.getNextBoolean()); }
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); } }
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(); }
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(); } }
boolean showDialog(ImageProcessor ip) { int bitDepth = imp.getBitDepth(); boolean isStack = imp.getStackSize() > 1; r = ip.getRoi(); int width = newWidth; if (width == 0) width = r.width; int height = (int) ((double) width * r.height / r.width); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); if (xscale != 0.0 && yscale != 0.0) { width = (int) (r.width * xscale); height = (int) (r.height * yscale); } else { xstr = "-"; ystr = "-"; } GenericDialog gd = new GenericDialog("Scale"); gd.addStringField("X Scale (0.05-25):", xstr); gd.addStringField("Y Scale (0.05-25):", ystr); gd.setInsets(5, 0, 5); gd.addStringField("Width (pixels):", "" + width); gd.addStringField("Height (pixels):", "" + height); fields = gd.getStringFields(); for (int i = 0; i < 3; i++) { ((TextField) fields.elementAt(i)).addTextListener(this); ((TextField) fields.elementAt(i)).addFocusListener(this); } xField = (TextField) fields.elementAt(0); yField = (TextField) fields.elementAt(1); widthField = (TextField) fields.elementAt(2); heightField = (TextField) fields.elementAt(3); fieldWithFocus = xField; gd.addCheckbox("Interpolate", interpolate); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with Background Color", fillWithBackground); if (isStack) gd.addCheckbox("Process Entire Stack", processStack); gd.addCheckbox("Create New Window", newWindow); title = WindowManager.getUniqueName(imp.getTitle()); gd.setInsets(10, 0, 0); gd.addStringField("Title:", title, 12); gd.showDialog(); if (gd.wasCanceled()) return false; xstr = gd.getNextString(); ystr = gd.getNextString(); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); String wstr = gd.getNextString(); newWidth = (int) Tools.parseDouble(wstr, 0); newHeight = (int) Tools.parseDouble(gd.getNextString(), 0); if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0"))) newWidth = (int) (newHeight * (double) r.width / r.height); if (newWidth == 0 || newHeight == 0) { IJ.error("Invalid width or height entered"); return false; } if (xscale > 25.0) xscale = 25.0; if (yscale > 25.0) yscale = 25.0; if (xscale > 0.0 && yscale > 0.0) { newWidth = (int) (r.width * xscale); newHeight = (int) (r.height * yscale); } interpolate = gd.getNextBoolean(); if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean(); if (isStack) processStack = gd.getNextBoolean(); newWindow = gd.getNextBoolean(); if (!newWindow && xscale == 0.0) { xscale = (double) newWidth / r.width; yscale = (double) newHeight / r.height; } title = gd.getNextString(); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) bgValue = ip.getBestIndex(bgc); else if (bitDepth == 24) bgValue = bgc.getRGB(); } else { if (bitDepth == 8) bgValue = ip.isInvertedLut() ? 0.0 : 255.0; // white else if (bitDepth == 24) bgValue = 0xffffffff; // white } return true; }
public void run(String arg) { Frame[] niframes = WindowManager.getNonImageWindows(); String[] titles = new String[niframes.length + 1]; for (int i = 0; i < niframes.length; i++) { titles[i] = niframes[i].getTitle(); } titles[niframes.length] = "Clipboard"; GenericDialog gd = new GenericDialog("Windows"); boolean importfile = false; gd.addCheckbox("Import from file?", importfile); gd.addChoice("Windows", titles, titles[0]); boolean hasxvals = false; gd.addCheckbox("X Vals Column?", hasxvals); boolean multix = false; gd.addCheckbox("Multi_X_Columns?", multix); boolean skipendzeros = false; gd.addCheckbox("Skip_end_zeros?", skipendzeros); String[] delimiters = {"Tab", "Comma", "Space"}; gd.addChoice("Delimiter", delimiters, delimiters[0]); gd.showDialog(); if (gd.wasCanceled()) { return; } importfile = gd.getNextBoolean(); int index = gd.getNextChoiceIndex(); hasxvals = gd.getNextBoolean(); multix = gd.getNextBoolean(); skipendzeros = gd.getNextBoolean(); int delimindex = gd.getNextChoiceIndex(); if (multix) hasxvals = true; String textdata = ""; if (importfile) { OpenDialog od = new OpenDialog("Open File", "", ".txt"); String directory = od.getDirectory(); String name = od.getFileName(); if (name == null) { return; } try { File infile = new File(directory + name); BufferedReader b = new BufferedReader(new FileReader(infile)); textdata = (new jdataio()).readstringfile(b); b.close(); } catch (IOException e) { return; } } else { if (index == niframes.length) { // here we get the data from the clipboard Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try { if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { textdata = (String) t.getTransferData(DataFlavor.stringFlavor); } } catch (UnsupportedFlavorException e) { } catch (IOException e) { } if (textdata.equals("")) { IJ.error("Error copying from clipboard."); return; } } else { if (niframes[index] instanceof Editor) { Editor tw = (Editor) niframes[index]; textdata = tw.getText(); } else { if (niframes[index] instanceof TextWindow) { TextWindow tw = (TextWindow) niframes[index]; textdata = tw.getTextPanel().getText(); } else { IJ.showMessage("Not a valid text window"); return; } } } } if (textdata == null) { IJ.showMessage("Error in Obtaining String"); return; } if (textdata.indexOf("\r") >= 0) { textdata = textdata.replace('\r', '\n'); } char[] delims = {'\t', ',', ' '}; delimit_string ds = new delimit_string(delims[delimindex]); String[] rows = ds.getrows(textdata); int lines = rows.length; int columns = ds.getnumcolumns(rows[0]); int ycolumns = columns; if (hasxvals) { if (multix) { ycolumns /= 2; } else { ycolumns--; } } if (multix) { float[][] ydata = new float[ycolumns][lines]; float[][] xdata = new float[ycolumns][lines]; for (int i = 0; i < lines; i++) { float[] temp = ds.delim2float(rows[i], columns); for (int j = 0; j < ycolumns; j++) { ydata[j][i] = temp[2 * j + 1]; xdata[j][i] = temp[2 * j]; } } int[] npts = new int[ycolumns]; for (int i = 0; i < ycolumns; i++) { npts[i] = lines; } if (skipendzeros) { for (int i = 0; i < ycolumns; i++) { int counter = lines - 1; while ((xdata[i][counter] == 0.0f || Float.isNaN(xdata[i][counter])) && counter > 0) { xdata[i][counter] = 0.0f; ydata[i][counter] = 0.0f; npts[i]--; counter--; } } } (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw(); } else { float[][] tempydata = new float[ycolumns][lines]; float[] tempxdata = new float[lines]; float[][] xdata = null; float[][] ydata = null; int startcolumn = 0; if (hasxvals) startcolumn = 1; for (int i = 0; i < lines; i++) { float[] temp = ds.delim2float(rows[i], columns); if (hasxvals) { tempxdata[i] = temp[0]; } else { tempxdata[i] = (float) (i + 1); } for (int j = 0; j < ycolumns; j++) { tempydata[j][i] = temp[j + startcolumn]; } } int[] npts = new int[ycolumns]; npts[0] = lines; if (skipendzeros) { int maxpts = 0; for (int i = 0; i < ycolumns; i++) { int counter = lines - 1; npts[i] = lines; while ((tempydata[i][counter] == 0.0f || Float.isNaN(tempydata[i][counter])) && counter > 0) { npts[i]--; counter--; } if (npts[i] > maxpts) maxpts = npts[i]; IJ.log("" + npts[i]); } ydata = new float[ycolumns][maxpts]; xdata = new float[ycolumns][maxpts]; for (int i = 0; i < ycolumns; i++) { // npts[i]=npts[0]; System.arraycopy(tempxdata, 0, xdata[i], 0, npts[i]); System.arraycopy(tempydata[i], 0, ydata[i], 0, npts[i]); } } else { ydata = tempydata; xdata = new float[ycolumns][]; for (int i = 0; i < ycolumns; i++) { npts[i] = npts[0]; xdata[i] = tempxdata.clone(); } } (new PlotWindow4("Text Plot", "x", "y", xdata, ydata, npts)).draw(); } }
boolean showDialog(ImageProcessor ip) { String macroOptions = Macro.getOptions(); if (macroOptions != null) { if (macroOptions.indexOf(" interpolate") != -1) macroOptions.replaceAll(" interpolate", " interpolation=Bilinear"); else if (macroOptions.indexOf(" interpolation=") == -1) macroOptions = macroOptions + " interpolation=None"; Macro.setOptions(macroOptions); } int bitDepth = imp.getBitDepth(); int stackSize = imp.getStackSize(); boolean isStack = stackSize > 1; oldDepth = stackSize; if (isStack) { xstr = "1.0"; ystr = "1.0"; zstr = "1.0"; } r = ip.getRoi(); int width = newWidth; if (width == 0) width = r.width; int height = (int) ((double) width * r.height / r.width); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); zscale = 1.0; if (xscale != 0.0 && yscale != 0.0) { width = (int) (r.width * xscale); height = (int) (r.height * yscale); } else { xstr = "-"; ystr = "-"; } GenericDialog gd = new GenericDialog("Scale"); gd.addStringField("X Scale:", xstr); gd.addStringField("Y Scale:", ystr); if (isStack) gd.addStringField("Z Scale:", zstr); gd.setInsets(5, 0, 5); gd.addStringField("Width (pixels):", "" + width); gd.addStringField("Height (pixels):", "" + height); if (isStack) { String label = "Depth (images):"; if (imp.isHyperStack()) { int slices = imp.getNSlices(); int frames = imp.getNFrames(); if (slices == 1 && frames > 1) { label = "Depth (frames):"; oldDepth = frames; } else { label = "Depth (slices):"; oldDepth = slices; } } gd.addStringField(label, "" + oldDepth); } fields = gd.getStringFields(); for (int i = 0; i < fields.size(); i++) { ((TextField) fields.elementAt(i)).addTextListener(this); ((TextField) fields.elementAt(i)).addFocusListener(this); } xField = (TextField) fields.elementAt(0); yField = (TextField) fields.elementAt(1); if (isStack) { zField = (TextField) fields.elementAt(2); widthField = (TextField) fields.elementAt(3); heightField = (TextField) fields.elementAt(4); depthField = (TextField) fields.elementAt(5); } else { widthField = (TextField) fields.elementAt(2); heightField = (TextField) fields.elementAt(3); } fieldWithFocus = xField; gd.addChoice("Interpolation:", methods, methods[interpolationMethod]); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with background color", fillWithBackground); gd.addCheckbox("Average when downsizing", averageWhenDownsizing); boolean hyperstack = imp.isHyperStack() || imp.isComposite(); if (isStack && !hyperstack) gd.addCheckbox("Process entire stack", processStack); gd.addCheckbox("Create new window", newWindow); title = WindowManager.getUniqueName(imp.getTitle()); gd.setInsets(10, 0, 0); gd.addStringField("Title:", title, 12); gd.showDialog(); if (gd.wasCanceled()) return false; xstr = gd.getNextString(); ystr = gd.getNextString(); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); if (isStack) { zstr = gd.getNextString(); zscale = Tools.parseDouble(ystr, 0.0); } String wstr = gd.getNextString(); newWidth = (int) Tools.parseDouble(wstr, 0); newHeight = (int) Tools.parseDouble(gd.getNextString(), 0); if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0"))) newWidth = (int) (newHeight * (double) r.width / r.height); if (newWidth == 0 || newHeight == 0) { IJ.error("Scaler", "Width or height is 0"); return false; } if (xscale > 0.0 && yscale > 0.0) { newWidth = (int) (r.width * xscale); newHeight = (int) (r.height * yscale); } if (isStack) newDepth = (int) Tools.parseDouble(gd.getNextString(), 0); interpolationMethod = gd.getNextChoiceIndex(); if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean(); averageWhenDownsizing = gd.getNextBoolean(); if (isStack && !hyperstack) processStack = gd.getNextBoolean(); if (hyperstack) processStack = true; newWindow = gd.getNextBoolean(); if (xscale == 0.0) { xscale = (double) newWidth / r.width; yscale = (double) newHeight / r.height; } title = gd.getNextString(); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) bgValue = ip.getBestIndex(bgc); else if (bitDepth == 24) bgValue = bgc.getRGB(); } else bgValue = 0.0; 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; }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); gd.addCheckbox("Acceptor_First", true); gd.showDialog(); if (gd.wasCanceled()) return; boolean a1 = gd.getNextBoolean(); int asp = 0; int dsp = 1; int aop = 2; int dop = 3; int atp = 4; int dtp = 5; if (!a1) { asp = 1; dsp = 0; aop = 3; dop = 2; atp = 5; dtp = 4; } ImageWindow iw = WindowManager.getCurrentWindow(); float[][] xvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); float[][] yvals = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); int[] npts = (int[]) jutils.runPW4VoidMethod(iw, "getNpts"); int maxpts = (int) jstatistics.getstatistic("Max", npts, null); int nsets = npts.length / 6; float[][] rtxvals = new float[nsets][maxpts]; float[][] rtavals = new float[nsets][maxpts]; float[][] rtdvals = new float[nsets][maxpts]; int[] rtnpts = new int[nsets]; int fretlength = 10; float[][] stfretvals = new float[nsets][fretlength]; float[][] offfretvals = new float[nsets][fretlength]; TextWindow tw = jutils.selectTable("DNA Damage FRET"); if (tw == null) tw = new TextWindow( "DNA Damage FRET", "title\tacceptor\tdonor\testripe\teoff\tmaxart\tmaxdrt", "", 400, 200); // note that st stands for stripe and off is for areas off the damage stripe for (int i = 0; i < npts.length / 6; i++) { int len = npts[i * 6]; int damageindex = findbleach(yvals[i * 6 + dsp], len); int fretindex = findbleach(yvals[i * 6 + atp], len); IJ.log("set " + i + " damage pos = " + damageindex + " , fret pos = " + fretindex); int predamagestart = damageindex - 4; int prefretstart = fretindex - 5; float staccpredam = getavg(yvals[i * 6 + asp], len, predamagestart, damageindex - 1); float stdonpredam = getavg(yvals[i * 6 + dsp], len, predamagestart, damageindex - 1); float nucaccpredam = getavg(yvals[i * 6 + atp], len, predamagestart, damageindex - 1); float nucdonpredam = getavg(yvals[i * 6 + dtp], len, predamagestart, damageindex - 1); float stdonprefret = getavg(yvals[i * 6 + dsp], len, prefretstart, fretindex - 2); float stdonafret = getavg(yvals[i * 6 + dsp], len, fretindex, fretindex + 3); float offdonprefret = getavg(yvals[i * 6 + dop], len, prefretstart, fretindex - 2); float offdonafret = getavg(yvals[i * 6 + dop], len, fretindex, fretindex + 3); float estripe = 1.0f - stdonprefret / stdonafret; float eoff = 1.0f - offdonprefret / offdonafret; rtnpts[i] = len; for (int j = 0; j < len; j++) { rtxvals[i][j] = j - damageindex - 1; rtavals[i][j] = (yvals[i * 6 + asp][j] / staccpredam) / (yvals[i * 6 + atp][j] / nucaccpredam); rtdvals[i][j] = (yvals[i * 6 + dsp][j] / stdonpredam) / (yvals[i * 6 + dtp][j] / nucdonpredam); } float[] smart = (float[]) algutils.get_subarray(rtavals[i], 0, fretindex); float[] smdrt = (float[]) algutils.get_subarray(rtdvals[i], 0, fretindex); jsmooth.blur1D(smart, 2.0f); jsmooth.blur1D(smdrt, 2.0f); float maxart = 0.0f; float maxdrt = 0.0f; for (int j = 0; j < fretindex - 2; j++) { if (smart[j] > maxart) maxart = smart[j]; if (smdrt[j] > maxdrt) maxdrt = smdrt[j]; } stfretvals[i] = getregion(yvals[i * 6 + dsp], len, prefretstart, fretlength); offfretvals[i] = getregion(yvals[i * 6 + dop], len, prefretstart, fretlength); tw.append( iw.getTitle() + "-" + (i + 1) + "\t" + staccpredam + "\t" + stdonpredam + "\t" + estripe + "\t" + eoff + "\t" + maxart + "\t" + maxdrt); } new PlotWindow4("Stripe_FRET_profiles", "time", "intensity", stfretvals, null).draw(); new PlotWindow4("OffStripe_FRET_profiles", "time", "intensity", offfretvals, null).draw(); new PlotWindow4("Acc_Rt_profiles", "time", "intensity", rtxvals, rtavals, rtnpts).draw(); new PlotWindow4("Don_Rt_profiles", "time", "intensity", rtxvals, rtdvals, rtnpts).draw(); }
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"); }
/** Displays a modal options dialog. */ public boolean showDialog() { Calibration cal = imp != null ? imp.getCalibration() : (new Calibration()); double unitSquared = cal.pixelWidth * cal.pixelHeight; if (pixelUnits) unitSquared = 1.0; if (Macro.getOptions() != null) { boolean oldMacro = updateMacroOptions(); if (oldMacro) unitSquared = 1.0; staticMinSize = 0.0; staticMaxSize = DEFAULT_MAX_SIZE; staticMinCircularity = 0.0; staticMaxCircularity = 1.0; staticShowChoice = NOTHING; } GenericDialog gd = new GenericDialog("Analyze Particles"); minSize = staticMinSize; maxSize = staticMaxSize; minCircularity = staticMinCircularity; maxCircularity = staticMaxCircularity; showChoice = staticShowChoice; if (maxSize == 999999) maxSize = DEFAULT_MAX_SIZE; options = staticOptions; String unit = cal.getUnit(); boolean scaled = cal.scaled(); if (unit.equals("inch")) { unit = "pixel"; unitSquared = 1.0; scaled = false; pixelUnits = true; } String units = unit + "^2"; int places = 0; double cmin = minSize * unitSquared; if ((int) cmin != cmin) places = 2; double cmax = maxSize * unitSquared; if ((int) cmax != cmax && cmax != DEFAULT_MAX_SIZE) places = 2; String minStr = ResultsTable.d2s(cmin, places); if (minStr.indexOf("-") != -1) { for (int i = places; i <= 6; i++) { minStr = ResultsTable.d2s(cmin, i); if (minStr.indexOf("-") == -1) break; } } String maxStr = ResultsTable.d2s(cmax, places); if (maxStr.indexOf("-") != -1) { for (int i = places; i <= 6; i++) { maxStr = ResultsTable.d2s(cmax, i); if (maxStr.indexOf("-") == -1) break; } } if (scaled) gd.setInsets(5, 0, 0); gd.addStringField("Size (" + units + "):", minStr + "-" + maxStr, 12); if (scaled) { gd.setInsets(0, 40, 5); gd.addCheckbox("Pixel units", pixelUnits); } gd.addStringField("Circularity:", IJ.d2s(minCircularity) + "-" + IJ.d2s(maxCircularity), 12); gd.addChoice("Show:", showStrings, showStrings[showChoice]); String[] labels = new String[8]; boolean[] states = new boolean[8]; labels[0] = "Display results"; states[0] = (options & SHOW_RESULTS) != 0; labels[1] = "Exclude on edges"; states[1] = (options & EXCLUDE_EDGE_PARTICLES) != 0; labels[2] = "Clear results"; states[2] = (options & CLEAR_WORKSHEET) != 0; labels[3] = "Include holes"; states[3] = (options & INCLUDE_HOLES) != 0; labels[4] = "Summarize"; states[4] = (options & DISPLAY_SUMMARY) != 0; labels[5] = "Record starts"; states[5] = (options & RECORD_STARTS) != 0; labels[6] = "Add to Manager"; states[6] = (options & ADD_TO_MANAGER) != 0; labels[7] = "In_situ Show"; states[7] = (options & IN_SITU_SHOW) != 0; gd.addCheckboxGroup(4, 2, labels, states); gd.addHelp(IJ.URL + "/docs/menus/analyze.html#ap"); gd.showDialog(); if (gd.wasCanceled()) return false; String size = gd.getNextString(); // min-max size if (scaled) pixelUnits = gd.getNextBoolean(); if (pixelUnits) unitSquared = 1.0; else unitSquared = cal.pixelWidth * cal.pixelHeight; String[] minAndMax = Tools.split(size, " -"); double mins = gd.parseDouble(minAndMax[0]); double maxs = minAndMax.length == 2 ? gd.parseDouble(minAndMax[1]) : Double.NaN; minSize = Double.isNaN(mins) ? DEFAULT_MIN_SIZE : mins / unitSquared; maxSize = Double.isNaN(maxs) ? DEFAULT_MAX_SIZE : maxs / unitSquared; if (minSize < DEFAULT_MIN_SIZE) minSize = DEFAULT_MIN_SIZE; if (maxSize < minSize) maxSize = DEFAULT_MAX_SIZE; staticMinSize = minSize; staticMaxSize = maxSize; minAndMax = Tools.split(gd.getNextString(), " -"); // min-max circularity double minc = gd.parseDouble(minAndMax[0]); double maxc = minAndMax.length == 2 ? gd.parseDouble(minAndMax[1]) : Double.NaN; minCircularity = Double.isNaN(minc) ? 0.0 : minc; maxCircularity = Double.isNaN(maxc) ? 1.0 : maxc; if (minCircularity < 0.0 || minCircularity > 1.0) minCircularity = 0.0; if (maxCircularity < minCircularity || maxCircularity > 1.0) maxCircularity = 1.0; if (minCircularity == 1.0 && maxCircularity == 1.0) minCircularity = 0.0; staticMinCircularity = minCircularity; staticMaxCircularity = maxCircularity; if (gd.invalidNumber()) { IJ.error("Bins invalid."); canceled = true; return false; } showChoice = gd.getNextChoiceIndex(); staticShowChoice = showChoice; if (gd.getNextBoolean()) options |= SHOW_RESULTS; else options &= ~SHOW_RESULTS; if (gd.getNextBoolean()) options |= EXCLUDE_EDGE_PARTICLES; else options &= ~EXCLUDE_EDGE_PARTICLES; if (gd.getNextBoolean()) options |= CLEAR_WORKSHEET; else options &= ~CLEAR_WORKSHEET; if (gd.getNextBoolean()) options |= INCLUDE_HOLES; else options &= ~INCLUDE_HOLES; if (gd.getNextBoolean()) options |= DISPLAY_SUMMARY; else options &= ~DISPLAY_SUMMARY; if (gd.getNextBoolean()) options |= RECORD_STARTS; else options &= ~RECORD_STARTS; if (gd.getNextBoolean()) options |= ADD_TO_MANAGER; else options &= ~ADD_TO_MANAGER; if (gd.getNextBoolean()) options |= IN_SITU_SHOW; else options &= ~IN_SITU_SHOW; staticOptions = options; options |= SHOW_PROGRESS; if ((options & DISPLAY_SUMMARY) != 0) Analyzer.setMeasurements(Analyzer.getMeasurements() | AREA); return true; }
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; }