use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class PcPalmMolecules method cropToRoi.
private MemoryPeakResults cropToRoi(MemoryPeakResults results) {
final Rectangle bounds = results.getBounds(true);
settings.area = (bounds.width * bounds.height * results.getNmPerPixel() * results.getNmPerPixel()) / 1e6;
if (roiBounds == null) {
return results;
}
// Adjust bounds relative to input results image
final double xscale = (double) roiImageWidth / bounds.width;
final double yscale = (double) roiImageHeight / bounds.height;
final float minX = (float) Math.floor(roiBounds.x / xscale);
final float maxX = (float) Math.ceil((roiBounds.x + roiBounds.width) / xscale);
final float minY = (float) Math.floor(roiBounds.y / yscale);
final float maxY = (float) Math.ceil((roiBounds.y + roiBounds.height) / yscale);
// Update the area with the cropped region
settings.area *= (maxX - minX) / bounds.width;
settings.area *= (maxY - minY) / bounds.height;
// Create a new set of results within the bounds
final MemoryPeakResults newResults = new MemoryPeakResults();
newResults.begin();
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
newResults.add(result);
}
});
newResults.end();
newResults.copySettings(results);
newResults.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY)));
return newResults;
}
use of uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure in project GDSC-SMLM by aherbert.
the class PulseActivationAnalysis method drawLoop.
private void drawLoop(ImagePlus imp, Roi roi, int number) {
if (!roi.isArea()) {
return;
}
// Map the ROI to a crop of the results set
final Rectangle roiBounds = roi.getBounds();
final Rectangle resultsBounds = results.getBounds(true);
// @formatter:off
final Rectangle2D.Double r = new Rectangle2D.Double(resultsBounds.width * (double) roiBounds.x / imp.getWidth(), resultsBounds.height * (double) roiBounds.y / imp.getHeight(), // Since we output pixels map the width/height to the nearest pixel
Math.ceil(resultsBounds.width * (double) roiBounds.width / imp.getWidth()), Math.ceil(resultsBounds.height * (double) roiBounds.height / imp.getHeight()));
// @formatter:on
final double x = r.getX();
final double y = r.getY();
final int magnification = getMagnification();
// For each result set crop out the localisation and construct an overlay
final Overlay o = new Overlay();
for (int i = 0; i < output.length; i++) {
final Color color = Settings.colors[i];
// The first result is the memory results
final MemoryPeakResults localResults = (MemoryPeakResults) output[i].getOutput(0);
localResults.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
if (r.contains(xx, yy)) {
add(o, (xx - x) * magnification, (yy - y) * magnification, color);
}
});
}
// This results in a change of shape depending on where the roi is positioned
int width = (int) r.getWidth();
int height = (int) r.getHeight();
width *= magnification;
height *= magnification;
final ImageProcessor ip = new ByteProcessor(width, height);
final String loopTitle = imp.getTitle() + " Loop " + number;
imp = WindowManager.getImage(loopTitle);
if (imp == null) {
imp = new ImagePlus(loopTitle, ip);
imp.show();
} else {
imp.setProcessor(ip);
imp.getWindow().toFront();
}
imp.setOverlay(o);
}
Aggregations