Search in sources :

Example 1 with PeakResults

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

the class PeakFit method showResults.

/**
 * Show results.
 */
protected void showResults() {
    IJ.showProgress(1.0);
    if (time >= 0) {
        if (silent) {
            results.end();
            return;
        }
        // Check if we are sorting
        IJ.showStatus("Finalising results ...");
        for (final PeakResults r : results.toArray()) {
            if (r instanceof MemoryPeakResults) {
                if (((MemoryPeakResults) r).isSortAfterEnd()) {
                    IJ.showStatus("Sorting " + r.size() + " results ...");
                }
                break;
            }
        }
        results.end();
        final String textTime = TextUtils.nanosToString(time);
        final String textRunTime = TextUtils.nanosToString(runTime);
        final int size = getSize();
        final String message = String.format("%s. Total fitting time = %s. Run time = %s", TextUtils.pleural(size, "localisation"), textTime, textRunTime);
        if (resultsSettings.getLogProgress()) {
            IJ.log(LOG_SPACER);
        }
        IJ.log(message);
        IJ.showStatus(message);
    } else {
        IJ.showStatus("");
    }
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) FilePeakResults(uk.ac.sussex.gdsc.smlm.results.FilePeakResults) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 2 with PeakResults

use of uk.ac.sussex.gdsc.smlm.results.PeakResults 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 localImp = this.imp;
    if (fitMaxima && singleFrame > 0 && source instanceof IJImageSource) {
        final String title = source.getName();
        localImp = WindowManager.getImage(title);
    }
    if (singleFrame > 0 && localImp != null) {
        MemoryPeakResults memoryResults = null;
        for (final PeakResults r : this.results.toArray()) {
            if (r instanceof MemoryPeakResults) {
                memoryResults = (MemoryPeakResults) r;
                break;
            }
        }
        if (memoryResults == null || memoryResults.size() == 0) {
            return;
        }
        final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.hideCancelButton();
        gd.addMessage("Add the fitted localisations as an overlay?");
        gd.showDialog();
        if (!gd.wasOKed()) {
            return;
        }
        final LUT lut = LutHelper.createLut(LutColour.ICE);
        final Overlay o = new Overlay();
        final int size = memoryResults.size();
        final Counter j = new Counter(size);
        final ImagePlus finalImp = localImp;
        memoryResults.forEach(DistanceUnit.PIXEL, (XyResultProcedure) (x, y) -> {
            final PointRoi roi = new OffsetPointRoi(x, y);
            final Color c = LutHelper.getColour(lut, j.decrementAndGet(), size);
            roi.setStrokeColor(c);
            roi.setFillColor(c);
            if (finalImp.getStackSize() > 1) {
                roi.setPosition(singleFrame);
            }
            o.add(roi);
        });
        localImp.setOverlay(o);
        localImp.getWindow().toFront();
    }
}
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) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) Color(java.awt.Color) SystemColor(java.awt.SystemColor) LUT(ij.process.LUT) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ImagePlus(ij.ImagePlus) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) FilePeakResults(uk.ac.sussex.gdsc.smlm.results.FilePeakResults) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi)

Example 3 with PeakResults

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

the class ResultsManager method addFileResults.

/**
 * Adds the file results.
 *
 * @param resultsList the results list
 * @param resultsSettings the results settings
 * @param resultsFilename the results filename
 * @param showDeviations the show deviations
 * @param showEndFrame the show end frame
 * @param showId the show id
 * @param showCategory the show category
 * @return the peak results
 */
public static PeakResults addFileResults(PeakResultsList resultsList, ResultsFileSettings resultsSettings, String resultsFilename, boolean showDeviations, boolean showEndFrame, boolean showId, boolean showCategory) {
    if (resultsSettings.getFileFormatValue() > 0 && resultsFilename != null) {
        final File file = new File(resultsFilename);
        final File parent = file.getParentFile();
        if (parent != null && parent.exists()) {
            PeakResults results;
            switch(resultsSettings.getFileFormat()) {
                case BINARY:
                    results = new BinaryFilePeakResults(resultsFilename, showDeviations, showEndFrame, showId, resultsSettings.getShowPrecision(), showCategory);
                    break;
                case TEXT:
                    final TextFilePeakResults f = new TextFilePeakResults(resultsFilename, showDeviations, showEndFrame, showId, resultsSettings.getShowPrecision(), showCategory);
                    f.setDistanceUnit(resultsSettings.getDistanceUnit());
                    f.setIntensityUnit(resultsSettings.getIntensityUnit());
                    f.setAngleUnit(resultsSettings.getAngleUnit());
                    f.setComputePrecision(true);
                    results = f;
                    break;
                case MALK:
                    results = new MalkFilePeakResults(resultsFilename);
                    break;
                case TSF:
                    results = new TsfPeakResultsWriter(resultsFilename);
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported file format: " + resultsSettings.getFileFormat());
            }
            resultsList.addOutput(results);
            return results;
        }
    }
    return null;
}
Also used : BinaryFilePeakResults(uk.ac.sussex.gdsc.smlm.results.BinaryFilePeakResults) MalkFilePeakResults(uk.ac.sussex.gdsc.smlm.results.MalkFilePeakResults) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) BinaryFilePeakResults(uk.ac.sussex.gdsc.smlm.results.BinaryFilePeakResults) MalkFilePeakResults(uk.ac.sussex.gdsc.smlm.results.MalkFilePeakResults) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) TsfPeakResultsWriter(uk.ac.sussex.gdsc.smlm.results.TsfPeakResultsWriter) File(java.io.File) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)

