Search in sources :

Example 26 with ExtendedGenericDialog

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

the class NeighbourAnalysis method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
    gd.addNumericField("Distance_Threshold (px)", distanceThreshold, 4);
    gd.addNumericField("Time_Threshold (frames)", timeThreshold, 0);
    gd.showDialog();
    if (gd.wasCanceled() || !readDialog(gd))
        return false;
    // Load the results
    results = ResultsManager.loadInputResults(inputOption, false);
    if (results == null || results.size() == 0) {
        IJ.error(TITLE, "No results could be loaded");
        IJ.showStatus("");
        return false;
    }
    return true;
}
Also used : ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 27 with ExtendedGenericDialog

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

the class PCPALMMolecules method getRunMode.

private boolean getRunMode(boolean resultsAvailable) {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    // Build a list of all images with a region ROI
    List<String> titles = new LinkedList<String>();
    if (WindowManager.getWindowCount() > 0) {
        for (int imageID : WindowManager.getIDList()) {
            ImagePlus imp = WindowManager.getImage(imageID);
            if (imp != null && imp.getRoi() != null && imp.getRoi().isArea())
                titles.add(imp.getTitle());
        }
    }
    if (!resultsAvailable) {
        runMode = 3;
        gd.addMessage("Simulate molecules for cluster analysis.\nComputes a binary image from localisation data");
        gd.addNumericField("Molecules", nMolecules, 0);
        gd.addNumericField("Simulation_size (um)", simulationSize, 2);
        gd.addNumericField("Blinking_rate", blinkingRate, 2);
        gd.addChoice("Blinking_distribution", BLINKING_DISTRIBUTION, BLINKING_DISTRIBUTION[blinkingDistribution]);
        gd.addNumericField("Average_precision (nm)", sigmaS, 2);
        gd.addCheckbox("Show_histograms", showHistograms);
        gd.addCheckbox("Distance_analysis", distanceAnalysis);
        gd.addChoice("Cluster_simulation", CLUSTER_SIMULATION, CLUSTER_SIMULATION[clusterSimulation]);
        gd.addNumericField("Cluster_number", clusterNumber, 2);
        gd.addNumericField("Cluster_variation (SD)", clusterNumberSD, 2);
        gd.addNumericField("Cluster_radius", clusterRadius, 2);
        gd.addCheckbox("Show_cluster_mask", showClusterMask);
        Recorder.recordOption("Run_mode", RUN_MODE[runMode]);
    } else {
        gd.addMessage("Prepare molecules for cluster analysis.\nComputes a binary image from raw localisation data");
        ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
        if (!titles.isEmpty())
            gd.addCheckbox((titles.size() == 1) ? "Use_ROI" : "Choose_ROI", chooseRoi);
        gd.addChoice("Run_mode", RUN_MODE, RUN_MODE[runMode]);
    }
    gd.addMessage("Select options for low resolution image:");
    gd.addSlider("Image_size (px)", 512, 2048, lowResolutionImageSize);
    gd.addSlider("ROI_size (um)", 1.5, 4, roiSizeInUm);
    gd.addMessage("Select options for high resolution image:");
    gd.addCheckbox("Show_high_res_image", showHighResolutionImage);
    gd.addSlider("nm_per_pixel_limit", 0, 20, nmPerPixelLimit);
    gd.addMessage("Optionally remove all analysis results from memory");
    gd.addCheckbox("Clear_results", clearResults);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    if (!resultsAvailable) {
        nMolecules = (int) Math.abs(gd.getNextNumber());
        simulationSize = Math.abs(gd.getNextNumber());
        blinkingRate = Math.abs(gd.getNextNumber());
        blinkingDistribution = gd.getNextChoiceIndex();
        sigmaS = Math.abs(gd.getNextNumber());
        showHistograms = gd.getNextBoolean();
        distanceAnalysis = gd.getNextBoolean();
        clusterSimulation = gd.getNextChoiceIndex();
        clusterNumber = Math.abs(gd.getNextNumber());
        clusterNumberSD = Math.abs(gd.getNextNumber());
        clusterRadius = Math.abs(gd.getNextNumber());
        showClusterMask = gd.getNextBoolean();
    } else {
        inputOption = ResultsManager.getInputSource(gd);
        if (!titles.isEmpty())
            chooseRoi = gd.getNextBoolean();
        runMode = gd.getNextChoiceIndex();
    }
    lowResolutionImageSize = (int) gd.getNextNumber();
    roiSizeInUm = gd.getNextNumber();
    showHighResolutionImage = gd.getNextBoolean();
    nmPerPixelLimit = Math.abs(gd.getNextNumber());
    clearResults = gd.getNextBoolean();
    // Check arguments
    try {
        if (!resultsAvailable) {
            Parameters.isAboveZero("Molecules", nMolecules);
            Parameters.isAboveZero("Simulation size", simulationSize);
            Parameters.isEqualOrAbove("Blinking rate", blinkingRate, 1);
            Parameters.isEqualOrAbove("Cluster number", clusterNumber, 1);
        }
        Parameters.isAbove("Image scale", lowResolutionImageSize, 1);
        Parameters.isAboveZero("ROI size", roiSizeInUm);
    } catch (IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    if (!titles.isEmpty() && chooseRoi && resultsAvailable) {
        if (titles.size() == 1) {
            roiImage = titles.get(0);
            Recorder.recordOption("Image", roiImage);
        } else {
            String[] items = titles.toArray(new String[titles.size()]);
            gd = new ExtendedGenericDialog(TITLE);
            gd.addMessage("Select the source image for the ROI");
            gd.addChoice("Image", items, roiImage);
            gd.showDialog();
            if (gd.wasCanceled())
                return false;
            roiImage = gd.getNextChoice();
        }
        ImagePlus imp = WindowManager.getImage(roiImage);
        roiBounds = imp.getRoi().getBounds();
        roiImageWidth = imp.getWidth();
        roiImageHeight = imp.getHeight();
    } else {
        roiBounds = null;
    }
    if (!resultsAvailable) {
        if (!getPValue())
            return false;
    }
    if (clearResults) {
        PCPALMAnalysis.results.clear();
        PCPALMFitting.previous_gr = null;
    }
    return true;
}
Also used : ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) LinkedList(java.util.LinkedList) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Example 28 with ExtendedGenericDialog

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

