Created
June 3, 2018 18:54
-
-
Save ctrueden/82b559f859e32041d211ae25ab003c63 to your computer and use it in GitHub Desktop.
Create some ImgLib2 ROIs and attach them to an IJ1 ImagePlus
This file contains 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
#@ ConvertService convert | |
#@ ImagePlus imp | |
import bdv.util.BdvFunctions | |
import bdv.util.BdvOptions | |
import ij.gui.Overlay | |
import ij.gui.Roi | |
import net.imglib2.roi.Masks | |
import net.imglib2.roi.geom.GeomMasks | |
import net.imglib2.view.Views | |
import net.imglib2.util.Intervals | |
// Create some ImgLib2 ROIs. | |
rois = [ | |
GeomMasks.closedEllipsoid([5, 6] as double[], [7, 8] as double[]), | |
GeomMasks.polygon2D([2, 3, 4, 5, 6, 1, 9, 9] as double[], [7, 5, 3, 4, 6, 1, 1, 9] as double[]) // TODO Fiji logo | |
] | |
// Lump them into a collection. | |
roiTree = new net.imagej.roi.DefaultROITree() | |
roiTree.addROIs(rois) | |
// Define a function to show ROIs with BDV. | |
def showROIs(roi) { | |
rrari = Masks.toRealRandomAccessibleRealInterval(roi) | |
println(rrari) | |
ra = Views.raster(rrari) | |
println(ra) | |
bounds = Intervals.smallestContainingInterval(rrari) | |
rai = Views.interval(ra, bounds) | |
BdvFunctions.show(rai, "Awesome", new BdvOptions().is2D()) | |
} | |
// Uncomment this to show the ImgLib2 ROIs with the BDV. | |
//showROIs(roiTree.children().get(1).data()) | |
// Convert IJ2 -> IJ1. | |
overlay = convert.convert(roiTree, Overlay.class) | |
println(overlay) | |
// You could also convert them individually if you like things to be more complicated. :-) | |
//roi0 = convert.convert(rois[0], Roi.class) | |
//println(roi0) | |
//roi1 = convert.convert(rois[1], Roi.class) | |
//println(roi1) | |
//overlay = new Overlay() | |
//overlay.add(roi0) | |
//overlay.add(roi1) | |
imp.setOverlay(overlay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment