Search in sources :

Example 6 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class SpotAnalysis method createProfile.

private void createProfile() {
    if (!parametersReady()) {
        return;
    }
    double psfWidth, blur;
    // Read settings
    try {
        psfWidth = Double.parseDouble(widthTextField.getText());
        blur = Double.parseDouble(blurTextField.getText());
        gain = Double.parseDouble(gainTextField.getText());
        msPerFrame = Double.parseDouble(exposureTextField.getText());
    } catch (NumberFormatException e) {
        IJ.error(TITLE, "Invalid numbers in the input parameters");
        return;
    }
    ImagePlus imp = WindowManager.getImage(inputChoice.getSelectedItem());
    // This should not be a problem but leave it in for now
    if (imp == null || (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16 && imp.getType() != ImagePlus.GRAY32)) {
        IJ.showMessage(TITLE, "Images must be grayscale.");
        return;
    }
    Roi roi = imp.getRoi();
    if (roi == null || !roi.isArea()) {
        IJ.showMessage(TITLE, "Image must have an area ROI");
        return;
    }
    int recommendedSize = (int) Math.ceil(8 * psfWidth);
    Rectangle bounds = roi.getBounds();
    if (bounds.width < recommendedSize || bounds.height < recommendedSize) {
        IJ.showMessage(TITLE, String.format("Recommend using an ROI of at least %d x %d for the PSF width", recommendedSize, recommendedSize));
        return;
    }
    // Check no existing spots are within the ROI
    if (resultsWithinBounds(bounds)) {
        GenericDialog gd = new GenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("The results list contains a spot within the selected bounds\n \nDo you want to continue?");
        gd.showDialog();
        if (!gd.wasOKed())
            return;
    }
    createProfile(imp, bounds, psfWidth, blur);
}
Also used : GenericDialog(ij.gui.GenericDialog) Rectangle(java.awt.Rectangle) ImagePlus(ij.ImagePlus) Roi(ij.gui.Roi) PointRoi(ij.gui.PointRoi) Point(java.awt.Point)

Example 7 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class SpotAnalysis method saveTraces.

private void saveTraces() {
    if (!onFrames.isEmpty() && updated) {
        GenericDialog gd = new GenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("The list contains unsaved selected frames.\n \nDo you want to continue?");
        gd.showDialog();
        if (!gd.wasOKed())
            return;
    }
    // For all spots in the results window, get the ID and then save the traces to memory
    if (!resultsWindowShowing())
        return;
    // Create a results set in memory
    MemoryPeakResults results = new MemoryPeakResults();
    results.setName(TITLE);
    results.begin();
    MemoryPeakResults.addResults(results);
    ArrayList<TraceResult> traceResults = new ArrayList<TraceResult>(resultsWindow.getTextPanel().getLineCount());
    for (int i = 0; i < resultsWindow.getTextPanel().getLineCount(); i++) {
        String line = resultsWindow.getTextPanel().getLine(i);
        Scanner s = new Scanner(line);
        s.useDelimiter("\t");
        int id = -1;
        double signal = -1;
        // Be careful as the text panel may not contain what we expect, i.e. empty lines, etc
        if (s.hasNextInt()) {
            id = s.nextInt();
            try {
                // cx
                s.nextDouble();
                // cy
                s.nextDouble();
                signal = s.nextDouble();
            } catch (InputMismatchException e) {
            // Ignore
            } catch (NoSuchElementException e) {
            // Ignore
            }
        }
        s.close();
        if (id != -1 && signal != -1) {
            Trace trace = traces.get(id);
            if (trace != null) {
                results.addAll(trace.getPoints());
                traceResults.add(new TraceResult(new Spot(id, signal), trace));
            }
        }
    }
    results.end();
    saveTracesToFile(traceResults);
    IJ.showStatus("Saved traces");
}
Also used : Scanner(java.util.Scanner) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) InputMismatchException(java.util.InputMismatchException) Point(java.awt.Point) Trace(gdsc.smlm.results.Trace) GenericDialog(ij.gui.GenericDialog) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class SmoothImage method showDialog.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.filter.ExtendedPlugInFilter#showDialog(ij.ImagePlus, java.lang.String,
	 * ij.plugin.filter.PlugInFilterRunner)
	 */
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
    // Note: We cannot use a NonBlockinnericDialog as scrolling through the image
    // throws away the snap shot. The pixel data for the previous slice is then fixed
    // with the preview. So we can only support a single slice.
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Smooth image:");
    gd.addChoice("Spot_filter", filterNames, filterNames[filter1]);
    gd.addSlider("Smoothing", 0, 4.5, smooth1);
    gd.addCheckbox("Difference_filter", differenceFilter);
    gd.addChoice("Spot_filter2", filterNames, filterNames[filter2]);
    gd.addSlider("Smoothing2", 1.5, 6, smooth2);
    gd.addPreviewCheckbox(pfr);
    gd.addDialogListener(this);
    gd.showDialog();
    if (gd.wasCanceled() || !dialogItemChanged(gd, null))
        return DONE;
    return IJ.setupDialog(imp, flags);
}
Also used : GenericDialog(ij.gui.GenericDialog)