the class FIRE method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Compute the resolution using Fourier Ring Correlation");
    gd.addHelp(About.HELP_URL);
    boolean single = results2 == null;
    gd.addMessage("Image construction options:");
    gd.addChoice("Image_scale", SCALE_ITEMS, SCALE_ITEMS[imageScaleIndex]);
    gd.addChoice("Auto_image_size", IMAGE_SIZE_ITEMS, IMAGE_SIZE_ITEMS[imageSizeIndex]);
    if (extraOptions)
        gd.addCheckbox("Use_signal (if present)", useSignal);
    gd.addNumericField("Max_per_bin", maxPerBin, 0);
    gd.addMessage("Fourier options:");
    String[] fourierMethodNames = SettingsManager.getNames((Object[]) FRC.FourierMethod.values());
    gd.addChoice("Fourier_method", fourierMethodNames, fourierMethodNames[fourierMethodIndex]);
    String[] samplingMethodNames = SettingsManager.getNames((Object[]) FRC.SamplingMethod.values());
    gd.addChoice("Sampling_method", samplingMethodNames, samplingMethodNames[samplingMethodIndex]);
    gd.addSlider("Sampling_factor", 0.2, 4, perimeterSamplingFactor);
    gd.addMessage("FIRE options:");
    String[] thresholdMethodNames = SettingsManager.getNames((Object[]) FRC.ThresholdMethod.values());
    gd.addChoice("Threshold_method", thresholdMethodNames, thresholdMethodNames[thresholdMethodIndex]);
    gd.addCheckbox("Show_FRC_curve", showFRCCurve);
    if (single) {
        gd.addMessage("For single datasets:");
        Label l = (Label) gd.getMessage();
        gd.addNumericField("Block_size", blockSize, 0);
        gd.addCheckbox("Random_split", randomSplit);
        gd.addNumericField("Repeats", repeats, 0);
        gd.addCheckbox("Show_FRC_curve_repeats", showFRCCurveRepeats);
        gd.addCheckbox("Show_FRC_time_evolution", showFRCTimeEvolution);
        gd.addCheckbox("Spurious correlation correction", spuriousCorrelationCorrection);
        gd.addNumericField("Q-value", qValue, 3);
        gd.addNumericField("Precision_Mean", mean, 2, 6, "nm");
        gd.addNumericField("Precision_Sigma", sigma, 2, 6, "nm");
        if (extraOptions)
            gd.addNumericField("Threads", getLastNThreads(), 0);
        // Rearrange the dialog
        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 == l) {
                    xOffset += 2;
                    // Skip title row
                    yOffset = yOffset - rowCount + 1;
                }
                // 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;
    imageScaleIndex = gd.getNextChoiceIndex();
    imageSizeIndex = gd.getNextChoiceIndex();
    if (extraOptions)
        myUseSignal = useSignal = gd.getNextBoolean();
    maxPerBin = Math.abs((int) gd.getNextNumber());
    fourierMethodIndex = gd.getNextChoiceIndex();
    fourierMethod = FourierMethod.values()[fourierMethodIndex];
    samplingMethodIndex = gd.getNextChoiceIndex();
    samplingMethod = SamplingMethod.values()[samplingMethodIndex];
    perimeterSamplingFactor = gd.getNextNumber();
    thresholdMethodIndex = gd.getNextChoiceIndex();
    thresholdMethod = FRC.ThresholdMethod.values()[thresholdMethodIndex];
    showFRCCurve = gd.getNextBoolean();
    if (single) {
        blockSize = Math.max(1, (int) gd.getNextNumber());
        randomSplit = gd.getNextBoolean();
        repeats = Math.max(1, (int) gd.getNextNumber());
        showFRCCurveRepeats = gd.getNextBoolean();
        showFRCTimeEvolution = gd.getNextBoolean();
        spuriousCorrelationCorrection = gd.getNextBoolean();
        qValue = Math.abs(gd.getNextNumber());
        mean = Math.abs(gd.getNextNumber());
        sigma = Math.abs(gd.getNextNumber());
        if (extraOptions) {
            setThreads((int) gd.getNextNumber());
            lastNThreads = this.nThreads;
        }
    }
    // Check arguments
    try {
        Parameters.isAboveZero("Perimeter sampling factor", perimeterSamplingFactor);
        if (single && spuriousCorrelationCorrection) {
            Parameters.isAboveZero("Q-value", qValue);
            Parameters.isAboveZero("Precision Mean", mean);
            Parameters.isAboveZero("Precision Sigma", sigma);
            // Set these for use in FIRE computation 
            setCorrectionParameters(qValue, mean, sigma);
        }
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    return true;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Color(java.awt.Color) Label(java.awt.Label) NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) Component(java.awt.Component) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Example 29 with ExtendedGenericDialog

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

