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;
}
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;
}
}
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();
}
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);
}
});
}
Aggregations