Example 9 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class CreateData method showSimpleDialog.

/**
	 * Show a dialog allowing the parameters for a simple/benchmark simulation to be performed
	 * 
	 * @return True if the parameters were collected
	 */
private boolean showSimpleDialog() {
    GenericDialog gd = new GenericDialog(TITLE);
    globalSettings = SettingsManager.loadSettings();
    settings = globalSettings.getCreateDataSettings();
    // Image size
    gd.addMessage("--- Image Size ---");
    gd.addNumericField("Pixel_pitch (nm)", settings.pixelPitch, 2);
    gd.addNumericField("Size (px)", settings.size, 0);
    if (!benchmarkMode) {
        gd.addNumericField("Depth (nm)", settings.depth, 0);
        gd.addCheckbox("Fixed_depth", settings.fixedDepth);
    }
    // Noise model
    gd.addMessage("--- Noise Model ---");
    if (extraOptions)
        gd.addCheckbox("No_poisson_noise", !settings.poissonNoise);
    gd.addNumericField("Background (photons)", settings.background, 2);
    gd.addNumericField("EM_gain", settings.getEmGain(), 2);
    gd.addNumericField("Camera_gain (ADU/e-)", settings.getCameraGain(), 4);
    gd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2);
    gd.addNumericField("Read_noise (e-)", settings.readNoise, 2);
    gd.addNumericField("Bias", settings.bias, 0);
    // PSF Model
    List<String> imageNames = addPSFOptions(gd);
    gd.addMessage("--- Fluorophores ---");
    Component splitLabel = gd.getMessage();
    // Do not allow grid or mask distribution
    if (simpleMode) {
        // Allow mask but not the grid
        gd.addChoice("Distribution", Arrays.copyOf(DISTRIBUTION, DISTRIBUTION.length - 1), settings.distribution);
        gd.addCheckbox("Sample_per_frame", settings.samplePerFrame);
    }
    gd.addNumericField("Particles", settings.particles, 0);
    if (simpleMode)
        gd.addNumericField("Density (um^-2)", settings.density, 2);
    else if (benchmarkMode) {
        gd.addNumericField("X_position (nm)", settings.xPosition, 2);
        gd.addNumericField("Y_position (nm)", settings.yPosition, 2);
        gd.addNumericField("Z_position (nm)", settings.zPosition, 2);
    }
    gd.addNumericField("Min_Photons", settings.photonsPerSecond, 0);
    gd.addNumericField("Max_Photons", settings.photonsPerSecondMaximum, 0);
    gd.addMessage("--- Save options ---");
    gd.addCheckbox("Raw_image", settings.rawImage);
    gd.addCheckbox("Save_image", settings.saveImage);
    gd.addCheckbox("Save_image_results", settings.saveImageResults);
    gd.addCheckbox("Save_localisations", settings.saveLocalisations);
    gd.addMessage("--- Report options ---");
    gd.addCheckbox("Show_histograms", settings.showHistograms);
    gd.addCheckbox("Choose_histograms", settings.chooseHistograms);
    gd.addNumericField("Histogram_bins", settings.histogramBins, 0);
    gd.addCheckbox("Remove_outliers", settings.removeOutliers);
    if (simpleMode)
        gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.densityRadius);
    gd.addNumericField("Depth-of-field (nm)", settings.depthOfField, 0);
    if (gd.getLayout() != null) {
        GridBagLayout grid = (GridBagLayout) gd.getLayout();
        int xOffset = 0, yOffset = 0;
        int lastY = -1, rowCount = 0;
        for (Component comp : gd.getComponents()) {
            // Check if this should be the second major column
            if (comp == splitLabel) {
                xOffset += 2;
                yOffset -= rowCount;
                rowCount = 0;
            }
            // Reposition the field
            GridBagConstraints c = grid.getConstraints(comp);
            if (lastY != c.gridy)
                rowCount++;
            lastY = c.gridy;
            c.gridx = c.gridx + xOffset;
            c.gridy = c.gridy + yOffset;
            c.insets.left = c.insets.left + 10 * xOffset;
            c.insets.top = 0;
            c.insets.bottom = 0;
            grid.setConstraints(comp, c);
        }
        if (IJ.isLinux())
            gd.setBackground(new Color(238, 238, 238));
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    settings.pixelPitch = Math.abs(gd.getNextNumber());
    settings.size = Math.abs((int) gd.getNextNumber());
    if (!benchmarkMode) {
        // Allow negative depth
        settings.depth = gd.getNextNumber();
        settings.fixedDepth = gd.getNextBoolean();
    }
    if (extraOptions)
        poissonNoise = settings.poissonNoise = !gd.getNextBoolean();
    settings.background = Math.abs(gd.getNextNumber());
    settings.setEmGain(Math.abs(gd.getNextNumber()));
    settings.setCameraGain(Math.abs(gd.getNextNumber()));
    settings.setQuantumEfficiency(Math.abs(gd.getNextNumber()));
    settings.readNoise = Math.abs(gd.getNextNumber());
    settings.bias = Math.abs((int) gd.getNextNumber());
    if (!collectPSFOptions(gd, imageNames))
        return false;
    if (simpleMode) {
        settings.distribution = gd.getNextChoice();
        settings.samplePerFrame = gd.getNextBoolean();
    }
    settings.particles = Math.abs((int) gd.getNextNumber());
    if (simpleMode)
        settings.density = Math.abs(gd.getNextNumber());
    else if (benchmarkMode) {
        settings.xPosition = gd.getNextNumber();
        settings.yPosition = gd.getNextNumber();
        settings.zPosition = gd.getNextNumber();
    }
    settings.photonsPerSecond = Math.abs((int) gd.getNextNumber());
    settings.photonsPerSecondMaximum = Math.abs((int) gd.getNextNumber());
    settings.rawImage = gd.getNextBoolean();
    settings.saveImage = gd.getNextBoolean();
    settings.saveImageResults = gd.getNextBoolean();
    settings.saveLocalisations = gd.getNextBoolean();
    settings.showHistograms = gd.getNextBoolean();
    settings.chooseHistograms = gd.getNextBoolean();
    settings.histogramBins = (int) Math.abs(gd.getNextNumber());
    settings.removeOutliers = gd.getNextBoolean();
    if (simpleMode)
        settings.densityRadius = (float) gd.getNextNumber();
    settings.depthOfField = (float) Math.abs(gd.getNextNumber());
    // Save before validation so that the current values are preserved.
    SettingsManager.saveSettings(globalSettings);
    if (gd.invalidNumber())
        return false;
    // Check arguments
    try {
        Parameters.isAboveZero("Pixel Pitch", settings.pixelPitch);
        Parameters.isAboveZero("Size", settings.size);
        if (!benchmarkMode && !settings.fixedDepth)
            Parameters.isPositive("Depth", settings.depth);
        Parameters.isPositive("Background", settings.background);
        Parameters.isPositive("EM gain", settings.getEmGain());
        Parameters.isPositive("Camera gain", settings.getCameraGain());
        Parameters.isPositive("Read noise", settings.readNoise);
        double noiseRange = settings.readNoise * settings.getCameraGain() * 4;
        Parameters.isEqualOrAbove("Bias must prevent clipping the read noise (@ +/- 4 StdDev) so ", settings.bias, noiseRange);
        Parameters.isAboveZero("Particles", settings.particles);
        if (simpleMode)
            Parameters.isAboveZero("Density", settings.density);
        Parameters.isAboveZero("Min Photons", settings.photonsPerSecond);
        if (settings.photonsPerSecondMaximum < settings.photonsPerSecond)
            settings.photonsPerSecondMaximum = settings.photonsPerSecond;
        if (!imagePSF) {
            Parameters.isAboveZero("Wavelength", settings.wavelength);
            Parameters.isAboveZero("NA", settings.numericalAperture);
            Parameters.isBelow("NA", settings.numericalAperture, 2);
        }
        Parameters.isPositive("Histogram bins", settings.histogramBins);
        if (simpleMode)
            Parameters.isPositive("Density radius", settings.densityRadius);
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    if (settings.distribution.equals(DISTRIBUTION[MASK])) {
        String[] maskImages = createDistributionImageList();
        if (maskImages != null) {
            gd = new GenericDialog(TITLE);
            gd.addMessage("Select the mask image for the distribution");
            gd.addChoice("Distribution_mask", maskImages, settings.distributionMask);
            if (maskListContainsStacks)
                gd.addNumericField("Distribution_slice_depth (nm)", settings.distributionMaskSliceDepth, 0);
            gd.showDialog();
            if (gd.wasCanceled())
                return false;
            settings.distributionMask = gd.getNextChoice();
            if (maskListContainsStacks)
                settings.distributionMaskSliceDepth = Math.abs(gd.getNextNumber());
        }
        SettingsManager.saveSettings(globalSettings);
    }
    return getHistogramOptions();
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) GenericDialog(ij.gui.GenericDialog) Color(java.awt.Color) Component(java.awt.Component)

Example 10 with GenericDialog

use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.

the class CMOSAnalysis method showDialog.

private boolean showDialog() {
    // Determine sub-directories to process
    File dir = new File(directory);
    File[] dirs = dir.listFiles(new FileFilter() {

        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });
    if (dirs.length == 0) {
        IJ.error(TITLE, "No sub-directories");
        return false;
    }
    // Get only those with numbers at the end. 
    // These should correspond to exposure times
    subDirs = new TurboList<SubDir>();
    Pattern p = Pattern.compile("([0-9]+)$");
    for (File path : dirs) {
        String name = path.getName();
        Matcher m = p.matcher(name);
        if (m.find()) {
            int t = Integer.parseInt(m.group(1));
            subDirs.add(new SubDir(t, path, name));
        }
    }
    if (subDirs.size() < 2) {
        IJ.error(TITLE, "Not enough sub-directories with exposure time suffix");
        return false;
    }
    Collections.sort(subDirs);
    if (subDirs.get(0).exposureTime != 0) {
        IJ.error(TITLE, "No sub-directories with exposure time 0");
        return false;
    }
    for (SubDir sd : subDirs) {
        Utils.log("Sub-directory: %s. Exposure time = %d", sd.name, sd.exposureTime);
    }
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    //@formatter:off
    gd.addMessage("Analyse the per-pixel offset, variance and gain of sCMOS images.\n \n" + TextUtils.wrap("See Huang et al (2013) Video-rate nanoscopy using sCMOS camera–specific " + "single-molecule localization algorithms. Nature Methods 10, 653-658 " + "(Supplementary Information).", 80));
    //@formatter:on
    gd.addNumericField("nThreads", getLastNThreads(), 0);
    gd.addCheckbox("Rolling_algorithm", rollingAlgorithm);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    setThreads((int) gd.getNextNumber());
    rollingAlgorithm = gd.getNextBoolean();
    return true;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) GenericDialog(ij.gui.GenericDialog) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

GenericDialog (ij.gui.GenericDialog)87 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)12 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)10 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)9 Checkbox (java.awt.Checkbox)9 Color (java.awt.Color)8 Component (java.awt.Component)8 GridBagConstraints (java.awt.GridBagConstraints)8 GridBagLayout (java.awt.GridBagLayout)8 Rectangle (java.awt.Rectangle)7 BasePoint (gdsc.core.match.BasePoint)6 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)6 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)6 Calibration (gdsc.smlm.results.Calibration)6 ArrayList (java.util.ArrayList)6 PeakResult (gdsc.smlm.results.PeakResult)5 TextField (java.awt.TextField)5 File (java.io.File)5 Vector (java.util.Vector)5 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)4