Search in sources :

Example 76 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class TrackPopulationAnalysis method showHasCategoryDialog.

private static boolean showHasCategoryDialog(List<MemoryPeakResults> combinedResults) {
    // Check if all results have a category
    if (combinedResults.stream().filter(MemoryPeakResults::hasCategory).count() == combinedResults.size()) {
        final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.addHelp(HelpUrls.getUrl("track-population-analysis"));
        gd.addMessage("Input results contain categories.\n \nUse the categories as the track sub-populations?");
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.showDialog();
        return gd.wasOKed();
    }
    return false;
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 77 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class SplitResults method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    if (MemoryPeakResults.isMemoryEmpty()) {
        IJ.error(TITLE, "There are no fitting results in memory");
        return;
    }
    final String[] items = ImageJUtils.getImageList(ImageJUtils.GREY_8_16);
    if (items.length == 0) {
        IJ.error(TITLE, "There are no suitable mask images");
        return;
    }
    settings = Settings.load();
    // Show a dialog allowing the results set to be filtered
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Select a dataset to split");
    ResultsManager.addInput(gd, settings.inputOption, InputSource.MEMORY);
    gd.addChoice("Object_mask", items, settings.objectMask);
    gd.addCheckbox("Show_object_mask", settings.showObjectMask);
    gd.addCheckbox("Non_mask_dataset", settings.nonMaskDataset);
    gd.addHelp(HelpUrls.getUrl("split-results"));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return;
    }
    settings.inputOption = ResultsManager.getInputSource(gd);
    settings.objectMask = gd.getNextChoice();
    settings.showObjectMask = gd.getNextBoolean();
    settings.nonMaskDataset = gd.getNextBoolean();
    settings.save();
    final MemoryPeakResults results = ResultsManager.loadInputResults(settings.inputOption, false, null, null);
    if (MemoryPeakResults.isEmpty(results)) {
        IJ.error(TITLE, "No results could be loaded");
        return;
    }
    final ImagePlus imp = WindowManager.getImage(settings.objectMask);
    if (imp == null) {
        IJ.error(TITLE, "No object mask could be found");
        return;
    }
    splitResults(results, imp.getProcessor());
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus)

Example 78 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class SplitResults method splitResults.

private void splitResults(MemoryPeakResults results, ImageProcessor ip) {
    IJ.showStatus("Splitting " + TextUtils.pleural(results.size(), "result"));
    // Create an object mask
    final ObjectAnalyzer objectAnalyzer = new ObjectAnalyzer(ip, false);
    final int maxx = ip.getWidth();
    final int maxy = ip.getHeight();
    final Rectangle bounds = results.getBounds();
    final double ox = bounds.getX();
    final double oy = bounds.getY();
    final double scaleX = bounds.getWidth() / maxx;
    final double scaleY = bounds.getHeight() / maxy;
    // Create a results set for each object
    final int maxObject = objectAnalyzer.getMaxObject();
    final MemoryPeakResults[] resultsSet = new MemoryPeakResults[maxObject + 1];
    for (int object = 0; object <= maxObject; object++) {
        final MemoryPeakResults newResults = new MemoryPeakResults();
        newResults.copySettings(results);
        newResults.setName(results.getName() + " " + object);
        resultsSet[object] = newResults;
    }
    final int[] mask = objectAnalyzer.getObjectMask();
    if (settings.showObjectMask) {
        final ImageProcessor objectIp = (maxObject <= 255) ? new ByteProcessor(maxx, maxy) : new ShortProcessor(maxx, maxy);
        for (int i = 0; i < mask.length; i++) {
            objectIp.set(i, mask[i]);
        }
        final ImagePlus imp = ImageJUtils.display(settings.objectMask + " Objects", objectIp);
        imp.setDisplayRange(0, maxObject);
        imp.updateAndDraw();
    }
    // Process the results mapping them to their objects
    final Counter i = new Counter();
    final int size = results.size();
    final int step = ImageJUtils.getProgressInterval(size);
    results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
        if (i.incrementAndGet() % step == 0) {
            IJ.showProgress(i.getCount(), size);
        }
        // Map to the mask objects
        final int object;
        final int x = (int) ((xx - ox) / scaleX);
        final int y = (int) ((yy - oy) / scaleY);
        if (x < 0 || x >= maxx || y < 0 || y >= maxy) {
            object = 0;
        } else {
            final int index = y * maxx + x;
            // is within the bounds of the image processor?
            if (index < 0 || index >= mask.length) {
                object = 0;
            } else {
                object = mask[index];
            }
        }
        resultsSet[object].add(result);
    });
    IJ.showProgress(1);
    // Add the new results sets to memory
    i.reset();
    for (int object = (settings.nonMaskDataset) ? 0 : 1; object <= maxObject; object++) {
        if (resultsSet[object].isNotEmpty()) {
            MemoryPeakResults.addResults(resultsSet[object]);
            i.increment();
        }
    }
    IJ.showStatus("Split " + TextUtils.pleural(results.size(), "result") + " into " + TextUtils.pleural(i.getCount(), "set"));
}
Also used : ByteProcessor(ij.process.ByteProcessor) Rectangle(java.awt.Rectangle) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ByteProcessor(ij.process.ByteProcessor) ObjectAnalyzer(uk.ac.sussex.gdsc.smlm.ij.utils.ObjectAnalyzer) ImageProcessor(ij.process.ImageProcessor) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) WindowManager(ij.WindowManager) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) ImagePlus(ij.ImagePlus) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ShortProcessor(ij.process.ShortProcessor) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) IJ(ij.IJ) PlugIn(ij.plugin.PlugIn) Rectangle(java.awt.Rectangle) ImagePlus(ij.ImagePlus) ShortProcessor(ij.process.ShortProcessor) ImageProcessor(ij.process.ImageProcessor) ObjectAnalyzer(uk.ac.sussex.gdsc.smlm.ij.utils.ObjectAnalyzer) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 79 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class SpotFinderPreview method showDialog.

