use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class TraceFilter method setup.
@Override
public void setup(MemoryPeakResults peakResults) {
ok = new HashSet<PeakResult>();
// Trace molecules. Anything that is part of a trace is OK
TraceManager tm = new TraceManager(peakResults);
tm.traceMolecules(d, t);
Trace[] traces = tm.getTraces();
for (Trace trace : traces) {
if (trace.size() > 1) {
for (PeakResult result : trace.getPoints()) {
ok.add(result);
}
}
}
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class Filter method filter2.
/**
* 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.
* <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 #filter(MemoryPeakResults, int)}
*
* @param results
* @param failures
* the number of failures to allow per frame before all peaks are rejected
* @return the filtered results
*/
public MemoryPeakResults filter2(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;
}
failCount += peak.origY;
// 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;
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class Filter method filterSubset.
/**
* 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>
* 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 filterSubset(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;
}
// 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;
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class ResultsManagerTest method checkEqual.
private void checkEqual(Spot[] spots, int channel, int slice, int position, int type, MemoryPeakResults actualResults) throws ArrayComparisonFailure {
Assert.assertNotNull("Input results are null", actualResults);
MemoryPeakResults expectedResults = extract(spots, channel, slice, position, type);
Assert.assertEquals("Size differ", expectedResults.size(), actualResults.size());
final float delta = 0;
List<PeakResult> expected = expectedResults.getResults();
List<PeakResult> actual = actualResults.getResults();
for (int i = 0; i < actualResults.size(); i++) {
PeakResult p1 = expected.get(i);
PeakResult p2 = actual.get(i);
Assert.assertEquals("Peak mismatch @ " + i, p1.getFrame(), p2.getFrame());
Assert.assertEquals("Orig X mismatch @ " + i, p1.origX, p2.origX);
Assert.assertEquals("Orig Y mismatch @ " + i, p1.origY, p2.origY);
Assert.assertEquals("Orig value mismatch @ " + i, p1.origValue, p2.origValue, delta);
Assert.assertEquals("Error mismatch @ " + i, p1.error, p2.error, 1e-6);
Assert.assertEquals("Noise mismatch @ " + i, p1.noise, p2.noise, delta);
Assert.assertNotNull("Params is null @ " + i, p2.params);
Assert.assertEquals("Background mismatch @ " + i, p1.getBackground(), p2.getBackground(), delta);
Assert.assertEquals("Signal mismatch @ " + i, p1.getSignal(), p2.getSignal(), delta);
Assert.assertEquals("XPosition mismatch @ " + i, p1.getXPosition(), p2.getXPosition(), delta);
Assert.assertEquals("YPosition mismatch @ " + i, p1.getYPosition(), p2.getYPosition(), delta);
Assert.assertEquals("XSD mismatch @ " + i, p1.getXSD(), p2.getXSD(), 1e-6);
Assert.assertEquals("YSD mismatch @ " + i, p1.getYSD(), p2.getYSD(), 1e-6);
Assert.assertEquals("ID mismatch @ " + i, p1.getId(), p2.getId());
}
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class FIRE method cropToRoi.
private MemoryPeakResults cropToRoi(MemoryPeakResults results) {
if (roiBounds == null)
return results;
// Adjust bounds relative to input results image
//Rectangle2D.Float bounds = results.getDataBounds();
Rectangle bounds = results.getBounds(true);
double xscale = roiImageWidth / bounds.width;
double yscale = roiImageHeight / bounds.height;
float minX = (float) (bounds.x + roiBounds.x / xscale);
float maxX = (float) (minX + roiBounds.width / xscale);
float minY = (float) (bounds.y + (roiBounds.y / yscale));
float maxY = (float) (minY + roiBounds.height / yscale);
// Create a new set of results within the bounds
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.begin();
for (PeakResult peakResult : results.getResults()) {
float x = peakResult.params[Gaussian2DFunction.X_POSITION];
float y = peakResult.params[Gaussian2DFunction.Y_POSITION];
if (x < minX || x > maxX || y < minY || y > maxY)
continue;
newResults.add(peakResult);
}
newResults.end();
newResults.copySettings(results);
newResults.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)));
return newResults;
}
Aggregations