Search in sources :

Example 11 with FilterSet

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

the class FilterAnalysis method addTraceFilters.

private void addTraceFilters(List<FilterSet> filterSets) {
    if (!traceFilter)
        return;
    for (double d = minDistance; d <= maxDistance; d += incDistance) {
        SNRFilter snr = new SNRFilter(maxSnr);
        List<Filter> filters = new LinkedList<Filter>();
        for (int t = minTime; t <= maxTime; t += incTime) {
            filters.add(new OrFilter(snr, new TraceFilter(d, t)));
        }
        filterSets.add(new FilterSet(filters));
    }
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) Filter(gdsc.smlm.results.filter.Filter) OrFilter(gdsc.smlm.results.filter.OrFilter) FilenameFilter(java.io.FilenameFilter) AndFilter(gdsc.smlm.results.filter.AndFilter) WidthFilter(gdsc.smlm.results.filter.WidthFilter) SNRFilter(gdsc.smlm.results.filter.SNRFilter) PrecisionHysteresisFilter(gdsc.smlm.results.filter.PrecisionHysteresisFilter) TraceFilter(gdsc.smlm.results.filter.TraceFilter) PrecisionFilter(gdsc.smlm.results.filter.PrecisionFilter) SNRHysteresisFilter(gdsc.smlm.results.filter.SNRHysteresisFilter) SNRFilter(gdsc.smlm.results.filter.SNRFilter) TraceFilter(gdsc.smlm.results.filter.TraceFilter) OrFilter(gdsc.smlm.results.filter.OrFilter) LinkedList(java.util.LinkedList)

Example 12 with FilterSet

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

the class FilterAnalysis method addPrecisionHysteresisFilters.

private void addPrecisionHysteresisFilters(List<FilterSet> filterSets) {
    if (!hysteresisPrecisionFilter)
        return;
    for (int precisionGap = minPrecisionGap; precisionGap <= maxPrecisionGap; precisionGap += incPrecisionGap) {
        List<Filter> filters = new LinkedList<Filter>();
        for (int precision = minPrecision; precision <= maxPrecision; precision++) {
            filters.add(new PrecisionHysteresisFilter(2, 0, 1, 0, precision, precisionGap));
        }
        filterSets.add(new FilterSet(filters));
    }
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) Filter(gdsc.smlm.results.filter.Filter) OrFilter(gdsc.smlm.results.filter.OrFilter) FilenameFilter(java.io.FilenameFilter) AndFilter(gdsc.smlm.results.filter.AndFilter) WidthFilter(gdsc.smlm.results.filter.WidthFilter) SNRFilter(gdsc.smlm.results.filter.SNRFilter) PrecisionHysteresisFilter(gdsc.smlm.results.filter.PrecisionHysteresisFilter) TraceFilter(gdsc.smlm.results.filter.TraceFilter) PrecisionFilter(gdsc.smlm.results.filter.PrecisionFilter) SNRHysteresisFilter(gdsc.smlm.results.filter.SNRHysteresisFilter) PrecisionHysteresisFilter(gdsc.smlm.results.filter.PrecisionHysteresisFilter) LinkedList(java.util.LinkedList)

Example 13 with FilterSet

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

the class FilterAnalysis method analyse.

/**
	 * Run different filtering methods on a set of labelled peak results outputting performance statistics on the
	 * success of
	 * the filter to an ImageJ table.
	 * <p>
	 * If the peak result original value is set to 1 it is considered a true peak, 0 for a false peak. Filtering is done
	 * using e.g. SNR threshold, Precision thresholds, etc. The statistics reported are shown in a table, e.g.
	 * precision, Jaccard, F-score.
	 * <p>
	 * For each filter set a plot is shown of the Jaccard score verses the filter value, thus filters should be provided
	 * in ascending numerical order otherwise they are sorted.
	 * 
	 * @param resultsList
	 * @param filterSets
	 */