Example 4 with PeakResults

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

the class PeakFit method createFitEngine.

/**
 * Creates a fitting engine using the current configuration.
 *
 * @param numberOfThreads the number of threads
 * @param queue the queue
 * @param queueSize the queue size
 * @return The fiting engine
 */
public FitEngine createFitEngine(int numberOfThreads, FitQueue queue, int queueSize) {
    // Ensure thread safety
    final PeakResultsList list = (numberOfThreads > 1) ? results.getThreadSafeList() : results;
    // Reduce to single object for speed
    final PeakResults r = (results.numberOfOutputs() == 1) ? list.toArray()[0] : list;
    // Update the configuration
    if (!updateFitConfiguration(config)) {
        return null;
    }
    final FitEngine engine = FitEngine.create(config, r, numberOfThreads, queue, queueSize);
    // Write settings out to the IJ log
    if (resultsSettings.getLogProgress()) {
        IJ.log(LOG_SPACER);
        IJ.log("Peak Fit");
        IJ.log(LOG_SPACER);
        ImageJUtils.log("Initial Peak SD = %s,%s", MathUtils.rounded(fitConfig.getInitialXSd()), MathUtils.rounded(fitConfig.getInitialYSd()));
        final SpotFilter spotFilter = engine.getSpotFilter();
        IJ.log("Spot Filter = " + spotFilter.getDescription());
        final int w = 2 * engine.getFitting() + 1;
        ImageJUtils.log("Fit window = %d x %d", w, w);
        if (!fitConfig.isDisableSimpleFilter()) {
            IJ.log("Coordinate shift = " + MathUtils.rounded(config.getFitConfiguration().getCoordinateShift()));
            IJ.log("Signal strength = " + MathUtils.rounded(fitConfig.getSignalStrength()));
        }
        if (fitConfig.isDirectFilter()) {
            IJ.log("Smart filter = " + fitConfig.getSmartFilter().getDescription());
        }
        if (extraOptions) {
            IJ.log("Noise = " + MathUtils.rounded(fitConfig.getNoise()));
        }
        IJ.log("Width factor = " + MathUtils.rounded(fitConfig.getMaxWidthFactor()));
        IJ.log(LOG_SPACER);
    }
    return engine;
}
Also used : PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) FitEngine(uk.ac.sussex.gdsc.smlm.engine.FitEngine) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) FilePeakResults(uk.ac.sussex.gdsc.smlm.results.FilePeakResults) ImageJTablePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) SpotFilter(uk.ac.sussex.gdsc.smlm.filters.SpotFilter)

Example 5 with PeakResults

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

the class ResultsMatchCalculator method savePairs.

private void savePairs(MemoryPeakResults results1, MemoryPeakResults results2, List<PointPair> allMatches) {
    if (!settings.savePairs) {
        return;
    }
    // Get the directory
    final String directory = ImageJUtils.getDirectory("Pairs_directory", settings.pairsDirectory);
    if (directory == null) {
        return;
    }
    settings.pairsDirectory = directory;
    final double[] distanceThresholds = getDistances(settings.distanceThreshold, settings.increments, settings.delta);
    // Create output files for each distance band
    final PeakResults[] output1 = new PeakResults[distanceThresholds.length];
    final PeakResults[] output2 = new PeakResults[distanceThresholds.length];
    double high = 0;
    for (int i = 0; i < distanceThresholds.length; i++) {
        final double low = high;
        high = distanceThresholds[i];
        output1[i] = createFilePeakResults(directory, 1, results1, low, high);
        output2[i] = createFilePeakResults(directory, 2, results2, low, high);
    }
    // Square the thresholds
    SimpleArrayUtils.apply(distanceThresholds, v -> v * v);
    final double[] pairDistances = getPairDistances(allMatches);
    int index = 0;
    for (final PointPair pair : allMatches) {
        final int insert = search(distanceThresholds, pairDistances[index++]);
        if (insert != -1) {
            final PeakResult r1 = ((PeakResultPoint) pair.getPoint1()).getPeakResult();
            final PeakResult r2 = ((PeakResultPoint) pair.getPoint2()).getPeakResult();
            output1[insert].add(r1);
            output2[insert].add(r2);
        }
    }
    for (int i = 0; i < output1.length; i++) {
        output1[i].end();
        output2[i].end();
    }
}
Also used : MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) TextFilePeakResults(uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults) PointPair(uk.ac.sussex.gdsc.core.match.PointPair) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) Point(java.awt.Point) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Aggregations

MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)12 PeakResults (uk.ac.sussex.gdsc.smlm.results.PeakResults)12 ImageJImagePeakResults (uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults)9 ImageJTablePeakResults (uk.ac.sussex.gdsc.smlm.ij.results.ImageJTablePeakResults)8 File (java.io.File)5 FilePeakResults (uk.ac.sussex.gdsc.smlm.results.FilePeakResults)5 TextFilePeakResults (uk.ac.sussex.gdsc.smlm.results.TextFilePeakResults)5 ImagePlus (ij.ImagePlus)3 ImageStack (ij.ImageStack)3 Rectangle (java.awt.Rectangle)3 ArrayList (java.util.ArrayList)3 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)3 IJ (ij.IJ)2 Prefs (ij.Prefs)2 GenericDialog (ij.gui.GenericDialog)2 YesNoCancelDialog (ij.gui.YesNoCancelDialog)2 Checkbox (java.awt.Checkbox)2 Choice (java.awt.Choice)2 Label (java.awt.Label)2 Panel (java.awt.Panel)2