How to create an efficient sparse ImgLib2 volume populated by a list of 3D spheres

imglib2

#1

Hi all,

Using the KDTree, perhaps there is a way to convert data like this:

from net.imglib2 import RealPoint

spheres = [
  RealPoint([100.2, 10.3, 23.5]),
  RealPoint([340.2, 55.0, 47.8]),
  ...
]

… into a sparse RealRandomAccessible. How would one go about it, @tpietzsch ?

The radius can be the same for all, or specified differently–doesn’t matter. The RealRandomAccessible's cursor should return a value when inside and zero when outside the radius of any of the spheres.

Thanks.


#2

I believe the answer is in imglib2-roi. You can make sphere ROIs and merge multiple ROIs by and operations.

@awalter17 has a demo branch in the imglib2-roi repository that she and @tpietzsch have worked on where you can find some examples of this.


#3

Thanks very much! Will explore imglib2-roi.


#4

So I did explore imglib2-roi, and it looks like an impenetrable jungle. Are there any annotated real-world examples of usage of imglib2-roi? Perhaps @tinevez has some?


#5

Hi Albert,
do you have something like this in mind:


Coordinates and associated colors put in KDTree, then converted to nearest neighbor RealRandomAccessible.


#6

Thanks. With a radius for every point, though.


#7

Ok, I should have read the topic title…
So:
You would make a KDTree of those centroids.
Then make a RealRandomAccessible with the KDTree and a custom RealRandomAccess.
The RealRandomAccess has a NearestNeighborSearchOnKDTree search on tree, in get() it does
search.search(this), then compares search.getDistance() to radius.
Returns one T value inside, another outside.
If you derive the custom RealRandomAccess from RealPoint, it’s not a lot of boilderplate


#8

If each point has a different radius, you need more than the nearest neighbor. You would use RadiusNeighborSearch with the maximum radius of any of your spheres.
In mastodon-collection we have IncrementalNEarestNeighborSearch https://github.com/bigdataviewer/mastodon-collection/blob/master/src/main/java/org/mastodon/kdtree/IncrementalNearestNeighborSearch.java which would be preferable but I haven’t got around to backporting that to imglib2 yet.


#9

Maybe as reference for boilerplate for RRAI and RRA:


This is similar (in terms of boilerplate): one color inside some distance to an ellipsoid surface, another color outside.


#10

Thank you very much @tpietzsch, that seems to be exactly what I am after.


#11

By the way this:

… reads like it would make a useful util class.


#12

I’ve posted a full example that uses the KDTree and NearestNeighborSearchOnKDTree classes to draw simulated segmentations of detected embryos in the sample image embryos.jpg.

https://www.ini.uzh.ch/~acardona/fiji-tutorial/#generative-image-circles