public void analyse(List<MemoryPeakResults> resultsList, List<FilterSet> filterSets) {
    createResultsWindow();
    plots = new ArrayList<NamedPlot>(plotTopN);
    bestFilter = new HashMap<String, FilterScore>();
    bestFilterOrder = new LinkedList<String>();
    IJ.showStatus("Analysing filters ...");
    int total = countFilters(filterSets);
    int count = 0;
    for (FilterSet filterSet : filterSets) {
        IJ.showStatus("Analysing " + filterSet.getName() + " ...");
        count = run(filterSet, resultsList, count, total);
    }
    IJ.showProgress(1);
    IJ.showStatus("");
    showPlots();
    calculateSensitivity(resultsList);
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet)

Example 14 with FilterSet

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

the class BenchmarkFilterAnalysis method iterate.

private void iterate() {
    // If this is run again immediately then provide options for reporting the results
    if (iterBestFilter != null && iterBestFilter == bestFilter) {
        GenericDialog gd = new GenericDialog(TITLE);
        gd.enableYesNoCancel();
        gd.addMessage("Iteration results are held in memory.\n \nReport these results?");
        gd.showDialog();
        if (gd.wasCanceled())
            return;
        if (gd.wasOKed()) {
            reportIterationResults();
            return;
        }
    }
    // TODO - collect this in the iteration dialog
    if (!showIterationDialog())
        return;
    // Total the time from the interactive plugins
    long time = 0;
    // Run the benchmark fit once interactively, keep the instance
    BenchmarkSpotFit fit = new BenchmarkSpotFit();
    // than has been optimised before)
    if (fit.resetMultiPathFilter() || invalidBenchmarkSpotFitResults(true)) {
        fit.run(null);
        if (!fit.finished)
            // The plugin did not complete
            return;
        resetParametersFromFitting();
    }
    if (invalidBenchmarkSpotFitResults(false))
        return;
    if (BenchmarkSpotFit.stopWatch != null)
        time += BenchmarkSpotFit.stopWatch.getTime();
    // Run filter analysis once interactively
    if (!loadFitResults())
        return;
    // Collect parameters for optimising the parameters
    if (!showDialog(FLAG_OPTIMISE_FILTER | FLAG_OPTIMISE_PARAMS))
        return;
    // Load filters from file
    List<FilterSet> filterSets = readFilterSets();
    if (filterSets == null || filterSets.isEmpty()) {
        IJ.error(TITLE, "No filters specified");
        return;
    }
    ComplexFilterScore current = analyse(filterSets);
    if (current == null)
        return;
    time += filterAnalysisStopWatch.getTime();
    current = analyseParameters(current);
    if (current == null)
        return;
    time += parameterAnalysisStopWatch.getTime();
    // Time the non-interactive plugins as a continuous section
    iterationStopWatch = StopWatch.createStarted();
    // Remove the previous iteration results
    iterBestFilter = null;
    Utils.log(TITLE + " Iterating ...");
    IterationConvergenceChecker checker = new IterationConvergenceChecker(current);
    // Iterate ...
    boolean outerConverged = false;
    int outerIteration = 1;
    double outerRangeReduction = 1;
    while (!outerConverged) {
        if (iterationConvergeBeforeRefit) {
            // Optional inner loop so that the non-filter and filter parameters converge
            // before a refit
            boolean innerConverged = false;
            int innerIteration = 0;
            double innerRangeReduction = 1;
            if (iterationMinRangeReduction < 1) {
                // Linear interpolate down to the min range reduction
                innerRangeReduction = Maths.max(iterationMinRangeReduction, Maths.interpolateY(0, 1, iterationMinRangeReductionIteration, iterationMinRangeReduction, innerIteration++));
            // This would make the range too small...
            //innerRangeReduction *= outerRangeReduction;
            }
            while (!innerConverged) {
                ComplexFilterScore previous = current;
                // Re-use the filters as the user may be loading a custom set.
                current = analyse(filterSets, current, innerRangeReduction);
                if (current == null)
                    break;
                double[] previousParameters = createParameters();
                current = analyseParameters(current, innerRangeReduction);
                if (current == null)
                    return;
                double[] currentParameters = createParameters();
                innerConverged = checker.converged("Filter", previous, current, previousParameters, currentParameters);
            }
            // Check if we can continue (e.g. not max iterations or escape pressed) 
            if (!checker.canContinue)
                break;
        }
        // Do the fit (using the current optimum filter)
        fit.run(current.r.filter, residualsThreshold, failCount, duplicateDistance);
        if (invalidBenchmarkSpotFitResults(false))
            return;
        if (!loadFitResults())
            return;
        // is centred around the current optimum.
        if (iterationMinRangeReduction < 1) {
            // Linear interpolate down to the min range reduction
            outerRangeReduction = Maths.max(iterationMinRangeReduction, Maths.interpolateY(0, 1, iterationMinRangeReductionIteration, iterationMinRangeReduction, outerIteration++));
        }
        // Optimise the filter again.
        ComplexFilterScore previous = current;
        // Re-use the filters as the user may be loading a custom set.
        current = analyse(filterSets, current, outerRangeReduction);
        if (current == null)
            break;
        double[] previousParameters = createParameters();
        current = analyseParameters(current, outerRangeReduction);
        if (current == null)
            return;
        double[] currentParameters = createParameters();
        outerConverged = checker.converged("Fit+Filter", previous, current, previousParameters, currentParameters);
    }
    if (current != null) //if (converged)
    {
        // Set-up the plugin so that it can be run again (in iterative mode) 
        // and the results reported for the top filter.
        // If the user runs the non-iterative mode then the results will be lost.
        iterBestFilter = bestFilter;
    }
    time += iterationStopWatch.getTime();
    IJ.log("Iteration analysis time : " + DurationFormatUtils.formatDurationHMS(time));
    IJ.showStatus("Finished");
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) GenericDialog(ij.gui.GenericDialog) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog)