the class FIRE method showQEstimationInputDialog.

private boolean showQEstimationInputDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    // Build a list of all images with a region ROI
    List<String> titles = new LinkedList<String>();
    if (WindowManager.getWindowCount() > 0) {
        for (int imageID : WindowManager.getIDList()) {
            ImagePlus imp = WindowManager.getImage(imageID);
            if (imp != null && imp.getRoi() != null && imp.getRoi().isArea())
                titles.add(imp.getTitle());
        }
    }
    gd.addMessage("Estimate the blinking correction parameter Q for Fourier Ring Correlation");
    ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
    if (!titles.isEmpty())
        gd.addCheckbox((titles.size() == 1) ? "Use_ROI" : "Choose_ROI", chooseRoi);
    gd.addMessage("Image construction options:");
    //gd.addCheckbox("Use_signal (if present)", useSignal);
    gd.addChoice("Image_scale", SCALE_ITEMS, SCALE_ITEMS[imageScaleIndex]);
    gd.addChoice("Auto_image_size", IMAGE_SIZE_ITEMS, IMAGE_SIZE_ITEMS[imageSizeIndex]);
    gd.addNumericField("Block_size", blockSize, 0);
    gd.addCheckbox("Random_split", randomSplit);
    gd.addNumericField("Max_per_bin", maxPerBin, 0);
    gd.addMessage("Fourier options:");
    String[] fourierMethodNames = SettingsManager.getNames((Object[]) FRC.FourierMethod.values());
    gd.addChoice("Fourier_method", fourierMethodNames, fourierMethodNames[fourierMethodIndex]);
    String[] samplingMethodNames = SettingsManager.getNames((Object[]) FRC.SamplingMethod.values());
    gd.addChoice("Sampling_method", samplingMethodNames, samplingMethodNames[samplingMethodIndex]);
    gd.addSlider("Sampling_factor", 0.2, 4, perimeterSamplingFactor);
    gd.addMessage("Estimation options:");
    String[] thresholdMethodNames = SettingsManager.getNames((Object[]) FRC.ThresholdMethod.values());
    gd.addChoice("Threshold_method", thresholdMethodNames, thresholdMethodNames[thresholdMethodIndex]);
    String[] precisionMethodNames = SettingsManager.getNames((Object[]) PrecisionMethod.values());
    gd.addChoice("Precision_method", precisionMethodNames, precisionMethodNames[precisionMethodIndex]);
    gd.addNumericField("Precision_Mean", mean, 2, 6, "nm");
    gd.addNumericField("Precision_Sigma", sigma, 2, 6, "nm");
    gd.addCheckbox("Sample_decay", sampleDecay);
    gd.addCheckbox("LOESS_smoothing", loessSmoothing);
    gd.addCheckbox("Fit_precision", fitPrecision);
    gd.addSlider("MinQ", 0, 0.4, minQ);
    gd.addSlider("MaxQ", 0.1, 0.5, maxQ);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    inputOption = ResultsManager.getInputSource(gd);
    if (!titles.isEmpty())
        chooseRoi = gd.getNextBoolean();
    //useSignal = gd.getNextBoolean();
    imageScaleIndex = gd.getNextChoiceIndex();
    imageSizeIndex = gd.getNextChoiceIndex();
    blockSize = Math.max(1, (int) gd.getNextNumber());
    randomSplit = gd.getNextBoolean();
    maxPerBin = Math.abs((int) gd.getNextNumber());
    fourierMethodIndex = gd.getNextChoiceIndex();
    fourierMethod = FourierMethod.values()[fourierMethodIndex];
    samplingMethodIndex = gd.getNextChoiceIndex();
    samplingMethod = SamplingMethod.values()[samplingMethodIndex];
    perimeterSamplingFactor = gd.getNextNumber();
    thresholdMethodIndex = gd.getNextChoiceIndex();
    thresholdMethod = FRC.ThresholdMethod.values()[thresholdMethodIndex];
    precisionMethodIndex = gd.getNextChoiceIndex();
    precisionMethod = PrecisionMethod.values()[precisionMethodIndex];
    mean = Math.abs(gd.getNextNumber());
    sigma = Math.abs(gd.getNextNumber());
    sampleDecay = gd.getNextBoolean();
    loessSmoothing = gd.getNextBoolean();
    fitPrecision = gd.getNextBoolean();
    minQ = Maths.clip(0, 0.5, gd.getNextNumber());
    maxQ = Maths.clip(0, 0.5, gd.getNextNumber());
    // Check arguments
    try {
        Parameters.isAboveZero("Perimeter sampling factor", perimeterSamplingFactor);
        if (precisionMethod == PrecisionMethod.FIXED) {
            Parameters.isAboveZero("Precision Mean", mean);
            Parameters.isAboveZero("Precision Sigma", sigma);
        }
        Parameters.isAbove("MaxQ", maxQ, minQ);
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    if (!titles.isEmpty() && chooseRoi) {
        if (titles.size() == 1) {
            roiImage = titles.get(0);
            Recorder.recordOption("Image", roiImage);
        } else {
            String[] items = titles.toArray(new String[titles.size()]);
            gd = new ExtendedGenericDialog(TITLE);
            gd.addMessage("Select the source image for the ROI");
            gd.addChoice("Image", items, roiImage);
            gd.showDialog();
            if (gd.wasCanceled())
                return false;
            roiImage = gd.getNextChoice();
        }
        ImagePlus imp = WindowManager.getImage(roiImage);
        roiBounds = imp.getRoi().getBounds();
        roiImageWidth = imp.getWidth();
        roiImageHeight = imp.getHeight();
    } else {
        roiBounds = null;
    }
    return true;
}
Also used : NonBlockingExtendedGenericDialog(ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) LinkedList(java.util.LinkedList) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Example 30 with ExtendedGenericDialog

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