@Override
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
    settings = Settings.load();
    this.overlay = imp.getOverlay();
    this.imp = imp;
    // Saved by reference so do it once now
    settings.save();
    // The image is locked by the PlugInFilterRunner so unlock it to allow scroll.
    // This should be OK as the image data is not modified and only the overlay is
    // adjusted. If another plugin changes the image then the preview should update
    // the overlay and it will be obvious to the user to turn this plugin off.
    imp.unlock();
    config = SettingsManager.readFitEngineConfiguration(0);
    fitConfig = config.getFitConfiguration();
    gd = new NonBlockingExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("spot-finder-preview"));
    gd.addMessage("Preview candidate maxima");
    final String[] templates = ConfigurationTemplate.getTemplateNames(true);
    gd.addChoice("Template", templates, templates[0]);
    final String[] models = CameraModelManager.listCameraModels(true);
    gd.addChoice("Camera_model_name", models, fitConfig.getCameraModelName());
    PeakFit.addPsfOptions(gd, (FitConfigurationProvider) () -> fitConfig);
    final PeakFit.SimpleFitEngineConfigurationProvider provider = new PeakFit.SimpleFitEngineConfigurationProvider(config);
    PeakFit.addDataFilterOptions(gd, provider);
    gd.addChoice("Spot_filter_2", SettingsManager.getDataFilterMethodNames(), config.getDataFilterMethod(1, settings.defaultDataFilterMethod).ordinal());
    PeakFit.addRelativeParameterOptions(gd, new RelativeParameterProvider(2.5, 4.5, "Smoothing_2", provider) {

        @Override
        void setAbsolute(boolean absolute) {
            final FitEngineConfiguration c = fitEngineConfigurationProvider.getFitEngineConfiguration();
            final DataFilterMethod m = c.getDataFilterMethod(1, settings.defaultDataFilterMethod);
            final double smooth = c.getDataFilterParameterValue(1, settings.defaultSmooth);
            c.setDataFilter(m, smooth, absolute, 1);
        }

        @Override
        boolean isAbsolute() {
            return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterAbsolute(1, false);
        }

        @Override
        double getValue() {
            return fitEngineConfigurationProvider.getFitEngineConfiguration().getDataFilterParameterValue(1, settings.defaultSmooth);
        }
    });
    PeakFit.addSearchOptions(gd, provider);
    PeakFit.addBorderOptions(gd, provider);
    // Find if this image was created with ground truth data
    if (imp.getID() == CreateData.getImageId()) {
        final MemoryPeakResults results = CreateData.getResults();
        if (results != null) {
            gd.addSlider("Match_distance", 0, 2.5, settings.distance);
            gd.addSlider("Lower_match_distance (%)", 0, 100, settings.lowerDistance);
            gd.addCheckbox("Multiple_matches", settings.multipleMatches);
            gd.addCheckbox("Show_TP", settings.showTP);
            gd.addCheckbox("Show_FP", settings.showFP);
            gd.addMessage("");
            label = (Label) gd.getMessage();
            final boolean integerCoords = false;
            actualCoordinates = ResultsMatchCalculator.getCoordinates(results, integerCoords);
        }
    }
    if (label == null) {
        // If no ground truth data add options to show the spots by their rank
        // and number of neighbours
        gd.addSlider("Top_N", 0, 100, settings.topN);
        topNScrollBar = gd.getLastScrollbar();
        gd.addSlider("Select", 0, 100, settings.select);
        selectScrollBar = gd.getLastScrollbar();
        gd.addSlider("Neigbour_radius", 0, 10, settings.neighbourRadius);
    }
    ImageListener imageListener = null;
    if (ImageJUtils.isShowGenericDialog()) {
        // Listen for changes in the dialog options
        gd.addOptionCollectedListener(event -> {
            // Just run on the current processor
            if (preview) {
                run(imp.getProcessor());
            }
        });
        // Listen for changes to an image
        imageListener = new ImageAdapter() {

            @Override
            public void imageUpdated(ImagePlus imp) {
                if (SpotFinderPreview.this.imp.getID() == imp.getID() && preview && imp.getCurrentSlice() != currentSlice && filter != null) {
                    run(imp.getProcessor(), filter);
                }
            }
        };
        ImagePlus.addImageListener(imageListener);
        // Support template settings
        final Vector<TextField> numerics = gd.getNumericFields();
        final Vector<Choice> choices = gd.getChoices();
        final Iterator<TextField> nu = numerics.iterator();
        final Iterator<Choice> ch = choices.iterator();
        final Choice textTemplate = ch.next();
        textTemplate.removeItemListener(gd);
        textTemplate.removeKeyListener(gd);
        textTemplate.addItemListener(this::itemStateChanged);
        textCameraModelName = ch.next();
        textPsf = ch.next();
        textDataFilterType = ch.next();
        textDataFilterMethod = ch.next();
        textSmooth = nu.next();
        textDataFilterMethod2 = ch.next();
        textSmooth2 = nu.next();
        textSearch = nu.next();
        textBorder = nu.next();
    }
    gd.addPreviewCheckbox(pfr);
    gd.addDialogListener(this::dialogItemChanged);
    gd.setOKLabel("Save");
    gd.setCancelLabel("Close");
    gd.showDialog();
    if (imageListener != null) {
        ImagePlus.removeImageListener(imageListener);
    }
    if (!gd.wasCanceled() && !SettingsManager.writeSettings(config, SettingsManager.FLAG_SILENT)) {
        IJ.error(TITLE, "Failed to save settings");
    }
    // Reset
    imp.setOverlay(overlay);
    return DONE;
}
Also used : Choice(java.awt.Choice) ImageListener(ij.ImageListener) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ImagePlus(ij.ImagePlus) DataFilterMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.DataFilterMethod) RelativeParameterProvider(uk.ac.sussex.gdsc.smlm.ij.plugins.PeakFit.RelativeParameterProvider) ImageAdapter(uk.ac.sussex.gdsc.core.ij.ImageAdapter) TextField(java.awt.TextField) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 80 with MemoryPeakResults

