use of uk.ac.sussex.gdsc.smlm.results.filter.DirectFilter in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method findOptimum.
@Nullable
@Override
public SearchResult<FilterScore> findOptimum(double[][] points) {
gaIteration++;
SimpleFilterScore max = filterScoreOptimum;
final FilterScoreResult[] scoreResults = scoreFilters(setStrength(new FilterSet(searchSpaceToFilters(points))), false);
if (scoreResults == null) {
return null;
}
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;
}
}
filterScoreOptimum = 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
final DirectFilter filter = max.result.filter;
final FractionClassificationResult r = scoreFilter(filter, defaultMinimalFilter, gaResultsList, coordinateStore);
final StringBuilder text = createResult(filter, r);
add(text, gaIteration);
gaWindow.accept(text.toString());
return new SearchResult<>(filter.getParameters(), max);
}
use of uk.ac.sussex.gdsc.smlm.results.filter.DirectFilter in project GDSC-SMLM by aherbert.
the class PeakFit method configureSmartFilter.
/**
* Show a dialog to configure the smart filter.
*
* <p>If the fit configuration isSmartFilter is not enabled then this method returns true. If it
* is enabled then a dialog is shown to input the configuration for a smart filter. If no valid
* filter can be created from the input then the method returns false.
*
* <p>Note: If the smart filter is successfully configured then the user may want to disable the
* standard fit validation.
*
* @param fitConfig the fit config
* @return true, if successful
*/
public static boolean configureSmartFilter(final FitConfiguration fitConfig) {
if (!fitConfig.isSmartFilter()) {
return true;
}
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
String xml = fitConfig.getSmartFilterString();
if (TextUtils.isNullOrEmpty(xml)) {
xml = fitConfig.getDefaultSmartFilterXml();
}
gd.addMessage("Smart filter (used to pick optimum results during fitting)");
gd.addTextAreas(uk.ac.sussex.gdsc.core.utils.XmlUtils.convertQuotes(xml), null, 8, 60);
// Add message about precision filtering
gd.addMessage(TextUtils.wrap("Note: Smart filters using precision may require a local background level. " + "Ensure the camera calibration is correct including any bias.", 80));
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
xml = gd.getNextText();
final Filter f = Filter.fromXml(xml);
if (!(f instanceof DirectFilter)) {
return false;
}
fitConfig.setDirectFilter((DirectFilter) f);
return true;
}
use of uk.ac.sussex.gdsc.smlm.results.filter.DirectFilter in project GDSC-SMLM by aherbert.
the class FitConfiguration method updateFilterSettings.
private void updateFilterSettings() {
updateMinSignal();
updatePrecisionThreshold();
updateCoordinateShift();
updateWidthThreshold();
updateMinWidthThreshold();
updateZFilter();
// Recreate the smart filter
if (!filterSettings.getSmartFilter()) {
return;
}
final String xml = filterSettings.getSmartFilterString();
if (TextUtils.isNullOrEmpty(xml)) {
return;
}
final Filter f = Filter.fromXml(xml);
if (f == null || !(f instanceof DirectFilter)) {
// Throw to ensure the filter is OK
throw new IllegalStateException("Unrecognised smart filter: " + xml);
// or
// setDirectFilter(null);
}
// This updates the SmartFilter flag and the SmartFilterString.
// Just set the filter directly
// setDirectFilter((DirectFilter) f);
this.directFilter = (DirectFilter) f;
}
Aggregations