Search in sources :

Example 6 with FilterSet

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

the class BenchmarkFilterAnalysis method saveFilterSet.

private static void saveFilterSet(FilterSet filterSet, String filename) {
    OutputStreamWriter out = null;
    try {
        List<FilterSet> list = new ArrayList<FilterSet>(1);
        list.add(filterSet);
        FileOutputStream fos = new FileOutputStream(filename);
        out = new OutputStreamWriter(fos, "UTF-8");
        // Use the instance so we can catch the exception
        out.write(XmlUtils.prettyPrintXml(XStreamWrapper.getInstance().toXML(list)));
    } catch (Exception e) {
        IJ.log("Unable to save the filter sets to file: " + e.getMessage());
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with FilterSet

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

the class BenchmarkFilterAnalysis method expandFilters.

/**
	 * If filters have been provided in FiltersSets of 3 then expand the filters into a set assuming the three represent
	 * min:max:increment.
	 */
private void expandFilters() {
    // Do not clear these when reading a new set of filters. 
    // The filters may be the same with slight modifications and so it is useful to keep the last settings.
    //searchRangeMap.clear();
    //stepSizeMap.clear();
    long[] expanded = new long[filterList.size()];
    String[] name = new String[expanded.length];
    int c = 0;
    boolean doIt = false;
    for (FilterSet filterSet : filterList) {
        if (filterSet.size() == 3 && filterSet.allSameType()) {
            name[c] = filterSet.getName();
            // Check we have min:max:increment by counting the combinations
            Filter f1 = filterSet.getFilters().get(0);
            Filter f2 = filterSet.getFilters().get(1);
            Filter f3 = filterSet.getFilters().get(2);
            int n = f1.getNumberOfParameters();
            double[] parameters = new double[n];
            double[] parameters2 = new double[n];
            double[] increment = new double[n];
            for (int i = 0; i < n; i++) {
                parameters[i] = f1.getParameterValue(i);
                parameters2[i] = f2.getParameterValue(i);
                increment[i] = f3.getParameterValue(i);
            }
            long combinations = countCombinations(parameters, parameters2, increment);
            if (combinations > 1) {
                expanded[c] = combinations;
                doIt = true;
            }
        }
        c++;
    }
    if (!doIt)
        return;
    GenericDialog gd = new GenericDialog(TITLE);
    gd.hideCancelButton();
    StringBuilder sb = new StringBuilder("The filter file contains potential triples of min:max:increment.\n \n");
    for (c = 0; c < expanded.length; c++) {
        if (expanded[c] > 0) {
            sb.append("Expand set [").append((c + 1)).append("]");
            if (!Utils.isNullOrEmpty(name[c]))
                sb.append(" ").append(name[c]);
            sb.append(" to ").append(expanded[c]).append(" filters\n");
        }
    }
    gd.addMessage(sb.toString());
    gd.addCheckbox("Expand_filters", expandFilters);
    gd.showDialog();
    if (!gd.wasCanceled()) {
        if (!(expandFilters = gd.getNextBoolean()))
            return;
    }
    IJ.showStatus("Expanding filters ...");
    List<FilterSet> filterList2 = new ArrayList<FilterSet>(filterList.size());
    for (FilterSet filterSet : filterList) {
        c = filterList2.size();
        if (expanded[c] == 0) {
            filterList2.add(filterSet);
            continue;
        }
        Filter f1 = filterSet.getFilters().get(0);
        Filter f2 = filterSet.getFilters().get(1);
        Filter f3 = filterSet.getFilters().get(2);
        final int n = f1.getNumberOfParameters();
        double[] parameters = new double[n];
        double[] parameters2 = new double[n];
        double[] increment = new double[n];
        for (int i = 0; i < n; i++) {
            parameters[i] = f1.getParameterValue(i);
            parameters2[i] = f2.getParameterValue(i);
            increment[i] = f3.getParameterValue(i);
        }
        List<Filter> list = expandFilters(f1, parameters, parameters2, increment);
        filterList2.add(new FilterSet(filterSet.getName(), list));
    }
    IJ.showStatus("");
    filterList = filterList2;
    Utils.log("Expanded input to %d filters in %s", countFilters(filterList), Utils.pleural(filterList.size(), "set"));
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) ArrayList(java.util.ArrayList) 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) GenericDialog(ij.gui.GenericDialog) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog)