use of uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.

the class TraceDiffusion method showMultiDialog.

private boolean showMultiDialog(ArrayList<MemoryPeakResults> allResults) {
    multiMode = true;
    // Show a list box containing all the results. This should remember the last set of chosen
    // items.
    final MultiDialog md = ResultsManager.createMultiDialog(TITLE);
    md.setSelected(selectedRef.get());
    md.setHelpUrl(HelpUrls.getUrl("trace-diffusion-multi"));
    md.showDialog();
    if (md.wasCancelled()) {
        return false;
    }
    final List<String> selected = md.getSelectedResults();
    if (selected.isEmpty()) {
        IJ.error(TITLE, "No results were selected");
        return false;
    }
    selectedRef.set(selected);
    for (final String name : selected) {
        final MemoryPeakResults r = MemoryPeakResults.getResults(name);
        if (r != null) {
            allResults.add(r);
        }
    }
    if (allResults.isEmpty()) {
        return false;
    }
    // Check calibration exists for the first set of results
    if (!checkCalibration(allResults.get(0))) {
        return false;
    }
    // Check the calibration is the same for the rest
    final CalibrationReader cal = allResults.get(0).getCalibrationReader();
    final double nmPerPixel = cal.getNmPerPixel();
    final double exposureTime = cal.getExposureTime();
    final DistanceUnit distanceUnit = cal.getDistanceUnit();
    for (int i = 1; i < allResults.size(); i++) {
        final MemoryPeakResults results = allResults.get(i);
        if (!results.hasCalibration() || results.getCalibrationReader().getExposureTime() != exposureTime || results.getNmPerPixel() != nmPerPixel || results.getDistanceUnit() != distanceUnit) {
            IJ.error(TITLE, "The exposure time, pixel pitch and distance unit must match across all the results");
            return false;
        }
    }
    return true;
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) MultiDialog(uk.ac.sussex.gdsc.core.ij.gui.MultiDialog)

Aggregations

MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)138 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)61 List (java.util.List)47 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)46 IJ (ij.IJ)39 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)39 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)38 PeakResultProcedure (uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)36 PlugIn (ij.plugin.PlugIn)34 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)33 Counter (uk.ac.sussex.gdsc.smlm.results.count.Counter)33 ImagePlus (ij.ImagePlus)31 Rectangle (java.awt.Rectangle)31 SimpleArrayUtils (uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils)31 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)28 TextUtils (uk.ac.sussex.gdsc.core.utils.TextUtils)28 SettingsManager (uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager)28 FrameCounter (uk.ac.sussex.gdsc.smlm.results.count.FrameCounter)28