Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Created April 8, 2021 22:52
Show Gist options
  • Save bogovicj/1bd7050e3604e9b693097a02b3462781 to your computer and use it in GitHub Desktop.
Save bogovicj/1bd7050e3604e9b693097a02b3462781 to your computer and use it in GitHub Desktop.
Voronoi diagram / "Natural interpolation"with imglib2-KDTree
#@ Dataset img
/**
* Voronoi diagram / "Natural interpolation"with imglib2-KDTree
* see
* https://forum.image.sc/t/natural-neighbor-interpolation-in-3d/51243
*
* John Bogovic
*/
import net.imglib2.*;
import net.imglib2.neighborsearch.KNearestNeighborSearchOnKDTree;
class ValuePoint extends RealPoint {
int value;
ValuePoint( double[] p, int value )
{
super( p );
this.value = value;
}
public int getValue() { return value; }
};
def toDataset( img, search )
{
Cursor c = img.cursor();
while( c.hasNext() )
{
c.fwd();
search.search( c );
c.get().setInteger( search.getSampler( 0 ).get().getValue() );
}
}
pts = [
new ValuePoint( new double[] { 5, 5, 15}, 1 ),
new ValuePoint( new double[] { 16, 5, 15}, 2 ),
new ValuePoint( new double[] { 16, 16, 15}, 3 ) ];
search = new KNearestNeighborSearchOnKDTree( new KDTree( pts, pts ), 1 );
toDataset( img, search );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment