Search in sources :

Example 91 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class TraceDiffusion method readDialog.

private boolean readDialog(ExtendedGenericDialog gd) {
    clusteringSettings.setTruncate(gd.getNextBoolean());
    clusteringSettings.setInternalDistances(gd.getNextBoolean());
    // settings.subSampledDistances = gd.getNextBoolean();
    clusteringSettings.setFitLength((int) Math.abs(gd.getNextNumber()));
    clusteringSettings.setMsdCorrection(gd.getNextBoolean());
    clusteringSettings.setPrecisionCorrection(gd.getNextBoolean());
    clusteringSettings.setMle(gd.getNextBoolean());
    settings.significanceLevel = Math.abs(gd.getNextNumber());
    clusteringSettings.setFitRestarts((int) Math.abs(gd.getNextNumber()));
    clusteringSettings.setJumpDistance((int) Math.abs(gd.getNextNumber()));
    settings.minDifference = Math.abs(gd.getNextNumber());
    settings.minFraction = Math.abs(gd.getNextNumber());
    if (extraOptions) {
        myMinN = settings.minN = (int) Math.abs(gd.getNextNumber());
    }
    settings.maxN = (int) Math.abs(gd.getNextNumber());
    settings.debugFitting = gd.getNextBoolean();
    settings.saveTraceDistances = gd.getNextBoolean();
    settings.saveRawData = gd.getNextBoolean();
    clusteringSettings.setShowHistograms(gd.getNextBoolean());
    settings.title = gd.getNextString();
    if (gd.invalidNumber()) {
        return false;
    }
    if (clusteringSettings.getShowHistograms()) {
        gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("Select the histograms to display");
        gd.addCheckbox("Remove_outliers", clusteringSettings.getRemoveOutliers());
        gd.addNumericField("Histogram_bins", clusteringSettings.getHistogramBins(), 0);
        for (int i = 0; i < settings.displayHistograms.length; i++) {
            gd.addCheckbox(Settings.NAMES[i].replace(' ', '_'), settings.displayHistograms[i]);
        }
        gd.addCheckbox("MSD/Molecule", settings.displayMsdHistogram);
        gd.addCheckbox("D/Molecule", settings.displayDHistogram);
        gd.addCheckbox("Trace_length", settings.displayTraceLength);
        gd.addCheckbox("Trace_size", settings.displayTraceSize);
        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }
        clusteringSettings.setRemoveOutliers(gd.getNextBoolean());
        clusteringSettings.setHistogramBins((int) Math.abs(gd.getNextNumber()));
        for (int i = 0; i < settings.displayHistograms.length; i++) {
            settings.displayHistograms[i] = gd.getNextBoolean();
        }
        settings.displayMsdHistogram = gd.getNextBoolean();
        settings.displayDHistogram = gd.getNextBoolean();
        settings.displayTraceLength = gd.getNextBoolean();
        settings.displayTraceSize = gd.getNextBoolean();
    }
    // Check arguments
    try {
        // Parameters.isAboveZero("Histogram bins", settings.getHistogramBins());
        ParameterUtils.isAbove("Fit length", clusteringSettings.getFitLength(), 1);
        ParameterUtils.isAboveZero("Jump distance", clusteringSettings.getJumpDistance());
        ParameterUtils.isEqualOrAbove("Maximum N", settings.maxN, myMinN);
        if (clusteringSettings.getMle()) {
            ParameterUtils.isAboveZero("Significance level", settings.significanceLevel);
        }
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    return true;
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 92 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class TraceMolecules method getParameters.

private boolean getParameters(int traceCount, double distance) {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(pluginTitle + " Optimiser");
    final String msg = String.format("Estimate %d molecules at d=%f, t=1", traceCount, distance);
    IJ.log(msg);
    gd.addMessage(msg);
    gd.addNumericField("Min_Distance_Threshold (px)", settings.getMinDistanceThreshold(), 2);
    gd.addNumericField("Max_Distance_Threshold (px)", settings.getMaxDistanceThreshold(), 2);
    gd.addNumericField("Min_Time_Threshold (frames)", settings.getMinTimeThreshold(), 0);
    gd.addNumericField("Max_Time_Threshold (frames)", settings.getMaxTimeThreshold(), 0);
    gd.addSlider("Steps", 1, 20, settings.getOptimiserSteps());
    gd.addNumericField("Blinking_rate", settings.getBlinkingRate(), 2);
    final String[] plotNames = SettingsManager.getNames((Object[]) OptimiserPlot.values());
    gd.addChoice("Plot", plotNames, plotNames[OptimiserPlot.get(settings.getOptimiserPlot()).ordinal()]);
    if (altKeyDown) {
        gd.addCheckbox("Optimise_blinking", pluginSettings.inputOptimiseBlinkingRate);
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.setMinDistanceThreshold(gd.getNextNumber());
    settings.setMaxDistanceThreshold(gd.getNextNumber());
    settings.setMinTimeThreshold((int) gd.getNextNumber());
    settings.setMaxTimeThreshold((int) gd.getNextNumber());
    settings.setOptimiserSteps((int) gd.getNextNumber());
    settings.setBlinkingRate(gd.getNextNumber());
    settings.setOptimiserPlot(gd.getNextChoiceIndex());
    if (altKeyDown) {
        optimiseBlinkingRate = pluginSettings.inputOptimiseBlinkingRate = gd.getNextBoolean();
    }
    writeSettings();
    if (gd.invalidNumber()) {
        return false;
    }
    if (settings.getMinDistanceThreshold() < 0) {
        settings.setMinDistanceThreshold(0);
    }
    if (settings.getMaxDistanceThreshold() < settings.getMinDistanceThreshold()) {
        settings.setMaxDistanceThreshold(settings.getMinDistanceThreshold());
    }
    if (settings.getMinTimeThreshold() < 0) {
        settings.setMinTimeThreshold(0);
    }
    if (settings.getMaxTimeThreshold() < settings.getMinTimeThreshold()) {
        settings.setMaxTimeThreshold(settings.getMinTimeThreshold());
    }
    if (settings.getOptimiserSteps() < 0) {
        settings.setOptimiserSteps(1);
    }
    if (settings.getBlinkingRate() < MIN_BLINKING_RATE) {
        IJ.error(gd.getTitle(), "Blinking rate must be above " + MIN_BLINKING_RATE);
        return false;
    }
    if (settings.getMinDistanceThreshold() == settings.getMaxDistanceThreshold() && settings.getMinTimeThreshold() == settings.getMaxTimeThreshold()) {
        IJ.error(gd.getTitle(), "Nothing to optimise");
        return false;
    }
    writeSettings();
    return true;
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 93 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class TraceDiffusion method showTraceDialog.

private boolean showTraceDialog(ArrayList<MemoryPeakResults> allResults) {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("trace-diffusion"));
    if (!multiMode) {
        ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
    }
    clusteringSettings = SettingsManager.readClusteringSettings(0).toBuilder();
    gd.addChoice("Mode", TRACE_MODE, clusteringSettings.getTraceDiffusionMode(), new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            clusteringSettings.setTraceDiffusionMode(value);
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            final ExtendedGenericDialog egd = new ExtendedGenericDialog("Trace diffusion options", null);
            // Only 2 modes
            if (clusteringSettings.getTraceDiffusionMode() == 1) {
                // Dynamic Multiple Target Tracing
                final TextField tfD = egd.addAndGetNumericField("Diffusion_coefficient", clusteringSettings.getDiffusionCoefficentMaximum(), 3, 6, "um^2/s");
                final TextField tfW = egd.addAndGetNumericField("Temporal_window", clusteringSettings.getTemporalWindow(), 0, 6, "frames");
                final TextField tfLdw = egd.addAndGetNumericField("Local_diffusion_weight", clusteringSettings.getLocalDiffusionWeight(), 2);
                final TextField tfOiw = egd.addAndGetNumericField("On_intensity_weight", clusteringSettings.getOnIntensityWeight(), 2);
                final TextField tfDdf = egd.addAndGetNumericField("Disappearance_decay_factor", clusteringSettings.getDisappearanceDecayFactor(), 0, 6, "frames");
                final TextField tfDt = egd.addAndGetNumericField("Disappearance_threshold", clusteringSettings.getDisappearanceThreshold(), 0, 6, "frames");
                final Checkbox cbDld = egd.addAndGetCheckbox("Disable_local_diffusion_model", clusteringSettings.getDisableLocalDiffusionModel());
                final Checkbox cbDim = egd.addAndGetCheckbox("Disable_intensity_model", clusteringSettings.getDisableIntensityModel());
                // Allow reset to defaults
                egd.addAndGetButton("Defaults", e -> {
                    final DmttConfiguration config = DmttConfiguration.newBuilder(1).build();
                    tfD.setText(String.valueOf(clusteringSettings.getDiffusionCoefficentMaximum()));
                    tfW.setText(String.valueOf(config.getTemporalWindow()));
                    tfLdw.setText(String.valueOf(config.getLocalDiffusionWeight()));
                    tfOiw.setText(String.valueOf(config.getOnIntensityWeight()));
                    tfDdf.setText(String.valueOf(config.getDisappearanceDecayFactor()));
                    tfDt.setText(String.valueOf(config.getDisappearanceThreshold()));
                    cbDld.setState(config.isDisableLocalDiffusionModel());
                    cbDim.setState(config.isDisableIntensityModel());
                });
            } else {
                // Nearest Neighbour
                egd.addNumericField("Distance_Threshold (nm)", clusteringSettings.getDistanceThreshold(), 0);
                egd.addNumericField("Distance_Exclusion (nm)", clusteringSettings.getDistanceExclusion(), 0);
            }
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            if (clusteringSettings.getTraceDiffusionMode() == 1) {
                // Dynamic Multiple Target Tracing
                clusteringSettings.setDiffusionCoefficentMaximum(egd.getNextNumber());
                clusteringSettings.setTemporalWindow((int) egd.getNextNumber());
                clusteringSettings.setLocalDiffusionWeight(egd.getNextNumber());
                clusteringSettings.setOnIntensityWeight(egd.getNextNumber());
                clusteringSettings.setDisappearanceDecayFactor(egd.getNextNumber());
                clusteringSettings.setDisappearanceThreshold((int) egd.getNextNumber());
                clusteringSettings.setDisableLocalDiffusionModel(egd.getNextBoolean());
                clusteringSettings.setDisableIntensityModel(egd.getNextBoolean());
            } else {
                // Nearest Neighbour
                clusteringSettings.setDistanceThreshold(egd.getNextNumber());
                clusteringSettings.setDistanceExclusion(Math.abs(egd.getNextNumber()));
            }
            return true;
        }
    });
    gd.addSlider("Min_trace_length", 2, 20, clusteringSettings.getMinimumTraceLength());
    gd.addCheckbox("Ignore_ends", clusteringSettings.getIgnoreEnds());
    gd.addCheckbox("Save_traces", clusteringSettings.getSaveTraces());
    gd.showDialog();
    if (gd.wasCanceled() || !readTraceDialog(gd)) {
        return false;
    }
    // Update the settings
    SettingsManager.writeSettings(clusteringSettings.build());
    // Load the results
    if (!multiMode) {
        final MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, true, null, null);
        if (MemoryPeakResults.isEmpty(results)) {
            IJ.error(TITLE, "No results could be loaded");
            IJ.showStatus("");
            return false;
        }
        if (!checkCalibration(results)) {
            return false;
        }
        allResults.add(results);
    }
    return true;
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) ConfigurationException(uk.ac.sussex.gdsc.smlm.data.config.ConfigurationException) TextWindow(ij.text.TextWindow) RealVector(org.apache.commons.math3.linear.RealVector) ImageJPluginLoggerHelper(uk.ac.sussex.gdsc.core.ij.ImageJPluginLoggerHelper) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) Path(java.nio.file.Path) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) ArrayPeakResultStore(uk.ac.sussex.gdsc.smlm.results.ArrayPeakResultStore) ClusteringSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.ClusteringSettings) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) ConvergenceException(org.apache.commons.math3.exception.ConvergenceException) MultivariateVectorFunction(org.apache.commons.math3.analysis.MultivariateVectorFunction) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Gaussian2DPeakResultHelper(uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultHelper) Logger(java.util.logging.Logger) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) List(java.util.List) LeastSquaresBuilder(org.apache.commons.math3.fitting.leastsquares.LeastSquaresBuilder) Converter(uk.ac.sussex.gdsc.core.data.utils.Converter) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) FileUtils(uk.ac.sussex.gdsc.core.utils.FileUtils) PlugIn(ij.plugin.PlugIn) JumpDistanceAnalysis(uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) LevenbergMarquardtOptimizer(org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TextField(java.awt.TextField) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog) CurveLogger(uk.ac.sussex.gdsc.smlm.fitting.JumpDistanceAnalysis.CurveLogger) Statistics(uk.ac.sussex.gdsc.core.utils.Statistics) SimpleImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.SimpleImageJTrackProgress) Files(java.nio.file.Files) Checkbox(java.awt.Checkbox) BufferedWriter(java.io.BufferedWriter) StdMath(uk.ac.sussex.gdsc.smlm.utils.StdMath) IOException(java.io.IOException) LeastSquaresProblem(org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem) DynamicMultipleTargetTracing(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing) TooManyIterationsException(org.apache.commons.math3.exception.TooManyIterationsException) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) Consumer(java.util.function.Consumer) Gaussian2DPeakResultCalculator(uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultCalculator) Paths(java.nio.file.Paths) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) DiagonalMatrix(org.apache.commons.math3.linear.DiagonalMatrix) PeakResultStoreList(uk.ac.sussex.gdsc.smlm.results.PeakResultStoreList) Optimum(org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) DmttConfiguration(uk.ac.sussex.gdsc.smlm.results.DynamicMultipleTargetTracing.DmttConfiguration) Checkbox(java.awt.Checkbox) TextField(java.awt.TextField) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 94 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class TiffSeriesViewer method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    settings = Settings.load();
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addChoice("Mode", Settings.MODE, settings.inputMode, new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            settings.inputMode = value;
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            // This has limited silent support to fake running in a macro
            if (settings.inputMode == 0) {
                String dir = null;
                final String title = "Select image series ...";
                if (silent) {
                    final String macroOptions = Macro.getOptions();
                    if (macroOptions != null) {
                        dir = Macro.getValue(macroOptions, title, null);
                    }
                } else {
                    dir = ImageJUtils.getDirectory(title, settings.inputDirectory);
                }
                if (TextUtils.isNullOrEmpty(dir)) {
                    return false;
                }
                settings.inputDirectory = dir;
            } else {
                String file = null;
                final String title = "Select image ...";
                if (silent) {
                    final String macroOptions = Macro.getOptions();
                    if (macroOptions != null) {
                        file = Macro.getValue(macroOptions, title, null);
                    }
                } else {
                    file = ImageJUtils.getFilename(title, settings.inputFile);
                }
                if (TextUtils.isNullOrEmpty(file)) {
                    return false;
                }
                settings.inputFile = file;
            }
            updateLabel();
            return true;
        }
    });
    gd.addMessage("");
    label = gd.getLastLabel();
    if (ImageJUtils.isShowGenericDialog()) {
        final Choice choice = gd.getLastChoice();
        choice.addItemListener(event -> {
            settings.inputMode = choice.getSelectedIndex();
            updateLabel();
        });
        updateLabel();
    }
    gd.addCheckbox("Log_progress", settings.logProgress);
    gd.addChoice("Output_mode", Settings.OUTPUT_MODE, settings.outputMode, new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            settings.outputMode = value;
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            if (settings.outputMode == 0) {
                // Nothing to do
                return false;
            }
            final ExtendedGenericDialog egd = new ExtendedGenericDialog("Output Options");
            egd.addNumericField("Slices_per_image", settings.imageCount, 0);
            egd.addDirectoryField("Output_directory", settings.outputDirectory);
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            settings.imageCount = (int) egd.getNextNumber();
            settings.outputDirectory = egd.getNextString();
            updateLabel2();
            return true;
        }
    });
    gd.addMessage("");
    label2 = gd.getLastLabel();
    if (ImageJUtils.isShowGenericDialog()) {
        final Choice choice = gd.getLastChoice();
        choice.addItemListener(event -> {
            settings.outputMode = choice.getSelectedIndex();
            updateLabel2();
        });
        updateLabel2();
    }
    gd.addHelp(HelpUrls.getUrl("tiff-series-viewer"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    settings.inputMode = gd.getNextChoiceIndex();
    settings.logProgress = gd.getNextBoolean();
    settings.outputMode = gd.getNextChoiceIndex();
    settings.save();
    SeriesImageSource source;
    if (settings.inputMode == 0) {
        final SeriesOpener series = new SeriesOpener(settings.inputDirectory);
        if (series.getNumberOfImages() == 0) {
            IJ.error(TITLE, "No images in the selected directory:\n" + settings.inputDirectory);
            return;
        }
        source = new SeriesImageSource(PeakFit.getName(series.getImageList()), series);
    } else {
        source = new SeriesImageSource(FileUtils.getName(settings.inputFile), new String[] { settings.inputFile });
    }
    // No memory buffer
    source.setBufferLimit(0);
    source.setReadHint(ReadHint.NONSEQUENTIAL);
    if (!source.isTiffSeries) {
        IJ.error(TITLE, "Not a TIFF image");
        return;
    }
    ImageJUtils.showStatus("Opening TIFF ...");
    final TrackProgressAdaptor progress = new TrackProgressAdaptor() {

        @Override
        public void progress(double fraction) {
            IJ.showProgress(fraction);
        }

        @Override
        public void progress(long position, long total) {
            IJ.showProgress((double) position / total);
        }

        @Override
        public void log(String format, Object... args) {
            if (settings.logProgress) {
                ImageJUtils.log(format, args);
            }
        }

        @Override
        public void status(String format, Object... args) {
            ImageJUtils.showStatus(() -> String.format(format, args));
        }

        @Override
        public boolean isLog() {
            return settings.logProgress;
        }
    };
    source.setTrackProgress(progress);
    if (!source.open()) {
        IJ.error(TITLE, "Cannot open the image");
        return;
    }
    ImageJUtils.showStatus("");
    // Create a virtual stack
    final TiffSeriesVirtualStack stack = new TiffSeriesVirtualStack(source);
    if (settings.outputMode == 0) {
        stack.show();
    } else {
        final int nImages = Math.max(1, settings.imageCount);
        final ImagePlus imp = stack.createImp();
        // The calibration only has the offset so ignore for speed.
        // Calibration cal = imp.getCalibration();
        final int size = stack.getSize();
        // Create the format string
        final int digits = String.format("%d", size).length();
        final String format = new File(settings.outputDirectory, imp.getShortTitle() + "%0" + digits + "d.tif").getPath();
        IJ.showStatus("Saving image ...");
        try {
            for (int i = 1; i <= size; i += nImages) {
                if (ImageJUtils.isInterrupted()) {
                    break;
                }
                ImageJUtils.showSlowProgress(i, size);
                final String path = String.format(format, i);
                final ImageStack out = new ImageStack(source.getWidth(), source.getHeight());
                for (int j = 0, k = i; j < nImages && k <= size; j++, k++) {
                    out.addSlice(null, stack.getPixels(k));
                }
                final ImagePlus outImp = new ImagePlus(path, out);
                // outImp.setCalibration(cal);
                saveAsTiff(outImp, path);
            }
            IJ.showStatus("Saved image");
        } catch (final IOException ex) {
            IJ.log(ExceptionUtils.getStackTrace(ex));
            IJ.error(TITLE, "Failed to save image: " + ex.getMessage());
            IJ.showStatus("Failed to save image");
        } finally {
            ImageJUtils.clearSlowProgress();
        }
    }
}
Also used : Choice(java.awt.Choice) ImageStack(ij.ImageStack) SeriesImageSource(uk.ac.sussex.gdsc.smlm.ij.SeriesImageSource) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) SeriesOpener(uk.ac.sussex.gdsc.core.ij.SeriesOpener) IOException(java.io.IOException) ImagePlus(ij.ImagePlus) ReadHint(uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint) TrackProgressAdaptor(uk.ac.sussex.gdsc.core.logging.TrackProgressAdaptor) File(java.io.File)