Example 8 with FilterSet

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

the class BenchmarkSpotFit method saveFilters.

private boolean saveFilters(String filename, ArrayList<Filter> filters) {
    ArrayList<FilterSet> filterList = new ArrayList<FilterSet>(1);
    // Add Range keyword to identify as a range filter set 
    filterList.add(new FilterSet("Range", filters));
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(filename);
        // Use the instance (not .toXML() method) to allow the exception to be caught
        XStreamWrapper.getInstance().toXML(filterList, fos);
        return true;
    } catch (Exception e) {
        IJ.log("Unable to save the filter set to file: " + e.getMessage());
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    return false;
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) OutOfRangeException(org.apache.commons.math3.exception.OutOfRangeException)

Example 9 with FilterSet

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

the class BenchmarkFilterAnalysis method score.

public SearchResult<FilterScore>[] score(double[][] points) {
    ga_iteration++;
    SimpleFilterScore max = es_optimum;
    final FilterScoreResult[] scoreResults = scoreFilters(setStrength(new FilterSet(searchSpaceToFilters(points))), false);
    if (scoreResults == null)
        return null;
    @SuppressWarnings("unchecked") SearchResult<FilterScore>[] scores = new SearchResult[scoreResults.length];
    for (int index = 0; index < scoreResults.length; index++) {
        final FilterScoreResult scoreResult = scoreResults[index];
        final SimpleFilterScore result = new SimpleFilterScore(scoreResult, true, scoreResult.criteria >= minCriteria);
        if (result.compareTo(max) < 0) {
            max = result;
        }
        scores[index] = new SearchResult<FilterScore>(result.r.filter.getParameters(), result);
    }
    es_optimum = max;
    // Add the best filter to the table
    // This filter may not have been part of the scored subset so use the entire results set for reporting
    DirectFilter filter = max.r.filter;
    FractionClassificationResult r = scoreFilter(filter, minimalFilter, ga_resultsList, coordinateStore);
    final StringBuilder text = createResult(filter, r);
    add(text, ga_iteration);
    gaWindow.append(text.toString());
    return scores;
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter) SearchResult(gdsc.smlm.search.SearchResult) FilterScore(gdsc.smlm.results.filter.FilterScore) FractionClassificationResult(gdsc.core.match.FractionClassificationResult)

Example 10 with FilterSet

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

the class BenchmarkFilterAnalysis method runAnalysis.

private void runAnalysis(List<FilterSet> filterSets, ComplexFilterScore optimum, double rangeReduction) {
    plots.clear();
    plots.ensureCapacity(plotTopN);
    bestFilter.clear();
    bestFilterOrder.clear();
    getCoordinateStore();
    filterAnalysisStopWatch = StopWatch.createStarted();
    IJ.showStatus("Analysing filters ...");
    int setNumber = 0;
    DirectFilter currentOptimum = (optimum != null) ? optimum.r.filter : null;
    for (FilterSet filterSet : filterSets) {
        setNumber++;
        if (filterAnalysis(filterSet, setNumber, currentOptimum, rangeReduction) < 0)
            break;
    }
    filterAnalysisStopWatch.stop();
    IJ.showProgress(1);
    IJ.showStatus("");
    final String timeString = filterAnalysisStopWatch.toString();
    IJ.log("Filter analysis time : " + timeString);
}
Also used : FilterSet(gdsc.smlm.results.filter.FilterSet) IDirectFilter(gdsc.smlm.results.filter.IDirectFilter) DirectFilter(gdsc.smlm.results.filter.DirectFilter)

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