Search in sources :

Example 11 with PeakResult

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

the class HysteresisFilter method setup.

@Override
public void setup(MemoryPeakResults peakResults) {
    ok = new HashSet<PeakResult>();
    // Create a set of candidates and valid peaks
    MemoryPeakResults traceResults = new MemoryPeakResults();
    // Initialise peaks to check
    LinkedList<PeakResult> candidates = new LinkedList<PeakResult>();
    for (PeakResult result : peakResults.getResults()) {
        switch(getStatus(result)) {
            case OK:
                ok.add(result);
                traceResults.add(result);
                break;
            case CANDIDATE:
                candidates.add(result);
                traceResults.add(result);
                break;
            default:
                break;
        }
    }
    if (candidates.isEmpty()) {
        // No candidates for tracing so just return
        return;
    }
    double distanceThreshold;
    switch(searchDistanceMode) {
        case 1:
            distanceThreshold = searchDistance / peakResults.getNmPerPixel();
            break;
        case 0:
        default:
            distanceThreshold = getSearchDistanceUsingCandidates(peakResults, candidates);
    }
    if (distanceThreshold <= 0)
        return;
    int myTimeThreshold;
    switch(timeThresholdMode) {
        case 1:
            if (peakResults.getCalibration() != null) {
                myTimeThreshold = (int) Math.round((this.timeThreshold / peakResults.getCalibration().getExposureTime()));
            } else
                myTimeThreshold = 1;
            break;
        case 0:
        default:
            myTimeThreshold = (int) this.timeThreshold;
    }
    if (myTimeThreshold <= 0)
        return;
    // Trace through candidates
    TraceManager tm = new TraceManager(traceResults);
    tm.setTraceMode(TraceMode.LATEST_FORERUNNER);
    tm.traceMolecules(distanceThreshold, myTimeThreshold);
    Trace[] traces = tm.getTraces();
    for (Trace trace : traces) {
        if (trace.size() > 1) {
            // Check if the trace touches a valid point
            boolean isOk = false;
            for (PeakResult result : trace.getPoints()) {
                if (ok.contains(result)) {
                    isOk = true;
                    break;
                }
            }
            // Add the entire trace to the OK points
            if (isOk) {
                for (PeakResult result : trace.getPoints()) {
                    ok.add(result);
                }
            }
        }
    }
}
Also used : Trace(gdsc.smlm.results.Trace) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) TraceManager(gdsc.smlm.results.TraceManager) PeakResult(gdsc.smlm.results.PeakResult) LinkedList(java.util.LinkedList)

Example 12 with PeakResult

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

the class Filter method score.

/**
	 * Filter the results and return the performance score. Allows benchmarking the filter by marking the results as
	 * true or false.
	 * <p>
	 * Any input PeakResult with an original value that is not zero will be treated as a true result, all other results
	 * are false. The filter is run and the results are marked as true positive, false negative and false positive.
	 * 
	 * @param resultsList
	 *            a list of results to analyse
	 * @return the score
	 */
public ClassificationResult score(List<MemoryPeakResults> resultsList) {
    int tp = 0, fp = 0, tn = 0, fn = 0;
    for (MemoryPeakResults peakResults : resultsList) {
        setup(peakResults);
        for (PeakResult peak : peakResults.getResults()) {
            final boolean isTrue = peak.origValue != 0;
            boolean isPositive = accept(peak);
            if (isTrue) {
                if (isPositive)
                    // true positive
                    tp++;
                else
                    // false negative
                    fn++;
            } else {
                if (isPositive)
                    // false positive
                    fp++;
                else
                    // true negative
                    tn++;
            }
        }
        end();
    }
    return new ClassificationResult(tp, fp, tn, fn);
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) ClassificationResult(gdsc.core.match.ClassificationResult) FractionClassificationResult(gdsc.core.match.FractionClassificationResult) PeakResult(gdsc.smlm.results.PeakResult)

Example 13 with PeakResult

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

the class Filter method fractionScore.

/**
	 * Filter the results and return the performance score. Allows benchmarking the filter by marking the results as
	 * true or false.
	 * <p>
	 * Input PeakResults must be allocated a score for true positive, false positive, true negative and false negative
	 * (accessed via the object property get methods). The filter is run and results that pass accumulate scores for
	 * true positive and false positive, otherwise the scores are accumulated for true negative and false negative. The
	 * simplest scoring scheme is to mark valid results as tp=fn=1 and fp=tn=0 and invalid results the opposite.
	 * <p>
	 * The number of consecutive rejections are counted per frame. When the configured number of failures is reached all
	 * remaining results for the frame are rejected. This assumes the results are ordered by the frame.
	 * 
	 * @param resultsList
	 *            a list of results to analyse
	 * @param failures
	 *            the number of failures to allow per frame before all peaks are rejected
	 * @return the score
	 */
public FractionClassificationResult fractionScore(List<MemoryPeakResults> resultsList, int failures) {
    int p = 0, n = 0;
    double fp = 0, fn = 0;
    double tp = 0, tn = 0;
    for (MemoryPeakResults peakResults : resultsList) {
        setup(peakResults);
        int frame = -1;
        int failCount = 0;
        for (PeakResult peak : peakResults.getResults()) {
            // Reset fail count for new frames
            if (frame != peak.getFrame()) {
                frame = peak.getFrame();
                failCount = 0;
            }
            // Reject all peaks if we have exceeded the fail count
            final boolean isPositive;
            if (failCount > failures) {
                isPositive = false;
            } else {
                // Otherwise assess the peak
                isPositive = accept(peak);
            }
            if (isPositive) {
                failCount = 0;
            } else {
                failCount++;
            }
            if (isPositive) {
                p++;
                tp += peak.getTruePositiveScore();
                fp += peak.getFalsePositiveScore();
            } else {
                fn += peak.getFalseNegativeScore();
                tn += peak.getTrueNegativeScore();
            }
        }
        n += peakResults.size();
        end();
    }
    n -= p;
    return new FractionClassificationResult(tp, fp, tn, fn, p, n);
}
Also used : FractionClassificationResult(gdsc.core.match.FractionClassificationResult) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult)

Example 14 with PeakResult

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

the class Filter method filter.

/**
	 * Filter the results
	 * <p>
	 * The number of consecutive rejections are counted per frame. When the configured number of failures is reached all
	 * remaining results for the frame are rejected. This assumes the results are ordered by the frame.
	 * 
	 * @param results
	 * @param failures
	 *            the number of failures to allow per frame before all peaks are rejected
	 * @return the filtered results
	 */
public MemoryPeakResults filter(MemoryPeakResults results, int failures) {
    MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.copySettings(results);
    setup(results);
    int frame = -1;
    int failCount = 0;
    for (PeakResult peak : results.getResults()) {
        if (frame != peak.getFrame()) {
            frame = peak.getFrame();
            failCount = 0;
        }
        // Reject all peaks if we have exceeded the fail count
        final boolean isPositive;
        if (failCount > failures) {
            isPositive = false;
        } else {
            // Otherwise assess the peak
            isPositive = accept(peak);
        }
        if (isPositive) {
            failCount = 0;
            newResults.add(peak);
        } else {
            failCount++;
        }
    }
    end();
    return newResults;
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult)

Example 15 with PeakResult

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

the class Filter method filterSubset2.

/**
	 * Filter the results
	 * <p>
	 * Input PeakResults must be allocated a score for true positive, false positive, true negative and false negative
	 * (accessed via the object property get methods). The filter is run and results that pass accumulate scores for
	 * true positive and false positive, otherwise the scores are accumulated for true negative and false negative. The
	 * simplest scoring scheme is to mark valid results as tp=fn=1 and fp=tn=0 and invalid results the opposite.
	 * <p>
	 * The number of consecutive rejections are counted per frame. When the configured number of failures is reached all
	 * remaining results for the frame are rejected. This assumes the results are ordered by the frame.
	 * <p>
	 * Note that this method is to be used to score a set of results that may have been extracted from a larger set
	 * since the number of consecutive failures before each peak are expected to be stored in the origY property. Set
	 * this to zero and the results should be identical to {@link #filterSubset(MemoryPeakResults, double[])}.
	 * <p>
	 * The number of failures before each peak is stored in the origX property of the PeakResult.
	 * 
	 * @param results
	 * @param score
	 *            If not null will be populated with the fraction score [ tp, fp, tn, fn, p, n ]
	 * @return the filtered results
	 */
public MemoryPeakResults filterSubset2(MemoryPeakResults results, double[] score) {
    MemoryPeakResults newResults = new MemoryPeakResults();
    newResults.copySettings(results);
    setup(results);
    int frame = -1;
    int failCount = 0;
    double fp = 0, fn = 0;
    double tp = 0, tn = 0;
    int p = 0;
    for (PeakResult peak : results.getResults()) {
        if (frame != peak.getFrame()) {
            frame = peak.getFrame();
            failCount = 0;
        }
        failCount += peak.origY;
        // Reject all peaks if we have exceeded the fail count
        final boolean isPositive = accept(peak);
        if (isPositive) {
            peak.origX = failCount;
            failCount = 0;
            newResults.add(peak);
        } else {
            failCount++;
        }
        if (isPositive) {
            p++;
            tp += peak.getTruePositiveScore();
            fp += peak.getFalsePositiveScore();
        } else {
            fn += peak.getFalseNegativeScore();
            tn += peak.getTrueNegativeScore();
        }
    }
    end();
    if (score != null && score.length > 5) {
        score[0] = tp;
        score[1] = fp;
        score[2] = tn;
        score[3] = fn;
        score[4] = p;
        score[5] = results.size() - p;
    }
    return newResults;
}
Also used : MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) 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