Example 95 with ExtendedGenericDialog

use of uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog in project GDSC-SMLM by aherbert.

the class TraceMatchCalculator method showDialog.

private boolean showDialog() {
    settings = Settings.load();
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Compare the traced points in results sets\nand computes the match statistics");
    ResultsManager.addInput(gd, "Results1", settings.inputOption1, InputSource.MEMORY_MULTI_FRAME);
    ResultsManager.addInput(gd, "Results2", settings.inputOption2, InputSource.MEMORY_MULTI_FRAME);
    ResultsManager.addInput(gd, "Results3", settings.inputOption3, InputSource.NONE, InputSource.MEMORY_MULTI_FRAME);
    gd.addNumericField("Distance", settings.distanceThreshold, 2, 6, "px");
    gd.addNumericField("Beta", settings.beta, 2);
    gd.addCheckbox("Show_pairs", settings.showPairs);
    gd.addChoice("Sort_pairs", Settings.SORT_OPTIONS, settings.sortIndex);
    gd.addHelp(HelpUrls.getUrl("trace-match-calculator"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.inputOption1 = gd.getNextChoice();
    settings.inputOption2 = gd.getNextChoice();
    settings.inputOption3 = gd.getNextChoice();
    settings.distanceThreshold = gd.getNextNumber();
    settings.beta = gd.getNextNumber();
    settings.showPairs = gd.getNextBoolean();
    settings.sortIndex = gd.getNextChoiceIndex();
    settings.save();
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Distance threshold", settings.distanceThreshold);
        ParameterUtils.isPositive("Beta", settings.beta);
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    return true;
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Aggregations

ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)151 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)38 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)21 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)14 Checkbox (java.awt.Checkbox)13 ImagePlus (ij.ImagePlus)12 File (java.io.File)11 Rectangle (java.awt.Rectangle)10 TextField (java.awt.TextField)10 ResultsImageSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings)10 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)10 Choice (java.awt.Choice)9 ArrayList (java.util.ArrayList)9 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)9 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)8 CalibrationReader (uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader)7 ResultsSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings)7 ResultsTableSettings (uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings)7 IJ (ij.IJ)6 GenericDialog (ij.gui.GenericDialog)5