use of uk.ac.sussex.gdsc.smlm.ij.plugins.PsfSpot in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method getSimulationCoordinates.
/**
* Gets the coordinates for the current simulation. This extract all the results in memory into a
* list per frame and is cached for the simulation Id.
*
* @return the coordinates
*/
private TIntObjectHashMap<PsfSpot[]> getSimulationCoordinates() {
Pair<Integer, TIntObjectHashMap<PsfSpot[]>> coords = coordinateCache.get();
if (coords.getKey() != simulationParameters.id) {
// Always use float coordinates.
// The Worker adds a pixel offset for the spot coordinates.
final TIntObjectHashMap<List<Coordinate>> coordinates = ResultsMatchCalculator.getCoordinates(results, false);
// Spot PSFs may overlap so we must determine the amount of signal overlap and amplitude
// effect for each spot...
final int nThreads = Prefs.getThreads();
final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<>(nThreads * 2);
final List<OverlapWorker> workers = new LinkedList<>();
final List<Thread> threads = new LinkedList<>();
final Ticker overlapTicker = ImageJUtils.createTicker(coordinates.size(), nThreads, "Computing PSF overlap ...");
for (int i = 0; i < nThreads; i++) {
final OverlapWorker worker = new OverlapWorker(jobs, coordinates, overlapTicker);
final Thread t = new Thread(worker);
workers.add(worker);
threads.add(t);
t.start();
}
// Process the frames
coordinates.forEachKey(value -> {
put(jobs, value);
return true;
});
// Finish all the worker threads by passing in a null job
for (int i = 0; i < threads.size(); i++) {
put(jobs, -1);
}
// Wait for all to finish
final TIntObjectHashMap<PsfSpot[]> actualCoordinates = new TIntObjectHashMap<>();
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).join();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new ConcurrentRuntimeException("Unexpected interrupt", ex);
}
actualCoordinates.putAll(workers.get(i).coordinates);
}
threads.clear();
// For testing
final SimpleRegression regression = new SimpleRegression(false);
for (final PsfSpot[] spots : actualCoordinates.valueCollection()) {
for (final PsfSpot spot : spots) {
regression.addData(spot.getAmplitude(), calculator.getAmplitude(spot.getPeakResult().getParameters()));
}
}
ImageJUtils.log("PixelAmplitude vs Amplitude = %f, slope=%f, n=%d", regression.getR(), regression.getSlope(), regression.getN());
ImageJUtils.finished();
coords = Pair.of(simulationParameters.id, actualCoordinates);
coordinateCache.set(coords);
}
return coords.getRight();
}
use of uk.ac.sussex.gdsc.smlm.ij.plugins.PsfSpot in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method showOverlay.
@SuppressWarnings("null")
private void showOverlay(ImagePlus imp, BenchmarkSpotFilterResult filterResult) {
final Overlay o = new Overlay();
filterResult.filterResults.forEachValue(result -> {
final int size = result.spots.length;
float[] tx = null;
float[] ty = null;
float[] fx = null;
float[] fy = null;
if (settings.showTP) {
tx = new float[size];
ty = new float[size];
}
if (settings.showFP) {
fx = new float[size];
fy = new float[size];
}
int tc = 0;
int fc = 0;
for (final ScoredSpot s : result.spots) {
if (s.match) {
if (settings.showTP) {
tx[tc] = s.spot.x + 0.5f;
ty[tc++] = s.spot.y + 0.5f;
}
} else if (settings.showFP) {
fx[fc] = s.spot.x + 0.5f;
fy[fc++] = s.spot.y + 0.5f;
}
}
if (settings.showTP) {
SpotFinderPreview.addRoi(result.frame, o, tx, ty, tc, Color.green);
}
if (settings.showFP) {
SpotFinderPreview.addRoi(result.frame, o, fx, fy, fc, Color.red);
}
if (settings.showFN) {
// We need the FN ...
final PsfSpot[] actual = result.actual;
final boolean[] actualAssignment = result.actualAssignment;
final float[] nx = new float[actual.length];
final float[] ny = new float[actual.length];
int npoints = 0;
for (int i = 0; i < actual.length; i++) {
if (!actualAssignment[i]) {
nx[npoints] = actual[i].getX();
ny[npoints++] = actual[i].getY();
}
}
SpotFinderPreview.addRoi(result.frame, o, nx, ny, npoints, Color.yellow);
}
return true;
});
imp.setOverlay(o);
}
Aggregations