Search in sources :

Example 36 with ExtendedGenericDialog

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

the class ResultsMatchCalculator method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Compare the points in two results sets\nand compute the match statistics");
    ResultsManager.addInput(gd, "Results1", inputOption1, InputSource.MEMORY);
    ResultsManager.addInput(gd, "Results2", inputOption2, InputSource.MEMORY);
    gd.addNumericField("Distance", dThreshold, 2);
    gd.addSlider("Increments", 0, 10, increments);
    gd.addNumericField("Delta", delta, 2);
    gd.addNumericField("Beta", beta, 2);
    gd.addCheckbox("Show_table", showTable);
    gd.addCheckbox("Show_pairs", showPairs);
    gd.addCheckbox("Save_classifications", saveClassifications);
    gd.addCheckbox("Id_analysis", idAnalysis);
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    inputOption1 = gd.getNextChoice();
    inputOption2 = gd.getNextChoice();
    dThreshold = gd.getNextNumber();
    increments = (int) gd.getNextNumber();
    delta = gd.getNextNumber();
    beta = gd.getNextNumber();
    showTable = gd.getNextBoolean();
    showPairs = gd.getNextBoolean();
    saveClassifications = gd.getNextBoolean();
    idAnalysis = gd.getNextBoolean();
    if (!(showTable || showPairs || saveClassifications)) {
        IJ.error(TITLE, "No outputs specified");
        return false;
    }
    // Check arguments
    try {
        Parameters.isPositive("Distance threshold", dThreshold);
        Parameters.isPositive("Increments", increments);
        Parameters.isAboveZero("Delta", delta);
        Parameters.isPositive("Beta", beta);
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    return true;
}
Also used : ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 37 with ExtendedGenericDialog

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

the class PeakFit method showSimpleDialog.

private int showSimpleDialog(final String filename) {
    GlobalSettings settings = SettingsManager.loadSettings(filename);
    // Initialise the fit config so that it can be used in the calibration wizard 
    fitConfig = settings.getFitEngineConfiguration().getFitConfiguration();
    boolean requireCalibration = requireCalibration(settings, filename);
    if (requireCalibration) {
        if (!showCalibrationWizard(settings, true))
            return DONE;
    }
    // Present dialog with simple output options: Image, Table
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Fit single-molecule localisations");
    if (!requireCalibration)
        gd.addCheckbox("Use_current_calibration", true);
    gd.addCheckbox("Show_table", showTable);
    gd.addCheckbox("Show_image", showImage);
    gd.showDialog();
    if (gd.wasCanceled())
        return DONE;
    boolean useCurrentCalibration = true;
    if (!requireCalibration)
        useCurrentCalibration = gd.getNextBoolean();
    showTable = gd.getNextBoolean();
    showImage = gd.getNextBoolean();
    if (!useCurrentCalibration) {
        if (!showCalibrationWizard(settings, false))
            return DONE;
    }
    // Restore fitting to default settings but maintain the calibrated width
    final double sd = fitConfig.getInitialPeakStdDev0();
    config = new FitEngineConfiguration(new FitConfiguration());
    fitConfig = config.getFitConfiguration();
    fitConfig.setInitialPeakStdDev(sd);
    // Allow to move 1 SD
    fitConfig.setCoordinateShiftFactor(1);
    resultsSettings = new ResultsSettings();
    // Do simple results output
    resultsSettings.resultsInMemory = true;
    resultsSettings.setResultsTable((showTable) ? ResultsTable.UNCALIBRATED : ResultsTable.NONE);
    if (showImage) {
        resultsSettings.setResultsImage(ResultsImage.SIGNAL_INTENSITY);
        resultsSettings.imageScale = Math.ceil(1024 / (FastMath.max(bounds.width, bounds.height)));
        resultsSettings.weightedImage = true;
        resultsSettings.equalisedImage = true;
    } else {
        resultsSettings.setResultsImage(ResultsImage.NONE);
    }
    // Log the settings we care about:
    calibration = settings.getCalibration();
    IJ.log("-=-=-=-");
    IJ.log("Peak Fit");
    IJ.log("-=-=-=-");
    Utils.log("Pixel pitch = %s", Utils.rounded(calibration.getNmPerPixel(), 4));
    Utils.log("Exposure Time = %s", Utils.rounded(calibration.getExposureTime(), 4));
    Utils.log("Gain = %s", Utils.rounded(calibration.getGain(), 4));
    Utils.log("PSF width = %s", Utils.rounded(fitConfig.getInitialPeakStdDev0(), 4));
    // Save
    settings.setFitEngineConfiguration(config);
    settings.setResultsSettings(resultsSettings);
    SettingsManager.saveSettings(settings, filename);
    return FLAGS;
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) FitConfiguration(gdsc.smlm.fitting.FitConfiguration) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ResultsSettings(gdsc.smlm.ij.settings.ResultsSettings)

Example 38 with ExtendedGenericDialog

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

the class PeakFit method showCalibrationWizard.

