//load ImageJ %classpath config resolver scijava.public https://maven.scijava.org/content/groups/public %classpath add mvn net.imagej imagej 2.0.0-rc-67 //create ImageJ object ij = new net.imagej.ImageJ() ij.op().help('integralSum') ramp = ij.op().run("create.img", [150, 100]) formula = "p[0] + p[1]" ij.op().image().equation(ramp, formula) ij.notebook().display(ramp) import net.imglib2.algorithm.neighborhood.RectangleNeighborhood //our current position in the neighborhood. This is not really important in this use case //since all we care about is the region as a whole (since we are summing each pixel), //however in other applications it can be useful. position = [5, 5] as long[] //The top left corner of the neighborhood min = [0, 0] as long[] //The bottom right corner of the neighborhood max = [10, 10] as long[] //An Interval object that defines the span of the image. This is, again, //not really important for our use case, ut we can pass through our ramp image since //all Imgs are Intervals span = ramp //A RandomAccess that allows us to access all of the data values of our Img randomAccess = ramp.randomAccess() neighborhood = RectangleNeighborhood.factory().create(position, min, max, span, randomAccess) import net.imglib2.type.numeric.real.DoubleType output = new DoubleType() ij.op().stats().integralSum(output, neighborhood) output