Example 15 with FilterSet

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

the class BenchmarkFilterAnalysis method saveFilter.

private void saveFilter(DirectFilter filter) {
    // Save the filter to file
    String filename = getFilename("Best_Filter_File", filterFilename);
    if (filename != null) {
        filterFilename = filename;
        Prefs.set(KEY_FILTER_FILENAME, filename);
        List<Filter> filters = new ArrayList<Filter>(1);
        filters.add(filter);
        FilterSet filterSet = new FilterSet(filter.getName(), filters);
        List<FilterSet> list = new ArrayList<FilterSet>(1);
        list.add(filterSet);
        saveFilterSet(filterSet, filename);
    }
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) Filter(gdsc.smlm.results.filter.Filter) MultiPathFilter(gdsc.smlm.results.filter.MultiPathFilter) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) ArrayList(java.util.ArrayList)

Aggregations

FilterSet (gdsc.smlm.results.filter.FilterSet)17 Filter (gdsc.smlm.results.filter.Filter)9 DirectFilter (gdsc.smlm.results.filter.DirectFilter)7 IDirectFilter (gdsc.smlm.results.filter.IDirectFilter)7 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 AndFilter (gdsc.smlm.results.filter.AndFilter)5 OrFilter (gdsc.smlm.results.filter.OrFilter)5 PrecisionFilter (gdsc.smlm.results.filter.PrecisionFilter)5 PrecisionHysteresisFilter (gdsc.smlm.results.filter.PrecisionHysteresisFilter)5 SNRFilter (gdsc.smlm.results.filter.SNRFilter)5 SNRHysteresisFilter (gdsc.smlm.results.filter.SNRHysteresisFilter)5 TraceFilter (gdsc.smlm.results.filter.TraceFilter)5 WidthFilter (gdsc.smlm.results.filter.WidthFilter)5 FilenameFilter (java.io.FilenameFilter)5 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)4 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)4 GenericDialog (ij.gui.GenericDialog)4 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)4 IOException (java.io.IOException)3