the class FilterResults method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    GlobalSettings gs = SettingsManager.loadSettings();
    filterSettings = gs.getFilterSettings();
    checkLimits();
    gd.addSlider("Max_drift", minDrift, maxDrift, filterSettings.maxDrift);
    gd.addSlider("Min_Signal", minSignal, maxSignal, filterSettings.minSignal);
    gd.addSlider("Min_SNR", minSNR, maxSNR, filterSettings.minSNR);
    gd.addSlider("Min_Precision", minPrecision, maxPrecision, filterSettings.maxPrecision);
    // TODO - If calibrated present the widths in nm
    gd.addMessage("Average Width = " + IJ.d2s(averageWidth, 3));
    gd.addSlider("Min_Width", minWidth, maxWidth, filterSettings.minWidth);
    gd.addSlider("Max_Width", minWidth, maxWidth, filterSettings.maxWidth);
    // Get a list of potential mask images
    String[] items = getImageList();
    gd.addChoice("Mask", items, filterSettings.maskTitle);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    filterSettings.maxDrift = (float) gd.getNextNumber();
    filterSettings.minSignal = (float) gd.getNextNumber();
    filterSettings.minSNR = (float) gd.getNextNumber();
    filterSettings.maxPrecision = (float) gd.getNextNumber();
    filterSettings.minWidth = (float) gd.getNextNumber();
    filterSettings.maxWidth = (float) gd.getNextNumber();
    filterSettings.maskTitle = gd.getNextChoice();
    return SettingsManager.saveSettings(gs);
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Aggregations

ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)60 ImagePlus (ij.ImagePlus)11 NonBlockingExtendedGenericDialog (ij.gui.NonBlockingExtendedGenericDialog)8 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)6 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)6 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)6 Calibration (gdsc.smlm.results.Calibration)5 ClusterPoint (gdsc.core.clustering.ClusterPoint)4 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)4 PeakResult (gdsc.smlm.results.PeakResult)4 Rectangle (java.awt.Rectangle)4 LinkedList (java.util.LinkedList)4 ArrayList (java.util.ArrayList)3 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)3 IJImageSource (gdsc.smlm.ij.IJImageSource)2 IJTablePeakResults (gdsc.smlm.ij.results.IJTablePeakResults)2 ResultsSettings (gdsc.smlm.ij.settings.ResultsSettings)2 ImageSource (gdsc.smlm.results.ImageSource)2 Trace (gdsc.smlm.results.Trace)2 Filter (gdsc.smlm.results.filter.Filter)2