// ---
// jupyter:
//   jupytext:
//     text_representation:
//       extension: .groovy
//       format_name: light
//       format_version: '1.5'
//       jupytext_version: 1.14.4
//   kernelspec:
//     display_name: Groovy
//     language: groovy
//     name: groovy
// ---

// ## StackView Op

// +
//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()
// -

// This `Op` wraps the `Views.stack()` method of ImgLib2, taking multiple n-dimensional `RandomAccessibleInterval`s and stacking them to form a single (n+1)-dimensional `RandomAccessibleInterval`.

ij.op().help('stackView')

// We are interested in the first of the two, for this notebook. To create the stack we need two `Img`s, which we can create using [`equation`](../image/equation.ipynb)

// +
import net.imglib2.FinalInterval
import net.imglib2.img.Img
import net.imglib2.type.numeric.integer.UnsignedByteType

dims = new FinalInterval(200, 150)

imgList = new ArrayList<Img>()

input1 = ij.op().create().img(dims, new UnsignedByteType())
equation1 = "127 * Math.sin(p[0] / 4) + 128"
ij.op().run("equation", input1, equation1)
input2 = ij.op().create().img(dims, new UnsignedByteType())
equation2 = "127 * Math.cos(p[1] / 4) + 128"
ij.op().run("equation", input2, equation2)

imgList.add(input1)
imgList.add(input2)

//TODO show side by side
// -

// We can stack them by passing both into `Views.stack()`:

// +
import net.imglib2.view.Views

stack = ij.op().run("stackView", imgList)

ij.notebook().display(stack)

StarcoderdataJupyterScriptsDedupFiltered