use of uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate in project GDSC-SMLM by aherbert.
the class TcPalmAnalysis method createSelectionFilter.
/**
* Creates the selection filter to identify all cluster groups using a custom filter.
*
* @param roi the roi
* @param settings the settings
* @return the bi predicate
*/
private BiPredicate<ClusterData, Rectangle2D> createSelectionFilter(final Roi roi, final TcPalmAnalysisSettings settings) {
// Filter on time first as this is simple.
BiPredicate<ClusterData, Rectangle2D> test = null;
if (settings.getMinFrame() > minT) {
final int min = settings.getMinFrame();
test = (c, r) -> c.start >= min;
}
if (settings.getMaxFrame() < maxT) {
final int max = settings.getMaxFrame();
test = and(test, (c, r) -> c.end <= max);
}
// Add square bounds check
test = and(test, settings.getIntersects() ? ClusterData::intersects : ClusterData::isWithin);
// -- Check if the cluster is inside the ROI using a CoordinatePredicate
if (roi.getType() != Roi.RECTANGLE || roi.getCornerDiameter() != 0) {
final CoordinatePredicate pred = CoordinatePredicateUtils.createContainsPredicate(roi);
if (settings.getIntersects()) {
test = and(test, (c, r) -> c.intersects(pred, image::mapX, image::mapY));
} else {
test = and(test, (c, r) -> c.isWithin(pred, image::mapX, image::mapY));
}
}
return test;
}
use of uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate in project GDSC-SMLM by aherbert.
the class CropResults method roiCropResults.
private void roiCropResults() {
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);
final ImagePlus imp = WindowManager.getImage(settings.getRoiImage());
if (imp == null) {
IJ.error(TITLE, "No ROI image: " + settings.getRoiImage());
return;
}
final CoordinatePredicate roiTest = CoordinatePredicateUtils.createContainsPredicate(imp.getRoi());
if (roiTest == null) {
IJ.error(TITLE, "Not an area ROI");
return;
}
// Scale the results to the size of the image with the ROI
final int roiImageWidth = imp.getWidth();
final int roiImageHeight = imp.getHeight();
final double ox = integerBounds.getX();
final double oy = integerBounds.getY();
final double xscale = roiImageWidth / integerBounds.getWidth();
final double yscale = roiImageHeight / integerBounds.getHeight();
final Predicate<PeakResult> testZ = getZFilter();
results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (x, y, result) -> {
if (roiTest.test((x - ox) * xscale, (y - oy) * yscale) && testZ.test(result)) {
newResults.add(result);
}
});
if (settings.getPreserveBounds()) {
newResults.setBounds(integerBounds);
} else {
newResults.setBounds(null);
newResults.getBounds(true);
}
IJ.showStatus(newResults.size() + " Cropped localisations");
}
Aggregations