Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Created April 2, 2024 14:12
Show Gist options
  • Save bogovicj/356a0363909ba7bd7f53230d323acc78 to your computer and use it in GitHub Desktop.
Save bogovicj/356a0363909ba7bd7f53230d323acc78 to your computer and use it in GitHub Desktop.
ImageJ2 script that displays a Diamond or Hypersphere neighborhood for a given radius
#@ DatasetService ds
#@ UIService ui
#@ Long radius = 13
#@ String (choices={"Diamond", "Hypersphere"}, style="listBox") shapeType
/*
* Displays a Diamond or Hypersphere neighborhood for a given radius
*/
if( shapeType.equals("Diamond"))
shp = new DiamondShape(radius);
else
shp = new HyperSphereShape(radius);
// allocate an image
img = ds.create(new UnsignedByteType(), new long[]{ 4*radius+1, 4*radius+1 }, "shape", new AxisType[] { Axes.X, Axes.Y } );
// make the shape and center it
nbhds = shp.neighborhoodsRandomAccessible( img ).randomAccess();
nbhds.setPosition( 2*radius, 0 );
nbhds.setPosition( 2*radius, 1 );
// fill the shape and show iut
nbhds.get().cursor().forEachRemaining( x -> x.setReal(255) );
ui.show(img);
import net.imagej.*;
import net.imagej.axis.*;
import net.imglib2.*;
import net.imglib2.algorithm.neighborhood.*;
import net.imglib2.type.numeric.*;
import net.imglib2.type.numeric.integer.*;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment