Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NicoKiaru/f88aaf6bfc201d468b57c771424f1f06 to your computer and use it in GitHub Desktop.
Save NicoKiaru/f88aaf6bfc201d468b57c771424f1f06 to your computer and use it in GitHub Desktop.
Demo of procedural image generation in FIJI using Imglib2 + shearing
import net.imglib2.position.FunctionRandomAccessible
import net.imglib2.type.numeric.integer.UnsignedShortType
import java.util.function.BiConsumer
import bdv.util.BdvFunctions
import bdv.util.BdvOptions
import net.imglib2.FinalInterval
import net.imglib2.view.Views
import net.imglib2.realtransform.AffineTransform3D
import net.imglib2.type.numeric.ARGBType
// If NEW BigVolumeViewer site enabled:
//import bvv.util.BvvFunctions
//import bvv.util.BvvOptions
// 1 - Creates checkerboard image
// ... first unrestricted in space (randomAccessible)
randomAccessible = new FunctionRandomAccessible<UnsignedShortType>(3 as int,
{ l,t ->
int px = l.getIntPosition(0)
int py = l.getIntPosition(1)
int pz = l.getIntPosition(2)
t.set((int) ((int)(px/4)%2 + (int)(py/4)%2 + (int)(pz/4)%2)) // Checkerboard
} as BiConsumer, { return new UnsignedShortType()});
// ... second restricted to an interval in 3D -> RandomAccessibleInterval, or rai in short
rai = Views.interval(randomAccessible, FinalInterval.createMinMax( 0, 0, 0, 23, 23, 23))
// 2 - Creates AffineTransformation
// 2a - Identity AffineTransform3D
at3Didentity = new AffineTransform3D()
// 2b - AffineTransformed3D...
at3Dsheared = new AffineTransform3D()
// ... sheared
at3Dsheared.set(0.5,0,1)
// Uncomment next two lines for weirder shearing
//at3Dsheared.set(0.3,2,1)
//at3Dsheared.set(0.4,1,2)
// ... and translated to avoid overlap with the non sheared image
at3Dsheared.translate(24,0,0);
// 3 - Display using BigDataViewer
// 3a - Display non sheared image
bss = BdvFunctions.show(rai,"Image",
BdvOptions.options()
.sourceTransform(at3Didentity) // AffineTransform used for the rai
);
// Display settings:
// MinMax
bss.setDisplayRange( 0, 3 )
// Color : Green
bss.setColor(new ARGBType(ARGBType.rgba(0,255,0,1)));
// 3b - Display sheared image
bss = BdvFunctions.show(rai,"Sheared Image",
BdvOptions.options()
.sourceTransform(at3Dsheared) // AffineTransform used for the rai
.addTo(bss.getBdvHandle()) // Appends data to an existing Bdv window -> reference taken from the first displayed image
);
// Display settings
bss.setDisplayRange( 0, 3 )
bss.setColor(new ARGBType(ARGBType.rgba(255,0,0,1)));
// If NEW BigVolumeViewer site enabled:
// 4 - Display using BigVolumeViewer
// 4a - Display non sheared image
/*
bss = BvvFunctions.show(rai,"Image", BvvOptions.options().sourceTransform(at3Didentity) )
bss.setDisplayRange( 0, 3 )
bss.setColor(new ARGBType(ARGBType.rgba(0,255,0,1)))
// 4a - Display non sheared image
bss = BvvFunctions.show(rai,"Sheared Image", BvvOptions.options().sourceTransform(at3Dsheared).addTo(bss.getBvvHandle()) )
bss.setDisplayRange( 0, 3 )
bss.setColor(new ARGBType(ARGBType.rgba(255,0,0,1)))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment