Search in sources :

Example 96 with GenericDialog

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

the class PsfCreator method createInteractivePlots.

private void createInteractivePlots(ImageStack psf, int zCentre, double nmPerPixel, double psfWidth) {
    this.psf = psf;
    this.zCentre = zCentre;
    this.psfNmPerPixel = nmPerPixel;
    this.psfWidth = psfWidth;
    this.slice = zCentre;
    this.distanceThreshold = psfWidth * 3;
    final GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage("Plot the cumulative signal verses distance from the PSF centre.\n \nZ-centre = " + zCentre + "\nPSF width = " + MathUtils.rounded(psfWidth) + " nm");
    gd.addSlider("Slice", 1, psf.getSize(), slice);
    final double maxDistance = (psf.getWidth() / 1.414213562) * nmPerPixel;
    gd.addSlider("Distance", 0, maxDistance, distanceThreshold);
    gd.addCheckbox("Normalise", normalise);
    gd.addDialogListener(new InteractivePlotListener());
    if (!IJ.isMacro()) {
        drawPlots(true);
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    drawPlots(true);
}
Also used : GenericDialog(ij.gui.GenericDialog) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 97 with GenericDialog

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

the class RenameResults method showDialog.

private boolean showDialog() {
    final GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("rename-results"));
    gd.addMessage("To rename the results in memory update the second name field as desired.\n" + "(Note the semi-colon at the end of the line is needed for macro recording.)");
    final StringBuilder sb = new StringBuilder();
    for (final String name : MemoryPeakResults.getResultNames()) {
        sb.append(name).append(" = ").append(name).append(";\n");
    }
    gd.addTextAreas(sb.toString(), null, 20, 80);
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    renameText = gd.getNextText();
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog)

Example 98 with GenericDialog

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

the class ResultsManager method collectOptions.

private static void collectOptions(PeakResultsReader reader, ResultOption[] options) {
    final GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage("Options required for file format: " + reader.getFormat().getName());
    for (final ResultOption option : options) {
        if (option.hasValues()) {
            final String[] items = new String[option.values.length];
            for (int i = 0; i < items.length; i++) {
                items[i] = option.values[i].toString();
            }
            gd.addChoice(getOptionName(option), items, option.getValue().toString());
        } else if (option.getValue() instanceof Number) {
            final Number n = (Number) option.getValue();
            if (n.doubleValue() == n.intValue()) {
                gd.addNumericField(getOptionName(option), n.intValue(), 0);
            } else {
                final String value = n.toString();
                int sig = 0;
                int index = value.indexOf('.');
                if (index != -1) {
                    // There is a decimal point. Count the digits after it
                    while (++index < value.length()) {
                        if (!Character.isDigit(value.charAt(index))) {
                            // A non-digit character after the decimal point is for scientific notation
                            sig = -sig;
                            break;
                        }
                        sig++;
                    }
                }
                gd.addNumericField(getOptionName(option), n.doubleValue(), sig);
            }
        } else if (option.getValue() instanceof String) {
            gd.addStringField(getOptionName(option), (String) option.getValue());
        } else if (option.getValue() instanceof Boolean) {
            gd.addCheckbox(getOptionName(option), (Boolean) option.getValue());
        } else {
            IJ.log(TITLE + ": Unsupported reader option: " + option.name + "=" + option.getValue().toString());
        }
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    try {
        for (final ResultOption option : options) {
            if (option.hasValues()) {
                option.setValue(option.values[gd.getNextChoiceIndex()]);
            } else if (option.getValue() instanceof Number) {
                final double d = gd.getNextNumber();
                // Convert to the correct type using the String value constructor for the number
                option.setValue(option.getValue().getClass().getConstructor(String.class).newInstance(Double.toString(d)));
            } else if (option.getValue() instanceof String) {
                option.setValue(gd.getNextString());
            } else if (option.getValue() instanceof Boolean) {
                option.setValue(gd.getNextBoolean());
            }
        }
        reader.setOptions(options);
    } catch (final Exception ex) {
        // This can occur if the options are not valid
        IJ.log(TITLE + ": Failed to configure reader options: " + ex.getMessage());
    }
}
Also used : ResultOption(uk.ac.sussex.gdsc.smlm.results.ResultOption) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) GenericDialog(ij.gui.GenericDialog) IOException(java.io.IOException)

Example 99 with GenericDialog

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

the class ResultsManager method runClearMemory.

private static void runClearMemory(String arg) {
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        IJ.showStatus("");
        return;
    }
    Collection<MemoryPeakResults> allResults;
    boolean removeAll = false;
    String helpKey = "clear-memory-results";
    if (arg.contains("multi")) {
        helpKey += "-multi";
        final MultiDialog md = createMultiDialog(TITLE);
        md.setSelected(lastSelected.get());
        md.setHelpUrl(HelpUrls.getUrl(helpKey));
        md.showDialog();
        if (md.wasCancelled()) {
            return;
        }
        final List<String> selected = md.getSelectedResults();
        if (selected.isEmpty()) {
            return;
        }
        lastSelected.set(selected);
        allResults = new ArrayList<>(selected.size());
        for (final String name : selected) {
            final MemoryPeakResults r = MemoryPeakResults.getResults(name);
            if (r != null) {
                allResults.add(r);
            }
        }
    } else {
        removeAll = true;
        allResults = MemoryPeakResults.getAllResults();
    }
    if (allResults.isEmpty()) {
        return;
    }
    long memorySize = 0;
    int size = 0;
    for (final MemoryPeakResults results : allResults) {
        memorySize += MemoryPeakResults.estimateMemorySize(results);
        size += results.size();
    }
    final String memory = TextUtils.bytesToString(memorySize);
    final String count = TextUtils.pleural(size, "result");
    final String sets = TextUtils.pleural(allResults.size(), "set");
    final GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage(String.format("Do you want to remove %s from memory (%s, %s)?", count, sets, memory));
    gd.addHelp(HelpUrls.getUrl(helpKey));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    if (removeAll) {
        MemoryPeakResults.clearMemory();
    } else {
        for (final MemoryPeakResults results : allResults) {
            MemoryPeakResults.removeResults(results.getName());
        }
    }
    SummariseResults.clearSummaryTable();
    ImageJUtils.log("Cleared %s (%s, %s)", count, sets, memory);
}
Also used : ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) GenericDialog(ij.gui.GenericDialog) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Example 100 with GenericDialog

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

the class PeakFit method runMaximaFitting.

/**
 * Load the selected results from memory. All multiple frame results are added directly to the
 * results. All single frame results are added to a list of candidate maxima per frame and fitted
 * using the configured parameters.
 */
