Search in sources :

Example 1 with CoordinatePredicate

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;
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) IntUnaryOperator(java.util.function.IntUnaryOperator) Rectangle2D(java.awt.geom.Rectangle2D) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) IdFramePeakResultComparator(uk.ac.sussex.gdsc.smlm.results.sort.IdFramePeakResultComparator) UnaryOperator(java.util.function.UnaryOperator) Hull(uk.ac.sussex.gdsc.core.math.hull.Hull) TableCellRenderer(javax.swing.table.TableCellRenderer) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) FloatUnaryOperator(uk.ac.sussex.gdsc.core.utils.function.FloatUnaryOperator) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) RoiManager(ij.plugin.frame.RoiManager) RowSorter(javax.swing.RowSorter) SoftLock(uk.ac.sussex.gdsc.core.utils.SoftLock) JFrame(javax.swing.JFrame) LutHelper(uk.ac.sussex.gdsc.core.ij.process.LutHelper) KeyStroke(javax.swing.KeyStroke) TableModelEvent(javax.swing.event.TableModelEvent) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) Component(java.awt.Component) Hull2d(uk.ac.sussex.gdsc.core.math.hull.Hull2d) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) Executors(java.util.concurrent.Executors) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) ImagePlus(ij.ImagePlus) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) ToDoubleFunction(java.util.function.ToDoubleFunction) TcPalmAnalysisSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.TcPalmAnalysisSettings) FileUtils(uk.ac.sussex.gdsc.core.utils.FileUtils) PlugIn(ij.plugin.PlugIn) ListSelectionModel(javax.swing.ListSelectionModel) ActionListener(java.awt.event.ActionListener) PolygonRoi(ij.gui.PolygonRoi) StoredData(uk.ac.sussex.gdsc.core.utils.StoredData) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) WindowManager(ij.WindowManager) ConvexHull2d(uk.ac.sussex.gdsc.core.math.hull.ConvexHull2d) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PointRoi(ij.gui.PointRoi) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) GenericDialog(ij.gui.GenericDialog) AbstractTableModel(javax.swing.table.AbstractTableModel) SortUtils(uk.ac.sussex.gdsc.core.utils.SortUtils) RounderUtils(uk.ac.sussex.gdsc.core.data.utils.RounderUtils) Overlay(ij.gui.Overlay) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Window(java.awt.Window) IOException(java.io.IOException) JScrollPane(javax.swing.JScrollPane) RoiListener(ij.gui.RoiListener) Paths(java.nio.file.Paths) ConcurrentMonoStack(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrentMonoStack) ListSelectionListener(javax.swing.event.ListSelectionListener) TIntArrayList(gnu.trove.list.array.TIntArrayList) IdentityTypeConverter(uk.ac.sussex.gdsc.core.data.utils.IdentityTypeConverter) Point(java.awt.Point) CoordinatePredicateUtils(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicateUtils) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) ImageJPluginLoggerHelper(uk.ac.sussex.gdsc.core.ij.ImageJPluginLoggerHelper) LocalCollectors(uk.ac.sussex.gdsc.core.utils.LocalCollectors) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ScreenDimensionHelper(uk.ac.sussex.gdsc.core.ij.gui.ScreenDimensionHelper) PlotWindow(ij.gui.PlotWindow) ListSelectionEvent(javax.swing.event.ListSelectionEvent) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) JMenuBar(javax.swing.JMenuBar) CoordinatePredicate(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) JMenu(javax.swing.JMenu) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) WindowEvent(java.awt.event.WindowEvent) DoubleStream(java.util.stream.DoubleStream) Objects(java.util.Objects) List(java.util.List) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) JTable(javax.swing.JTable) LUT(ij.process.LUT) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) Roi(ij.gui.Roi) Rectangle(java.awt.Rectangle) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) AtomicReference(java.util.concurrent.atomic.AtomicReference) SwingConstants(javax.swing.SwingConstants) TextField(java.awt.TextField) Level(java.util.logging.Level) AWTEvent(java.awt.AWTEvent) BiPredicate(java.util.function.BiPredicate) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) ImagePeakResultsFactory(uk.ac.sussex.gdsc.smlm.ij.results.ImagePeakResultsFactory) UnitHelper(uk.ac.sussex.gdsc.smlm.data.config.UnitHelper) ExecutorService(java.util.concurrent.ExecutorService) LutColour(uk.ac.sussex.gdsc.core.ij.process.LutHelper.LutColour) ActionEvent(java.awt.event.ActionEvent) Rounder(uk.ac.sussex.gdsc.core.data.utils.Rounder) TimeUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.TimeUnit) Consumer(java.util.function.Consumer) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) TableColumnAdjuster(uk.ac.sussex.gdsc.smlm.ij.gui.TableColumnAdjuster) IJ(ij.IJ) DoublePredicate(java.util.function.DoublePredicate) Collections(java.util.Collections) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) CoordinatePredicate(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate)

Example 2 with CoordinatePredicate

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");
}
Also used : Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) PassPeakResultPredicate(uk.ac.sussex.gdsc.smlm.results.predicates.PassPeakResultPredicate) IdentityTypeConverter(uk.ac.sussex.gdsc.core.data.utils.IdentityTypeConverter) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) OptionListener(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog.OptionListener) CoordinatePredicateUtils(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicateUtils) PeakResultValueParameter(uk.ac.sussex.gdsc.smlm.results.PeakResultValueParameter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) UnitHelper(uk.ac.sussex.gdsc.smlm.data.config.UnitHelper) CropResultsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.CropResultsSettings) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) CoordinatePredicate(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ConversionException(uk.ac.sussex.gdsc.core.data.utils.ConversionException) Predicate(java.util.function.Predicate) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) Consumer(java.util.function.Consumer) ImagePlus(ij.ImagePlus) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) MinMaxResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.MinMaxResultProcedure) MinMaxPeakResultPredicate(uk.ac.sussex.gdsc.smlm.results.predicates.MinMaxPeakResultPredicate) PlugIn(ij.plugin.PlugIn) TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Rectangle(java.awt.Rectangle) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ImagePlus(ij.ImagePlus) CoordinatePredicate(uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

Aggregations

IJ (ij.IJ)2 ImagePlus (ij.ImagePlus)2 WindowManager (ij.WindowManager)2 PlugIn (ij.plugin.PlugIn)2 Rectangle (java.awt.Rectangle)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Consumer (java.util.function.Consumer)2 IdentityTypeConverter (uk.ac.sussex.gdsc.core.data.utils.IdentityTypeConverter)2 TypeConverter (uk.ac.sussex.gdsc.core.data.utils.TypeConverter)2 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)2 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)2 CoordinatePredicate (uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicate)2 CoordinatePredicateUtils (uk.ac.sussex.gdsc.core.ij.roi.CoordinatePredicateUtils)2 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)2 TextUtils (uk.ac.sussex.gdsc.core.utils.TextUtils)2 CalibrationHelper (uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper)2 UnitHelper (uk.ac.sussex.gdsc.smlm.data.config.UnitHelper)2 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)2 InputSource (uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource)2 SettingsManager (uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager)2