use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class TraceExporter method exportSpotOn.
private void exportSpotOn(MemoryPeakResults results) {
try (BufferedWriter out = Files.newBufferedWriter(Paths.get(settings.directory, results.getName() + ".csv"))) {
out.write("frame,t,trajectory,x,y");
out.newLine();
final TypeConverter<TimeUnit> converter = UnitConverterUtils.createConverter(TimeUnit.FRAME, TimeUnit.SECOND, results.getCalibrationReader().getExposureTime());
@SuppressWarnings("resource") final BufferedWriter writer = out;
results.forEach(DistanceUnit.UM, (XyrResultProcedure) (x, y, result) -> {
try {
if (result.hasEndFrame()) {
final String sId = Integer.toString(result.getId());
final String sx = Float.toString(x);
final String sy = Float.toString(y);
for (int t = result.getFrame(); t <= result.getEndFrame(); t++) {
writer.write(Integer.toString(t));
writer.write(",");
writer.write(Float.toString(converter.convert(t)));
writer.write(",");
writer.write(sId);
writer.write(",");
writer.write(sx);
writer.write(",");
writer.write(sy);
writer.newLine();
}
} else {
writer.write(Integer.toString(result.getFrame()));
writer.write(",");
writer.write(Float.toString(converter.convert(result.getFrame())));
writer.write(",");
writer.write(Integer.toString(result.getId()));
writer.write(",");
writer.write(Float.toString(x));
writer.write(",");
writer.write(Float.toString(y));
writer.newLine();
}
} catch (final IOException ex) {
throw new RuntimeException(ex);
}
});
} catch (final IOException | RuntimeException ex) {
handleException(ex);
}
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method extractPulses.
@Nullable
private static Pulse[] extractPulses(MemoryPeakResults results) {
if (results == null) {
return null;
}
final Pulse[] pulses = new Pulse[results.size()];
final Counter i = new Counter();
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> pulses[i.getAndIncrement()] = new Pulse(x, y, result.getFrame(), result.getEndFrame()));
return pulses;
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class SpotAnalysis method addCandidateFrames.
private void addCandidateFrames(String title) {
for (final MemoryPeakResults r : MemoryPeakResults.getAllResults()) {
if (r.getSource() instanceof IJImageSource && r.getSource().getName().equals(title)) {
final float minx = areaBounds.x;
final float maxx = minx + areaBounds.width;
final float miny = areaBounds.y;
final float maxy = miny + areaBounds.height;
r.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
if (result.getXPosition() >= minx && result.getXPosition() <= maxx && result.getYPosition() >= miny && result.getYPosition() <= maxy) {
candidateFrames.add(result.getFrame());
}
});
}
}
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class DriftCalculator method findSpots.
private static Spot[] findSpots(MemoryPeakResults results, Rectangle bounds, int[] limits) {
final LocalList<Spot> list = new LocalList<>(limits[1] - limits[0] + 1);
final float minx = bounds.x;
final float miny = bounds.y;
final float maxx = (float) bounds.x + bounds.width;
final float maxy = (float) bounds.y + bounds.height;
// Find spots within the ROI
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
if (x > minx && x < maxx && y > miny && y < maxy) {
list.add(new Spot(result.getFrame(), x, y, result.getIntensity()));
}
});
// For each frame pick the strongest spot
Collections.sort(list, Spot::compare);
final LocalList<Spot> newList = new LocalList<>(list.size());
int currentT = -1;
for (final Spot spot : list) {
if (currentT != spot.time) {
newList.add(spot);
currentT = spot.time;
}
}
return newList.toArray(new Spot[0]);
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class CropResults method cropResults.
/**
* Apply the filters to the data.
*/
private void cropResults() {
final MemoryPeakResults newResults = createNewResults();
// These bounds are integer. But this is because the results are meant to come from an image.
final Rectangle integerBounds = results.getBounds(true);
// The crop bounds can be floating point...
// Border
final double border = settings.getBorder();
final double xx = integerBounds.x + border;
final double yy = integerBounds.y + border;
final double w = Math.max(0, integerBounds.width - 2 * border);
final double h = Math.max(0, integerBounds.height - 2 * border);
Rectangle2D pixelBounds = new Rectangle2D.Double(xx, yy, w, h);
// Bounding box
if (settings.getSelectRegion()) {
final Rectangle2D boxBounds = new Rectangle2D.Double(settings.getX(), settings.getY(), settings.getWidth(), settings.getHeight());
pixelBounds = pixelBounds.createIntersection(boxBounds);
}
// and create another intersection
if (myUseRoi) {
final ImagePlus imp = WindowManager.getImage(settings.getRoiImage());
if (imp != null && imp.getRoi() != null) {
final Rectangle roi = imp.getRoi().getBounds();
final int roiImageWidth = imp.getWidth();
final int roiImageHeight = imp.getHeight();
final double xscale = (double) roiImageWidth / integerBounds.width;
final double yscale = (double) roiImageHeight / integerBounds.height;
final Rectangle2D roiBounds = new Rectangle2D.Double(roi.x / xscale, roi.y / yscale, roi.width / xscale, roi.height / yscale);
pixelBounds = pixelBounds.createIntersection(roiBounds);
}
}
final Rectangle2D bounds = pixelBounds;
final Predicate<PeakResult> testZ = getZFilter();
// Copy the results if the origin is reset
final Consumer<PeakResult> consumer = settings.getResetOrigin() ? r -> newResults.add(r.copy()) : newResults::add;
if (bounds.getWidth() > 0 && bounds.getHeight() > 0) {
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
if (bounds.contains(x, y) && testZ.test(result)) {
consumer.accept(result);
}
});
}
if (settings.getPreserveBounds()) {
newResults.setBounds(integerBounds);
} else {
// Get the lower and upper integer limits
final int x = (int) Math.floor(bounds.getX());
final int y = (int) Math.floor(bounds.getY());
final int ux = (int) Math.ceil(bounds.getX() + bounds.getWidth());
final int uy = (int) Math.ceil(bounds.getY() + bounds.getHeight());
// Ensure the width and height are at least 1
newResults.setBounds(new Rectangle(x, y, Math.max(1, ux - x), Math.max(1, uy - y)));
if (settings.getResetOrigin()) {
newResults.translate(-x, -y);
}
}
IJ.showStatus(newResults.size() + " Cropped localisations");
}
Aggregations