Search in sources :

Example 6 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class FilterResults method filterResults.

/**
	 * Apply the filters to the data
	 */
private void filterResults() {
    checkLimits();
    MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.copySettings(results);
    newResults.setName(results.getName() + " Filtered");
    // Initialise the mask
    ByteProcessor mask = getMask(filterSettings.maskTitle);
    MaskDistribution maskFilter = null;
    final float centreX = results.getBounds().width / 2.0f;
    final float centreY = results.getBounds().height / 2.0f;
    if (mask != null) {
        double scaleX = (double) results.getBounds().width / mask.getWidth();
        double scaleY = (double) results.getBounds().height / mask.getHeight();
        maskFilter = new MaskDistribution((byte[]) mask.getPixels(), mask.getWidth(), mask.getHeight(), 0, scaleX, scaleY);
    }
    int i = 0;
    final int size = results.size();
    final double maxVariance = filterSettings.maxPrecision * filterSettings.maxPrecision;
    for (PeakResult result : results.getResults()) {
        if (i % 64 == 0)
            IJ.showProgress(i, size);
        if (getDrift(result) > filterSettings.maxDrift)
            continue;
        if (result.getSignal() < filterSettings.minSignal)
            continue;
        if (getSNR(result) < filterSettings.minSNR)
            continue;
        if (getVariance(result) > maxVariance)
            continue;
        final float width = getWidth(result);
        if (width < filterSettings.minWidth || width > filterSettings.maxWidth)
            continue;
        if (maskFilter != null) {
            // Check the coordinates are inside the mask
            double[] xy = new double[] { result.getXPosition() - centreX, result.getYPosition() - centreY };
            if (!maskFilter.isWithinXY(xy))
                continue;
        }
        // Passed all filters. Add to the results
        newResults.add(result);
    }
    IJ.showProgress(1);
    IJ.showStatus(newResults.size() + " Filtered localisations");
    MemoryPeakResults.addResults(newResults);
}
Also used : ByteProcessor(ij.process.ByteProcessor) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) MaskDistribution(gdsc.smlm.model.MaskDistribution) PeakResult(gdsc.smlm.results.PeakResult)

Example 7 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class FilterResults method analyseResults.

/**
	 * Analyse the results and determine the range for each filter
	 */
private void analyseResults() {
    IJ.showStatus("Analysing results ...");
    nmPerPixel = results.getNmPerPixel();
    gain = results.getGain();
    emCCD = results.isEMCCD();
    double maxVariance = maxPrecision * maxPrecision;
    double minVariance = minPrecision * minPrecision;
    int size = results.size();
    int i = 0;
    for (PeakResult result : results.getResults()) {
        if (i % 64 == 0)
            IJ.showProgress(i, size);
        final float drift = getDrift(result);
        if (maxDrift < drift)
            maxDrift = drift;
        if (minDrift > drift)
            minDrift = drift;
        final float signal = result.getSignal();
        if (maxSignal < signal)
            maxSignal = signal;
        if (minSignal > signal)
            minSignal = signal;
        final float snr = getSNR(result);
        if (maxSNR < snr)
            maxSNR = snr;
        if (minSNR > snr)
            minSNR = snr;
        // Use variance to avoid sqrt()
        final double variance = getVariance(result);
        if (maxVariance < variance)
            maxVariance = variance;
        if (minVariance > variance)
            minVariance = variance;
        final float width = getWidth(result);
        averageWidth += width;
        if (maxWidth < width)
            maxWidth = width;
        if (minWidth > width)
            minWidth = width;
    }
    averageWidth /= results.size();
    maxPrecision = Math.sqrt(maxVariance);
    minPrecision = Math.sqrt(minVariance);
    IJ.showProgress(1);
    IJ.showStatus("");
}
Also used : PeakResult(gdsc.smlm.results.PeakResult)

Example 8 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class LoadLocalisations method getZDepth.

