use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class FilterResults method filterResults.
/**
* Apply the filters to the data
*/
private void filterResults() {
checkLimits();
MemoryPeakResults newResults = new MemoryPeakResults();
newResults.copySettings(results);
newResults.setName(results.getName() + " Filtered");
// Initialise the mask
ByteProcessor mask = getMask(filterSettings.maskTitle);
MaskDistribution maskFilter = null;
final float centreX = results.getBounds().width / 2.0f;
final float centreY = results.getBounds().height / 2.0f;
if (mask != null) {
double scaleX = (double) results.getBounds().width / mask.getWidth();
double scaleY = (double) results.getBounds().height / mask.getHeight();
maskFilter = new MaskDistribution((byte[]) mask.getPixels(), mask.getWidth(), mask.getHeight(), 0, scaleX, scaleY);
}
int i = 0;
final int size = results.size();
final double maxVariance = filterSettings.maxPrecision * filterSettings.maxPrecision;
for (PeakResult result : results.getResults()) {
if (i % 64 == 0)
IJ.showProgress(i, size);
if (getDrift(result) > filterSettings.maxDrift)
continue;
if (result.getSignal() < filterSettings.minSignal)
continue;
if (getSNR(result) < filterSettings.minSNR)
continue;
if (getVariance(result) > maxVariance)
continue;
final float width = getWidth(result);
if (width < filterSettings.minWidth || width > filterSettings.maxWidth)
continue;
if (maskFilter != null) {
// Check the coordinates are inside the mask
double[] xy = new double[] { result.getXPosition() - centreX, result.getYPosition() - centreY };
if (!maskFilter.isWithinXY(xy))
continue;
}
// Passed all filters. Add to the results
newResults.add(result);
}
IJ.showProgress(1);
IJ.showStatus(newResults.size() + " Filtered localisations");
MemoryPeakResults.addResults(newResults);
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class FilterResults method analyseResults.
/**
* Analyse the results and determine the range for each filter
*/
private void analyseResults() {
IJ.showStatus("Analysing results ...");
nmPerPixel = results.getNmPerPixel();
gain = results.getGain();
emCCD = results.isEMCCD();
double maxVariance = maxPrecision * maxPrecision;
double minVariance = minPrecision * minPrecision;
int size = results.size();
int i = 0;
for (PeakResult result : results.getResults()) {
if (i % 64 == 0)
IJ.showProgress(i, size);
final float drift = getDrift(result);
if (maxDrift < drift)
maxDrift = drift;
if (minDrift > drift)
minDrift = drift;
final float signal = result.getSignal();
if (maxSignal < signal)
maxSignal = signal;
if (minSignal > signal)
minSignal = signal;
final float snr = getSNR(result);
if (maxSNR < snr)
maxSNR = snr;
if (minSNR > snr)
minSNR = snr;
// Use variance to avoid sqrt()
final double variance = getVariance(result);
if (maxVariance < variance)
maxVariance = variance;
if (minVariance > variance)
minVariance = variance;
final float width = getWidth(result);
averageWidth += width;
if (maxWidth < width)
maxWidth = width;
if (minWidth > width)
minWidth = width;
}
averageWidth /= results.size();
maxPrecision = Math.sqrt(maxVariance);
minPrecision = Math.sqrt(minVariance);
IJ.showProgress(1);
IJ.showStatus("");
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class LoadLocalisations method getZDepth.
private boolean getZDepth(MemoryPeakResults results) {
// The z-depth is stored in pixels in the error field
double min = results.getHead().error;
double max = min;
for (PeakResult peak : results.getResults()) {
if (min > peak.error)
min = peak.error;
else if (max < peak.error)
max = peak.error;
}
// No z-depth
if (min == max && min == 0)
return true;
maxz = FastMath.min(maxz, max);
minz = FastMath.max(minz, min);
// Display in nm
final double pp = results.getNmPerPixel();
min *= pp;
max *= pp;
String msg = String.format("%d localisations with %.2f <= z <= %.2f", results.size(), min, max);
min = Math.floor(min);
max = Math.ceil(max);
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage(msg);
gd.addCheckbox("Limit Z-depth", limitZ);
gd.addSlider("minZ", min, max, minz * pp);
gd.addSlider("maxZ", min, max, maxz * pp);
gd.showDialog();
if (gd.wasCanceled() || gd.invalidNumber()) {
return false;
}
myLimitZ = limitZ = gd.getNextBoolean();
minz = gd.getNextNumber() / pp;
maxz = gd.getNextNumber() / pp;
return true;
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class FIRE method canCalculatePrecision.
private boolean canCalculatePrecision(MemoryPeakResults results) {
// Calibration is required to compute the precision
Calibration cal = results.getCalibration();
if (cal == null)
return false;
if (!cal.hasNmPerPixel() || !cal.hasGain() || !cal.hasEMCCD())
return false;
// Check all have a width and signal
PeakResult[] data = results.toArray();
for (int i = 0; i < data.length; i++) {
PeakResult p = data[i];
if (p.getSD() <= 0 || p.getSignal() <= 0)
return true;
}
// Check for variable width that is not 1 and a variable signal
for (int i = 0; i < data.length; i++) {
PeakResult p = data[i];
// Check this is valid
if (p.getSD() != 1) {
// Check the rest for a different value
float w1 = p.getSD();
float s1 = p.getSignal();
for (int j = i + 1; j < data.length; j++) {
PeakResult p2 = data[j];
if (p2.getSD() != 1 && p2.getSD() != w1 && p2.getSignal() != s1)
return true;
}
// All the results are the same, this is not valid
break;
}
}
return false;
}
use of gdsc.smlm.results.PeakResult in project GDSC-SMLM by aherbert.
the class HysteresisFilter method getSearchDistanceUsingCandidates.
/**
* Find average precision of the candidates and use it for the search
* distance
*
* @param peakResults
* @param candidates
* @return
*/
private double getSearchDistanceUsingCandidates(MemoryPeakResults peakResults, LinkedList<PeakResult> candidates) {
SummaryStatistics stats = new SummaryStatistics();
final double nmPerPixel = peakResults.getNmPerPixel();
final double gain = peakResults.getGain();
final boolean emCCD = peakResults.isEMCCD();
for (PeakResult peakResult : candidates) {
stats.addValue(peakResult.getPrecision(nmPerPixel, gain, emCCD));
}
double distanceThreshold = stats.getMean() * searchDistance / nmPerPixel;
return distanceThreshold;
}
Aggregations