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