private void runMaximaFitting() {
    final MemoryPeakResults memoryResults = ResultsManager.loadInputResults(settings.inputOption, false, DistanceUnit.PIXEL);
    if (memoryResults == null || memoryResults.size() == 0) {
        log("No results for maxima fitting");
        return;
    }
    // The total frames (for progress reporting)
    int totalFrames;
    // A function that can convert a frame into a set of candidate indices
    final IntFunction<int[]> frameToMaxIndices;
    // The frames to process (should be sorted ascending)
    Supplier<IntStream> frames;
    // Support fitting all time frames with the same results.
    if (settings.fitAcrossAllFrames) {
        // Check if the input spans multiple frames
        if (getSingleFrame(memoryResults) == 0) {
            final int min = memoryResults.getMinFrame();
            final int max = memoryResults.getMaxFrame();
            final GenericDialog gd = new GenericDialog(TITLE);
            gd.enableYesNoCancel();
            gd.hideCancelButton();
            ImageJUtils.addMessage(gd, "Candidate maxima for fitting span multiple frames (%d-%d).\n \n" + "Please confirm the %s are correct.", min, max, TextUtils.pleural(memoryResults.size(), "candidate"));
            gd.showDialog();
            if (!gd.wasOKed()) {
                return;
            }
        }
        final int[] maxIndices = getMaxIndices(Arrays.asList(memoryResults.toArray()));
        // This may not work correctly if using for example a series image source that
        // incorrectly estimates the number of frames
        totalFrames = source.getFrames();
        frameToMaxIndices = frame -> maxIndices;
        frames = () -> IntStream.rangeClosed(1, totalFrames);
    } else {
        // Build a map between the time-frame and the results in that frame.
        final Map<Integer, List<PeakResult>> map = Arrays.stream(memoryResults.toArray()).parallel().filter(peakResult -> peakResult.getFrame() == peakResult.getEndFrame()).collect(Collectors.groupingBy(PeakResult::getFrame));
        totalFrames = map.size();
        // Build a function that can convert a frame into a set of candidate indices
        frameToMaxIndices = frame -> getMaxIndices(map.get(frame));
        frames = () -> map.keySet().stream().mapToInt(Integer::intValue).sorted();
    }
    final ImageStack stack = (extraSettings.showProcessedFrames) ? new ImageStack(bounds.width, bounds.height) : null;
    // Use the FitEngine to allow multi-threading.
    final FitEngine engine = createFitEngine(getNumberOfThreads(totalFrames));
    if (engine == null) {
        return;
    }
    final int step = ImageJUtils.getProgressInterval(totalFrames);
    // No crop bounds are supported.
    // To pre-process data for noise estimation
    final boolean isFitCameraCounts = fitConfig.isFitCameraCounts();
    final CameraModel cameraModel = fitConfig.getCameraModel();
    runTime = System.nanoTime();
    final AtomicBoolean shutdown = new AtomicBoolean();
    final String format = String.format("Slice: %%d / %d (Results=%%d)", totalFrames);
    frames.get().forEachOrdered(slice -> {
        if (shutdown.get() || escapePressed()) {
            shutdown.set(true);
            return;
        }
        final float[] data = source.get(slice);
        if (data == null) {
            shutdown.set(true);
            return;
        }
        if (slice % step == 0) {
            if (ImageJUtils.showStatus(() -> String.format(format, slice, results.size()))) {
                IJ.showProgress(slice, totalFrames);
            }
        }
        // We must pre-process the data before noise estimation
        final float[] data2 = data.clone();
        if (isFitCameraCounts) {
            cameraModel.removeBias(data2);
        } else {
            cameraModel.removeBiasAndGain(data2);
        }
        final float noise = FitWorker.estimateNoise(data2, source.getWidth(), source.getHeight(), config.getNoiseMethod());
        if (stack != null) {
            stack.addSlice(String.format("Frame %d - %d", source.getStartFrameNumber(), source.getEndFrameNumber()), data);
        }
        // Get the frame number from the source to allow for interlaced and aggregated data
        engine.run(createMaximaFitJob(frameToMaxIndices.apply(slice), source.getStartFrameNumber(), source.getEndFrameNumber(), data, bounds, noise));
    });
    engine.end(shutdown.get());
    time = engine.getTime();
    runTime = System.nanoTime() - runTime;
    if (stack != null) {
        ImageJUtils.display("Processed frames", stack);
    }
    showResults();
    source.close();
}
Also used : Color(java.awt.Color) Choice(java.awt.Choice) Arrays(java.util.Arrays) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) UnitConverterUtils(uk.ac.sussex.gdsc.smlm.data.config.UnitConverterUtils) ImageProcessor(ij.process.ImageProcessor) ImageSource(uk.ac.sussex.gdsc.smlm.results.ImageSource) Filter(uk.ac.sussex.gdsc.smlm.results.filter.Filter) PSFType(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFType) StringUtils(org.apache.commons.lang3.StringUtils) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) Panel(java.awt.Panel) Vector(java.util.Vector) Matcher(java.util.regex.Matcher) YesNoCancelDialog(ij.gui.YesNoCancelDialog) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Map(java.util.Map) FitProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.FitProtosHelper) ImageJImageConverter(uk.ac.sussex.gdsc.smlm.ij.utils.ImageJImageConverter) FilePeakResults(uk.ac.sussex.gdsc.smlm.results.FilePeakResults) EnumSet(java.util.EnumSet) LutHelper(uk.ac.sussex.gdsc.core.ij.process.LutHelper) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) GuiProtosHelper(uk.ac.sussex.gdsc.smlm.ij.settings.GuiProtosHelper) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Scrollbar(java.awt.Scrollbar) ImagePlus(ij.ImagePlus) CalibrationProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtosHelper) FitEngineSettings(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.FitEngineSettings) PeakResultProcedureX(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedureX) Prefs(ij.Prefs) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) PointRoi(ij.gui.PointRoi) DataFilterMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.DataFilterMethod) GenericDialog(ij.gui.GenericDialog) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) Overlay(ij.gui.Overlay) IntFunction(java.util.function.IntFunction) SeriesOpener(uk.ac.sussex.gdsc.core.ij.SeriesOpener) FitWorker(uk.ac.sussex.gdsc.smlm.engine.FitWorker) FitEngine(uk.ac.sussex.gdsc.smlm.engine.FitEngine) File(java.io.File) AggregatedImageSource(uk.ac.sussex.gdsc.smlm.results.AggregatedImageSource) DirectFilter(uk.ac.sussex.gdsc.smlm.results.filter.DirectFilter) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) ImageStack(ij.ImageStack) CameraModel(uk.ac.sussex.gdsc.smlm.model.camera.CameraModel) PsfHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfHelper) FitJob(uk.ac.sussex.gdsc.smlm.engine.FitJob) ResultsTableSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsTableSettings) FitTask(uk.ac.sussex.gdsc.smlm.engine.FitParameters.FitTask) ItemListener(java.awt.event.ItemListener) PSFParameter(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSFParameter) FitSolver(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.FitSolver) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) ImageJPluginLoggerHelper(uk.ac.sussex.gdsc.core.ij.ImageJPluginLoggerHelper) XyResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyResultProcedure) InterlacedImageSource(uk.ac.sussex.gdsc.smlm.results.InterlacedImageSource) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) PlugInFilter(ij.plugin.filter.PlugInFilter) PsfProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.PsfProtosHelper) FitParameters(uk.ac.sussex.gdsc.smlm.engine.FitParameters) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) ItemEvent(java.awt.event.ItemEvent) CameraType(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) TrackProgressAdaptor(uk.ac.sussex.gdsc.core.logging.TrackProgressAdaptor) ResultsImageType(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) GridBagConstraints(java.awt.GridBagConstraints) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) BitFlagUtils(uk.ac.sussex.gdsc.core.utils.BitFlagUtils) List(java.util.List) SpotFilter(uk.ac.sussex.gdsc.smlm.filters.SpotFilter) LUT(ij.process.LUT) Pattern(java.util.regex.Pattern) FitQueue(uk.ac.sussex.gdsc.smlm.engine.FitQueue) SeriesImageSource(uk.ac.sussex.gdsc.smlm.ij.SeriesImageSource) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) ParameterisedFitJob(uk.ac.sussex.gdsc.smlm.engine.ParameterisedFitJob) IntStream(java.util.stream.IntStream) Rectangle(java.awt.Rectangle) Insets(java.awt.Insets) PrecisionMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.PrecisionMethod) PSFCalculatorSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.PSFCalculatorSettings) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PSF(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.PSF) ResultsFileSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsFileSettings) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextField(java.awt.TextField) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) NoiseEstimatorMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.NoiseEstimatorMethod) ResultsProtosHelper(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtosHelper) TemplateSettings(uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings) FastMleSteppingFunctionSolver(uk.ac.sussex.gdsc.smlm.fitting.nonlinear.FastMleSteppingFunctionSolver) SystemColor(java.awt.SystemColor) AstigmatismModel(uk.ac.sussex.gdsc.smlm.data.config.PSFProtos.AstigmatismModel) Iterator(java.util.Iterator) Checkbox(java.awt.Checkbox) Label(java.awt.Label) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) TimeUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.TimeUnit) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) PerPixelCameraModel(uk.ac.sussex.gdsc.smlm.model.camera.PerPixelCameraModel) CameraModel(uk.ac.sussex.gdsc.smlm.model.camera.CameraModel) PerPixelCameraModel(uk.ac.sussex.gdsc.smlm.model.camera.PerPixelCameraModel) ImageStack(ij.ImageStack) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FitEngine(uk.ac.sussex.gdsc.smlm.engine.FitEngine) GenericDialog(ij.gui.GenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ArrayList(java.util.ArrayList) PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) List(java.util.List) IntStream(java.util.stream.IntStream)

Aggregations

GenericDialog (ij.gui.GenericDialog)236 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)45 ArrayList (java.util.ArrayList)31 ImagePlus (ij.ImagePlus)25 Rectangle (java.awt.Rectangle)21 File (java.io.File)21 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)20 Point (java.awt.Point)20 Color (java.awt.Color)17 NonBlockingExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog)15 Roi (ij.gui.Roi)14 IOException (java.io.IOException)14 Checkbox (java.awt.Checkbox)13 Component (java.awt.Component)13 TextField (java.awt.TextField)13 Vector (java.util.Vector)12 List (java.util.List)11 Worker (ini.trakem2.utils.Worker)10 GridBagConstraints (java.awt.GridBagConstraints)10 Choice (java.awt.Choice)9