import numpy as np import holoviews as hv hv.extension('bokeh')
ImageStack facilitates the representation of a regularly spaced 2D grid within a continuous domain of color space values (RGB(A)). The grid’s structure aligns closely with that of an Image element. In its simplest form, the grid can be defined through an array with dimensions of
L represents the number of channels. Alternatively, explicit and uniformly spaced x/y-coordinate arrays can also define the
The core methods for constructing an
Creating using coordinates and channel values:
ImageStack((X, Y, L1, L2, ..., LL), vdims=["l1", "l2", ... "ll"])
Xis a 1D array with
Yis a 1D array with
LLrepresent 2D arrays with dimensions
Creation through a composite array and bounds specification:
ImageStack(Z, bounds=(x0, y0, x1, y1))
In this scenario,
Zis a 3D array with dimensions
NxMxL, and the bounds parameter defines the (left, bottom, right, top) corners of the grid.
For comprehensive information, refer to the Gridded Datasets user guide.
x = np.arange(0, 3) y = np.arange(5, 8) a = np.array([[np.nan, np.nan, 1], [np.nan] * 3, [np.nan] * 3]) b = np.array([[np.nan] * 3, [1, 1, np.nan], [np.nan] * 3]) c = np.array([[np.nan] * 3, [np.nan] * 3, [1, 1, 1]]) img_stack = hv.ImageStack((x, y, a, b, c), kdims=["x", "y"], vdims=["a", "b", "c"]) img_stack
cmap can be added to differentiate the different levels.
cmap = ["red", "green", "blue"] img_stack.opts(cmap=cmap)
Slicing, sampling, etc. on an
ImageStack all operate in this continuous space, whereas the corresponding operations on a
Raster work on the raw array coordinates.
Here we take slices up to x=0.5 and y=7, which is out of bounds for the red.