use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceDiffusion method showMultiDialog.
private boolean showMultiDialog(ArrayList<MemoryPeakResults> allResults) {
multiMode = true;
// Show a list box containing all the results. This should remember the last set of chosen items.
MultiDialog md = new MultiDialog(TITLE, new MultiDialog.MemoryResultsItems());
md.addSelected(selected);
md.showDialog();
if (md.wasCanceled())
return false;
selected = md.getSelectedResults();
if (selected.isEmpty()) {
IJ.error(TITLE, "No results were selected");
return false;
}
for (String name : selected) {
MemoryPeakResults r = MemoryPeakResults.getResults(name);
if (r != null)
allResults.add(r);
}
if (allResults.isEmpty())
return false;
// Check calibration exists for the first set of results
if (!checkCalibration(allResults.get(0)))
return false;
// Check the calibration is the same for the rest
Calibration cal = allResults.get(0).getCalibration();
final double nmPerPixel = cal.getNmPerPixel();
final double exposureTime = cal.getExposureTime();
for (int i = 1; i < allResults.size(); i++) {
MemoryPeakResults results = allResults.get(1);
if (results.getCalibration() == null || results.getCalibration().getExposureTime() != exposureTime || results.getNmPerPixel() != nmPerPixel) {
IJ.error(TITLE, "The exposure time and pixel pitch must match across all the results");
return false;
}
}
return true;
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class TraceDiffusion method showTraceDialog.
private boolean showTraceDialog(ArrayList<MemoryPeakResults> allResults) {
ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
if (!multiMode)
ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
globalSettings = SettingsManager.loadSettings();
settings = globalSettings.getClusteringSettings();
gd.addNumericField("Distance_Threshold (nm)", settings.distanceThreshold, 0);
gd.addNumericField("Distance_Exclusion (nm)", settings.distanceExclusion, 0);
gd.addSlider("Min_trace_length", 2, 20, settings.minimumTraceLength);
gd.addCheckbox("Ignore_ends", settings.ignoreEnds);
gd.addCheckbox("Save_traces", settings.saveTraces);
gd.showDialog();
if (gd.wasCanceled() || !readTraceDialog(gd))
return false;
// Update the settings
SettingsManager.saveSettings(globalSettings);
// Load the results
if (!multiMode) {
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, true);
if (results == null || results.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return false;
}
if (!checkCalibration(results))
return false;
allResults.add(results);
}
return true;
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
if (!showDialog())
return;
// Load the results
MemoryPeakResults results1 = ResultsManager.loadInputResults(inputOption1, false);
MemoryPeakResults results2 = ResultsManager.loadInputResults(inputOption2, false);
if (results1 == null || results1.size() == 0 || results2 == null || results2.size() == 0) {
IJ.error(TITLE, "No results could be loaded");
IJ.showStatus("");
return;
}
final long start = System.nanoTime();
compareCoordinates(results1, results2, dThreshold, increments, delta);
double seconds = (System.nanoTime() - start) / 1000000000.0;
IJ.showStatus(String.format("%s = %ss", TITLE, Utils.rounded(seconds, 4)));
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class PeakFit method runMaximaFitting.
/**
* Load the selected results from memory. All multiple frame results are added directly to the results. All single
* frame
* results are added to a list of candidate maxima per frame and fitted using the configured parameters.
*/
private void runMaximaFitting() {
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() == 0) {
log("No results for maxima fitting");
return;
}
// No check for imageSource since this has been check in the calling method
int totalFrames = source.getFrames();
// Store the indices of each new time-frame
results.sort();
List<PeakResult> candidateMaxima = results.getResults();
// Use the FitEngine to allow multi-threading.
FitEngine engine = createFitEngine(getNumberOfThreads(totalFrames));
final int step = Utils.getProgressInterval(totalFrames);
runTime = System.nanoTime();
boolean shutdown = false;
int slice = candidateMaxima.get(0).getFrame();
ArrayList<PeakResult> sliceCandidates = new ArrayList<PeakResult>();
Iterator<PeakResult> iter = candidateMaxima.iterator();
while (iter.hasNext()) {
PeakResult r = iter.next();
if (slice != r.getFrame()) {
if (escapePressed()) {
shutdown = true;
break;
}
if (slice % step == 0) {
if (Utils.showStatus("Slice: " + slice + " / " + totalFrames))
IJ.showProgress(slice, totalFrames);
}
// Process results
if (!processResults(engine, sliceCandidates, slice))
break;
sliceCandidates.clear();
}
slice = r.getFrame();
sliceCandidates.add(r);
}
// Process final results
if (!shutdown)
processResults(engine, sliceCandidates, slice);
engine.end(shutdown);
time = engine.getTime();
runTime = System.nanoTime() - runTime;
showResults();
source.close();
}
use of gdsc.smlm.results.MemoryPeakResults in project GDSC-SMLM by aherbert.
the class Filter method fractionScoreSubset.
/**
* 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.
* <p>
* Note that this method is to be used to score a subset that was generated using
* {@link #filterSubset(MemoryPeakResults, int)} since the number of consecutive failures before each peak are
* expected to be stored in the origX property.
*
* @param resultsList
* a list of results to analyse
* @param failures
* the number of failures to allow per frame before all peaks are rejected
* @param tn
* The initial true negatives (used when the results have been pre-filtered)
* @param fn
* The initial false negatives (used when the results have been pre-filtered)
* @param n
* The initial negatives (used when the results have been pre-filtered)
* @return the score
*/
public FractionClassificationResult fractionScoreSubset(List<MemoryPeakResults> resultsList, int failures, double tn, double fn, int n) {
int p = 0;
double fp = 0;
double tp = 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;
}
failCount += peak.origX;
// 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);
}
Aggregations