private boolean showCalibrationWizard(GlobalSettings settings, boolean showIntroduction) {
    if (showIntroduction) {
        ExtendedGenericDialog gd = newWizardDialog("No configuration file could be loaded.", "Please follow the configuration wizard to calibrate.");
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
    }
    //if (calibration.nmPerPixel <= 0 || calibration.nmPerPixel == defaultCalibration.nmPerPixel)
    if (!getPixelPitch())
        return false;
    //if (calibration.gain <= 0 || calibration.gain == defaultCalibration.gain)
    if (!getGain())
        return false;
    //if (calibration.exposureTime <= 0 || calibration.exposureTime == defaultCalibration.exposureTime)
    if (!getExposureTime())
        return false;
    //if (fitConfig.getInitialPeakWidth0() == new FitConfiguration().getInitialPeakWidth0())
    if (!getPeakWidth())
        return false;
    // Check parameters
    try {
        Parameters.isAboveZero("nm per pixel", calibration.getNmPerPixel());
        Parameters.isAboveZero("Gain", calibration.getGain());
        Parameters.isAboveZero("Exposure time", calibration.getExposureTime());
        Parameters.isAboveZero("Initial SD", fitConfig.getInitialPeakStdDev0());
    } catch (IllegalArgumentException e) {
        IJ.error(TITLE, e.getMessage());
        return false;
    }
    return true;
}
Also used : ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 39 with ExtendedGenericDialog

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

the class PeakFit method configureDataFilter.

/**
	 * Show a dialog to configure the data filter. The updated settings are saved to the settings file. An error
	 * message is shown if the dialog is cancelled or the configuration is invalid.
	 * 
	 * @param settings
	 * @param filename
	 * @param extraOptions
	 *            True if extra configuration options should be allowed
	 * @return True if the configuration succeeded
	 */
public static boolean configureDataFilter(GlobalSettings settings, String filename, boolean extraOptions) {
    FitEngineConfiguration config = settings.getFitEngineConfiguration();
    int numberOfFilters = 1;
    final int n;
    switch(config.getDataFilterType()) {
        case JURY:
            n = Integer.MAX_VALUE;
            break;
        case DIFFERENCE:
            n = 2;
            break;
        case SINGLE:
        default:
            n = 1;
    }
    String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values());
    for (int i = 1; i < n; i++) {
        int filter = i + 1;
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.enableYesNoCancel("Add", "Continue");
        gd.addMessage(String.format("Configure the %s filter.\nClick continue to proceed with the current set of %d.", config.getDataFilterType().toString(), i));
        String fieldName = "Spot_filter" + filter;
        if (IJ.isMacro())
            // Use blank default value so bad macro parameters return nothing
            gd.addStringField(fieldName, "");
        else
            gd.addChoice(fieldName, filterNames, filterNames[config.getDataFilter(i).ordinal()]);
        gd.addSlider("Smoothing" + filter, 0, 4.5, config.getSmooth(i));
        gd.showDialog();
        if (gd.wasCanceled())
            return false;
        if (gd.wasOKed()) {
            int filterIndex = -1;
            if (IJ.isMacro()) {
                String filterName = gd.getNextString();
                for (int j = 0; j < filterNames.length; j++) if (filterNames[j].equals(filterName)) {
                    filterIndex = j;
                    break;
                }
                if (filterIndex < 0)
                    break;
            } else
                filterIndex = gd.getNextChoiceIndex();
            config.setDataFilter(filterIndex, Math.abs(gd.getNextNumber()), i);
            numberOfFilters++;
        } else {
            break;
        }
    }
    config.setNumberOfFilters(numberOfFilters);
    if (filename != null)
        SettingsManager.saveSettings(settings, filename);
    return true;
}
Also used : FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 40 with ExtendedGenericDialog

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

the class PeakFit method addSingleFrameOverlay.

private void addSingleFrameOverlay() {
    // If a single frame was processed add the peaks as an overlay if they are in memory
    ImagePlus imp = this.imp;
    if (fitMaxima && singleFrame > 0) {
        if (source instanceof IJImageSource) {
            String title = source.getName();
            imp = WindowManager.getImage(title);
        }
    }
    if (singleFrame > 0 && imp != null) {
        MemoryPeakResults results = null;
        for (PeakResults r : this.results.toArray()) if (r instanceof MemoryPeakResults) {
            results = (MemoryPeakResults) r;
            break;
        }
        if (results == null || results.size() == 0)
            return;
        ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("Add the fitted localisations as an overlay?");
        gd.showDialog();
        if (!gd.wasOKed())
            return;
        LUT lut = LUTHelper.createLUT(LutColour.ICE);
        Overlay o = new Overlay();
        ArrayList<PeakResult> list = (ArrayList<PeakResult>) results.getResults();
        for (int i = 0, j = results.size() - 1; i < results.size(); i++, j--) {
            PeakResult r = list.get(i);
            PointRoi roi = new PointRoi(r.getXPosition(), r.getYPosition());
            Color c = LUTHelper.getColour(lut, j, results.size());
            roi.setStrokeColor(c);
            roi.setFillColor(c);
            if (imp.getStackSize() > 1)
                roi.setPosition(singleFrame);
            o.add(roi);
        }
        imp.setOverlay(o);
        imp.getWindow().toFront();
    }
}
Also used : Color(java.awt.Color) SystemColor(java.awt.SystemColor) ArrayList(java.util.ArrayList) LUT(ij.process.LUT) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) PeakResult(gdsc.smlm.results.PeakResult) ExtendedPeakResult(gdsc.smlm.results.ExtendedPeakResult) IJImageSource(gdsc.smlm.ij.IJImageSource) PeakResults(gdsc.smlm.results.PeakResults) IJTablePeakResults(gdsc.smlm.ij.results.IJTablePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) IJImagePeakResults(gdsc.smlm.ij.results.IJImagePeakResults) BinaryFilePeakResults(gdsc.smlm.results.BinaryFilePeakResults) MALKFilePeakResults(gdsc.smlm.results.MALKFilePeakResults) FilePeakResults(gdsc.smlm.results.FilePeakResults) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi)

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