private boolean getZDepth(MemoryPeakResults results) {
    // The z-depth is stored in pixels in the error field
    double min = results.getHead().error;
    double max = min;
    for (PeakResult peak : results.getResults()) {
        if (min > peak.error)
            min = peak.error;
        else if (max < peak.error)
            max = peak.error;
    }
    // No z-depth
    if (min == max && min == 0)
        return true;
    maxz = FastMath.min(maxz, max);
    minz = FastMath.max(minz, min);
    // Display in nm
    final double pp = results.getNmPerPixel();
    min *= pp;
    max *= pp;
    String msg = String.format("%d localisations with %.2f <= z <= %.2f", results.size(), min, max);
    min = Math.floor(min);
    max = Math.ceil(max);
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage(msg);
    gd.addCheckbox("Limit Z-depth", limitZ);
    gd.addSlider("minZ", min, max, minz * pp);
    gd.addSlider("maxZ", min, max, maxz * pp);
    gd.showDialog();
    if (gd.wasCanceled() || gd.invalidNumber()) {
        return false;
    }
    myLimitZ = limitZ = gd.getNextBoolean();
    minz = gd.getNextNumber() / pp;
    maxz = gd.getNextNumber() / pp;
    return true;
}
Also used : GenericDialog(ij.gui.GenericDialog) PeakResult(gdsc.smlm.results.PeakResult) AttributePeakResult(gdsc.smlm.results.AttributePeakResult)

Example 9 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class FIRE method canCalculatePrecision.

private boolean canCalculatePrecision(MemoryPeakResults results) {
    // Calibration is required to compute the precision
    Calibration cal = results.getCalibration();
    if (cal == null)
        return false;
    if (!cal.hasNmPerPixel() || !cal.hasGain() || !cal.hasEMCCD())
        return false;
    // Check all have a width and signal
    PeakResult[] data = results.toArray();
    for (int i = 0; i < data.length; i++) {
        PeakResult p = data[i];
        if (p.getSD() <= 0 || p.getSignal() <= 0)
            return true;
    }
    // Check for variable width that is not 1 and a variable signal
    for (int i = 0; i < data.length; i++) {
        PeakResult p = data[i];
        // Check this is valid
        if (p.getSD() != 1) {
            // Check the rest for a different value
            float w1 = p.getSD();
            float s1 = p.getSignal();
            for (int j = i + 1; j < data.length; j++) {
                PeakResult p2 = data[j];
                if (p2.getSD() != 1 && p2.getSD() != w1 && p2.getSignal() != s1)
                    return true;
            }
            // All the results are the same, this is not valid
            break;
        }
    }
    return false;
}
Also used : Calibration(gdsc.smlm.results.Calibration) PeakResult(gdsc.smlm.results.PeakResult) WeightedObservedPoint(org.apache.commons.math3.fitting.WeightedObservedPoint)

Example 10 with PeakResult

use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.

the class HysteresisFilter method getSearchDistanceUsingCandidates.

/**
	 * Find average precision of the candidates and use it for the search
	 * distance
	 * 
	 * @param peakResults
	 * @param candidates
	 * @return
	 */
private double getSearchDistanceUsingCandidates(MemoryPeakResults peakResults, LinkedList<PeakResult> candidates) {
    SummaryStatistics stats = new SummaryStatistics();
    final double nmPerPixel = peakResults.getNmPerPixel();
    final double gain = peakResults.getGain();
    final boolean emCCD = peakResults.isEMCCD();
    for (PeakResult peakResult : candidates) {
        stats.addValue(peakResult.getPrecision(nmPerPixel, gain, emCCD));
    }
    double distanceThreshold = stats.getMean() * searchDistance / nmPerPixel;
    return distanceThreshold;
}
Also used : SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) PeakResult(gdsc.smlm.results.PeakResult)

Aggregations

PeakResult (gdsc.smlm.results.PeakResult)89 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)40 ExtendedPeakResult (gdsc.smlm.results.ExtendedPeakResult)18 Rectangle (java.awt.Rectangle)18 ArrayList (java.util.ArrayList)17 IdPeakResult (gdsc.smlm.results.IdPeakResult)13 ImagePlus (ij.ImagePlus)9 Point (java.awt.Point)9 Trace (gdsc.smlm.results.Trace)8 ImageStack (ij.ImageStack)7 FractionClassificationResult (gdsc.core.match.FractionClassificationResult)6 Calibration (gdsc.smlm.results.Calibration)6 PreprocessedPeakResult (gdsc.smlm.results.filter.PreprocessedPeakResult)6 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)6 BasePoint (gdsc.core.match.BasePoint)5 Statistics (gdsc.core.utils.Statistics)5 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)5 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)5 GenericDialog (ij.gui.GenericDialog)5 ImageProcessor (ij.process.ImageProcessor)5