use of uk.ac.sussex.gdsc.core.match.PointPair in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method addPointPairResult.
private void addPointPairResult(StringBuilder sb, Pulse p1, Pulse p2) {
addPoint(sb, p2);
final PointPair pair = new PointPair(p1, p2);
final double d = pair.getXyDistance();
if (d >= 0) {
sb.append(MathUtils.rounded(d, 4)).append('\t');
} else {
sb.append("-\t");
}
if (p1 != null && p2 != null) {
sb.append(MathUtils.rounded(p1.score(p2, d * d, settings.distanceThreshold), 4)).append('\t');
} else {
sb.append("-\t");
}
}
use of uk.ac.sussex.gdsc.core.match.PointPair in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method compareCoordinates.
@SuppressWarnings("null")
private void compareCoordinates(MemoryPeakResults results1, MemoryPeakResults results2, MemoryPeakResults results3, double distanceThreshold) {
final Pulse[] p1 = extractPulses(results1);
final Pulse[] p2 = extractPulses(results2);
final Pulse[] p3 = extractPulses(results3);
final List<Pulse> tp = null;
List<Pulse> fp = null;
List<Pulse> fn = null;
List<PointPair> pairs = null;
final List<Pulse> tp2 = null;
List<Pulse> fp2 = null;
List<Pulse> fn2 = null;
List<PointPair> pairs2 = null;
if (settings.showPairs) {
pairs = new LinkedList<>();
fp = new LinkedList<>();
fn = new LinkedList<>();
pairs2 = new LinkedList<>();
fp2 = new LinkedList<>();
fn2 = new LinkedList<>();
}
final MatchResult result = MatchCalculator.analyseResults2D(p1, p2, distanceThreshold, tp, fp, fn, pairs);
final MatchResult result2 = MatchCalculator.analyseResults2D(p1, p3, distanceThreshold, tp2, fp2, fn2, pairs2);
// Create output
Consumer<String> resultsOutput;
if (!java.awt.GraphicsEnvironment.isHeadless()) {
final TextWindow resultsWindow = ImageJUtils.refresh(resultsWindowRef, () -> new TextWindow(TITLE + " Results", createResultsHeader(), "", 900, 300));
resultsOutput = resultsWindow::append;
if (settings.showPairs) {
if (p3 == null) {
// Produce a pairs output
final WindowAndPainter wap = refresh(pairsWindowRef, true, resultsWindow, results1);
// Add the unmatched points
WindowManager.getIDList();
for (final Coordinate c : fn) {
pairs.add(new PointPair(c, null));
}
for (final Coordinate c : fp) {
pairs.add(new PointPair(null, c));
}
final List<? extends PointPair> sortedPairs = sort(pairs);
for (final PointPair pair : sortedPairs) {
addPairResult(wap.textWindow, pair);
}
} else {
// Produce a triple output
final WindowAndPainter wap = refresh(triplesWindowRef, false, resultsWindow, results1);
final HashMap<Pulse, Triple> map = new HashMap<>();
final ArrayList<Triple> triples = new ArrayList<>(pairs.size());
for (final PointPair pair : pairs) {
final Pulse p = (Pulse) pair.getPoint1();
final Triple t = new Triple(p, (Pulse) pair.getPoint2(), null);
triples.add(t);
map.put(p, t);
}
// Complete the reference set of points
for (final Coordinate c : fn) {
final Pulse p = (Pulse) c;
final Triple t = new Triple(p, null, null);
triples.add(t);
map.put(p, t);
}
// Add the unmatched points
for (final Coordinate c : fp) {
triples.add(new Triple(null, (Pulse) c, null));
}
for (final Coordinate c : fp2) {
triples.add(new Triple(null, null, (Pulse) c));
}
// Add the results from the second match
for (final PointPair pair : pairs2) {
final Pulse p = (Pulse) pair.getPoint1();
final Pulse pp = (Pulse) pair.getPoint2();
final Triple triple = map.get(p);
if (triple != null) {
triple.p3 = pp;
} else {
triples.add(new Triple(null, null, pp));
}
}
final List<? extends Triple> sortedTriples = sort(triples);
for (final Triple t : sortedTriples) {
addTripleResult(wap.textWindow, t);
}
}
}
} else {
if (writeHeader.compareAndSet(true, false)) {
IJ.log(createResultsHeader());
}
resultsOutput = IJ::log;
}
final StringBuilder sb = new StringBuilder();
addResult(resultsOutput, sb, settings.inputOption1, settings.inputOption2, distanceThreshold, result);
if (p3 != null) {
addResult(resultsOutput, sb, settings.inputOption1, settings.inputOption3, distanceThreshold, result2);
}
}
use of uk.ac.sussex.gdsc.core.match.PointPair in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method savePairs.
private void savePairs(MemoryPeakResults results1, MemoryPeakResults results2, List<PointPair> allMatches) {
if (!settings.savePairs) {
return;
}
// Get the directory
final String directory = ImageJUtils.getDirectory("Pairs_directory", settings.pairsDirectory);
if (directory == null) {
return;
}
settings.pairsDirectory = directory;
final double[] distanceThresholds = getDistances(settings.distanceThreshold, settings.increments, settings.delta);
// Create output files for each distance band
final PeakResults[] output1 = new PeakResults[distanceThresholds.length];
final PeakResults[] output2 = new PeakResults[distanceThresholds.length];
double high = 0;
for (int i = 0; i < distanceThresholds.length; i++) {
final double low = high;
high = distanceThresholds[i];
output1[i] = createFilePeakResults(directory, 1, results1, low, high);
output2[i] = createFilePeakResults(directory, 2, results2, low, high);
}
// Square the thresholds
SimpleArrayUtils.apply(distanceThresholds, v -> v * v);
final double[] pairDistances = getPairDistances(allMatches);
int index = 0;
for (final PointPair pair : allMatches) {
final int insert = search(distanceThresholds, pairDistances[index++]);
if (insert != -1) {
final PeakResult r1 = ((PeakResultPoint) pair.getPoint1()).getPeakResult();
final PeakResult r2 = ((PeakResultPoint) pair.getPoint2()).getPeakResult();
output1[insert].add(r1);
output2[insert].add(r2);
}
}
for (int i = 0; i < output1.length; i++) {
output1[i].end();
output2[i].end();
}
}
use of uk.ac.sussex.gdsc.core.match.PointPair in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method showPairs.
/**
* Show the match pairs in a results table.
*
* <p>Adds an ROI painter for the original image source of results set 1 (if it is visible) to the
* table.
*
* @param results1 the first set of results
* @param pairs the pairs
* @param resultsWindow the results window
*/
private void showPairs(MemoryPeakResults results1, final List<PointPair> pairs, final TextWindow resultsWindow) {
if (!settings.showPairs) {
return;
}
final TextWindow pairsWindow = createPairsWindow(resultsWindow, results1.getSource());
pairsWindow.getTextPanel().clear();
final Ticker ticker = ImageJUtils.createTicker(pairs.size(), 0, "Writing pairs table");
try (final BufferedTextWindow bw = new BufferedTextWindow(pairsWindow)) {
final StringBuilder sb = new StringBuilder();
for (final PointPair pair : pairs) {
bw.append(addPairResult(sb, pair));
ticker.tick();
}
}
ImageJUtils.finished();
}
use of uk.ac.sussex.gdsc.core.match.PointPair in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method getPairDistances.
private static double[] getPairDistances(List<PointPair> pairs) {
final double[] d = new double[pairs.size()];
int index = 0;
for (final PointPair pair : pairs) {
d[index++] = pair.getXyDistanceSquared();
}
return d;
}
Aggregations