Last active
September 2, 2018 14:06
-
-
Save ctrueden/d4ab1996c63ba4d4fcd2a97e121fff3b to your computer and use it in GitHub Desktop.
Ops over regions with the imglib2-roi API
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
#@ Img image | |
#@ OpService ops | |
import net.imglib2.Interval | |
import net.imglib2.RandomAccessibleInterval | |
import net.imglib2.roi.Masks | |
import net.imglib2.roi.RealMask | |
import net.imglib2.roi.Regions | |
import net.imglib2.roi.geom.GeomMasks | |
import net.imglib2.view.Views | |
def roi(RealMask mask, RandomAccessibleInterval image) { | |
// Convert ROI from R^n to Z^n. | |
discreteROI = Views.raster(Masks.toRealRandomAccessible(mask)) | |
// Apply finite bounds to the discrete ROI. | |
boundedDiscreteROI = Views.interval(discreteROI, image) | |
// Create an iterable version of the finite discrete ROI. | |
iterableROI = Regions.iterable(boundedDiscreteROI) | |
return Regions.sample(iterableROI, image) | |
} | |
min = [40, 30] as double[] | |
max = [50, 60] as double[] | |
openBox = GeomMasks.openBox(min, max) | |
openROI = roi(openBox, image) | |
openSize = ops.stats().size(openROI) | |
openMean = ops.stats().mean(openROI) | |
println("open box: size=" + openSize + ", mean=" + openMean) | |
closedBox = GeomMasks.closedBox(min, max) | |
closedROI = roi(closedBox, image) | |
closedSize = ops.stats().size(closedROI) | |
closedMean = ops.stats().mean(closedROI) | |
println("closed box: size=" + closedSize + ", mean=" + closedMean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment