Search in sources :

Example 1 with NearestNeighborSearchOnKDTree

use of net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree in project bacmman by jeanollion.

the class Curvature method getCurvatureWatershedMap.

public static ImageFloat getCurvatureWatershedMap(final Image edm, final ImageInteger mask, KDTree<Double> curvature) {
    final ImageFloat res = new ImageFloat("CurvatureWatershedMap", edm);
    final NearestNeighborSearchOnKDTree<Double> search = new NearestNeighborSearchOnKDTree(curvature);
    final TreeSet<Voxel> heap = new TreeSet<>(Voxel.getComparator());
    final EllipsoidalNeighborhood neigh = new EllipsoidalNeighborhood(1.5, true);
    // initialize with the border of objects
    BoundingBox.loop(mask.getBoundingBox().resetOffset(), (int x, int y, int z) -> {
        if (mask.insideMask(x, y, z) && neigh.hasNullValue(x, y, z, mask, true)) {
            double edmValue = edm.getPixel(x, y, z);
            search.search(new Point(x + mask.xMin(), y + mask.yMin()));
            res.setPixel(x, y, z, search.getSampler().get());
            Voxel next;
            for (int i = 0; i < neigh.getSize(); ++i) {
                next = new Voxel(x + neigh.dx[i], y + neigh.dy[i], 0);
                if (!mask.contains(next.x, next.y, next.z) || !mask.insideMask(x, y, z))
                    continue;
                next.value = edm.getPixel(next.x, next.y, 0);
                if (next.value > edmValue)
                    heap.add(next);
            }
        }
    });
    Voxel next;
    while (!heap.isEmpty()) {
        Voxel v = heap.pollFirst();
        double value = 0, count = 0;
        for (int i = 0; i < neigh.getSize(); ++i) {
            next = new Voxel(v.x + neigh.dx[i], v.y + neigh.dy[i], 0);
            next.value = edm.getPixel(next.x, next.y, next.z);
            if (next.value > v.value)
                heap.add(next);
            else {
                value += res.getPixel(next.x, next.y, 0);
                ++count;
                if (count > 0)
                    res.setPixel(v.x, v.y, 0, value / count);
            }
        }
    }
    return res;
}
Also used : NearestNeighborSearchOnKDTree(net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree) Voxel(bacmman.data_structure.Voxel) TreeSet(java.util.TreeSet) EllipsoidalNeighborhood(bacmman.processing.neighborhood.EllipsoidalNeighborhood) Point(net.imglib2.Point) RealPoint(net.imglib2.RealPoint) ImageFloat(bacmman.image.ImageFloat) Point(net.imglib2.Point) RealPoint(net.imglib2.RealPoint)

Example 2 with NearestNeighborSearchOnKDTree

use of net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree in project bigdataviewer-biop-tools by BIOP.

the class WeightedVoronoiSourceGetter method getVoronoiTestLabelImage.

public static RandomAccessibleInterval<FloatType> getVoronoiTestLabelImage(final long[] imgTestSize, int numPts, boolean copyImg) {
    // the interval in which to create random points
    FinalInterval interval = new FinalInterval(imgTestSize);
    // create an IterableRealInterval
    IterableRealInterval<FloatType> realInterval = createRandomPoints(interval, numPts);
    // using nearest neighbor search we will be able to return a value an any position in space
    NearestNeighborSearch<FloatType> search = new NearestNeighborSearchOnKDTree<>(new KDTree<>(realInterval));
    // make it into RealRandomAccessible using nearest neighbor search
    RealRandomAccessible<FloatType> realRandomAccessible = Views.interpolate(search, new NearestNeighborSearchInterpolatorFactory<FloatType>());
    // convert it into a RandomAccessible which can be displayed
    RandomAccessible<FloatType> randomAccessible = Views.raster(realRandomAccessible);
    // set the initial interval as area to view
    RandomAccessibleInterval<FloatType> labelImage = Views.interval(randomAccessible, interval);
    if (copyImg) {
        final RandomAccessibleInterval<FloatType> labelImageCopy = new ArrayImgFactory(Util.getTypeFromInterval(labelImage)).create(labelImage);
        // Image copied to avoid computing it on the fly
        // https://github.com/imglib/imglib2-algorithm/blob/47cd6ed5c97cca4b316c92d4d3260086a335544d/src/main/java/net/imglib2/algorithm/util/Grids.java#L221 used for parallel copy
        Grids.collectAllContainedIntervals(imgTestSize, new int[] { 64, 64, 64 }).stream().forEach(blockinterval -> {
            copy(labelImage, Views.interval(labelImageCopy, blockinterval));
        });
        // LoopBuilder.setImages(labelImage, labelImageCopy).forEachPixel(Type::set);
        return labelImageCopy;
    } else {
        return labelImage;
    }
}
Also used : NearestNeighborSearchOnKDTree(net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) FloatType(net.imglib2.type.numeric.real.FloatType)

Example 3 with NearestNeighborSearchOnKDTree

use of net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree in project imagej-utils by embl-cba.

the class TableRowsScatterPlot method searchClosestPoint.

private T searchClosestPoint(NearestNeighborSearchOnKDTree<T> search) {
    final RealPoint realPoint = new RealPoint(3);
    bdvHandle.getViewerPanel().getGlobalMouseCoordinates(realPoint);
    RealPoint realPoint2d = new RealPoint(realPoint.getDoublePosition(0), realPoint.getDoublePosition(1));
    search.search(realPoint2d);
    return search.getSampler().get();
}
Also used : RealPoint(net.imglib2.RealPoint)

Example 4 with NearestNeighborSearchOnKDTree

