Created
April 8, 2021 22:52
-
-
Save bogovicj/1bd7050e3604e9b693097a02b3462781 to your computer and use it in GitHub Desktop.
Voronoi diagram / "Natural interpolation"with imglib2-KDTree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ 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