use of net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree in project imagej-utils by embl-cba.

the class TableRowsScatterPlot method installBdvBehaviours.

// private void addGridLinesOverlay()
// {
// GridLinesOverlay gridLinesOverlay = new GridLinesOverlay( bdvHandle, columnNames, columnNameY, dataPlotInterval, lineOverlay, axisLabelsFontSize );
// 
// BdvFunctions.showOverlay( gridLinesOverlay, "grid lines overlay", BdvOptions.options().addTo( bdvHandle ).is2D() );
// }
// private void addAxisTickLabelsOverlay()
// {
// AxisTickLabelsOverlay scatterPlotGridLinesOverlay = new AxisTickLabelsOverlay( xLabelToIndex, yLabelToIndex, dataInterval );
// 
// BdvFunctions.showOverlay( scatterPlotGridLinesOverlay, "axis tick labels overlay", BdvOptions.options().addTo( bdvHandle ).is2D() );
// }
private void installBdvBehaviours(NearestNeighborSearchOnKDTree<T> search) {
    Behaviours behaviours = new Behaviours(new InputTriggerConfig());
    behaviours.install(bdvHandle.getTriggerbindings(), "scatterplot" + selectedColumns[0] + selectedColumns[1]);
    BdvPopupMenus.addAction(bdvHandle, "Focus closest point [Left-Click ]", (x, y) -> focusAndSelectClosestPoint(search, true));
    behaviours.behaviour((ClickBehaviour) (x, y) -> focusAndSelectClosestPoint(search, true), "Focus closest point", "button1");
    BdvPopupMenus.addAction(bdvHandle, "Select closest point [ Ctrl Left-Click ]", (x, y) -> focusAndSelectClosestPoint(search, false));
    behaviours.behaviour((ClickBehaviour) (x, y) -> focusAndSelectClosestPoint(search, false), "Select closest point", "ctrl button1");
    BdvPopupMenus.addAction(bdvHandle, "Reconfigure...", (x, y) -> {
        ScatterPlotDialog dialog = new ScatterPlotDialog(tableRows.get(0).getColumnNames().stream().toArray(String[]::new), selectedColumns, scaleFactors, dotSizeScaleFactor);
        if (dialog.show()) {
            selectedColumns = dialog.getSelectedColumns();
            scaleFactors = dialog.getScaleFactors();
            dotSizeScaleFactor = dialog.getDotSizeScaleFactor();
            final int xLoc = SwingUtilities.getWindowAncestor(bdvHandle.getViewerPanel()).getLocationOnScreen().x;
            final int yLoc = SwingUtilities.getWindowAncestor(bdvHandle.getViewerPanel()).getLocationOnScreen().y;
            bdvHandle.close();
            createAndShowScatterPlot(xLoc, yLoc);
        }
    });
}
Also used : ARGBType(net.imglib2.type.numeric.ARGBType) BdvPopupMenus(de.embl.cba.bdv.utils.popup.BdvPopupMenus) SelectionModel(de.embl.cba.tables.select.SelectionModel) NearestNeighborSearchOnKDTree(net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree) TableRow(de.embl.cba.tables.tablerow.TableRow) Supplier(java.util.function.Supplier) ClickBehaviour(org.scijava.ui.behaviour.ClickBehaviour) InputTriggerConfig(org.scijava.ui.behaviour.io.InputTriggerConfig) SelectionListener(de.embl.cba.tables.select.SelectionListener) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) KDTree(net.imglib2.KDTree) FinalInterval(net.imglib2.FinalInterval) FunctionRealRandomAccessible(net.imglib2.position.FunctionRealRandomAccessible) Behaviours(org.scijava.ui.behaviour.util.Behaviours) RealPoint(net.imglib2.RealPoint) Prefs(bdv.util.Prefs) BdvOptions(bdv.util.BdvOptions) BdvUtils(de.embl.cba.bdv.utils.BdvUtils) BdvHandle(bdv.util.BdvHandle) BdvFunctions(bdv.util.BdvFunctions) List(java.util.List) IJ(ij.IJ) SelectionColoringModel(de.embl.cba.tables.color.SelectionColoringModel) javax.swing(javax.swing) Behaviours(org.scijava.ui.behaviour.util.Behaviours) InputTriggerConfig(org.scijava.ui.behaviour.io.InputTriggerConfig) RealPoint(net.imglib2.RealPoint)

Aggregations

RealPoint (net.imglib2.RealPoint)3 NearestNeighborSearchOnKDTree (net.imglib2.neighborsearch.NearestNeighborSearchOnKDTree)3 Voxel (bacmman.data_structure.Voxel)1 ImageFloat (bacmman.image.ImageFloat)1 EllipsoidalNeighborhood (bacmman.processing.neighborhood.EllipsoidalNeighborhood)1 BdvFunctions (bdv.util.BdvFunctions)1 BdvHandle (bdv.util.BdvHandle)1 BdvOptions (bdv.util.BdvOptions)1 Prefs (bdv.util.Prefs)1 BdvUtils (de.embl.cba.bdv.utils.BdvUtils)1 BdvPopupMenus (de.embl.cba.bdv.utils.popup.BdvPopupMenus)1 SelectionColoringModel (de.embl.cba.tables.color.SelectionColoringModel)1 SelectionListener (de.embl.cba.tables.select.SelectionListener)1 SelectionModel (de.embl.cba.tables.select.SelectionModel)1 TableRow (de.embl.cba.tables.tablerow.TableRow)1 IJ (ij.IJ)1 List (java.util.List)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 BiConsumer (java.util.function.BiConsumer)1