Accessing channel vectors

Hi All,

Let’s assume that I have an N-dimensional image that includes a spectral dimension (e.g. XYZC). I’d like to iteratively access the channel vectors (i.e. the values across the spectral dimension) for all pixels in the image. My goal is to take the dot product of each channel vector and some other vector. It seems that this should be doable using Views.hyperSlice as in from the ImgLib2 examples.

The inputs for Views.hyperSlice are not quite clear to me. I feel safe in assuming that int[] fixedAxes is my spectral dimension which I can get with int cDim = img.dimensionIndex(Axes.CHANNEL);. I’m not sure what I should be passing as long[] position. I think this should be the position along the spectral dimension at which the hyperslice is taken; however, the doc suggests that position is something else: “The position is passed as position vector in source space, i.e. the positions along fixed axes are ignored.” I’d appreciate any clarification someone can provide on this point. Alternative methods are also welcomed.


Hi @brossetti,

Views.hyperslice doesn’t take a long[], but rather a single int, and a single long.
The int argument is the dimension from which a single hyperslice is taken, and the long gives the position along that dimension.

The Views method is probably more convenient than calling the HyperSlice object directly…in fact i just noticed that even the Views convenience method does not use Hyperslice.

Does this help?

Edit: typo fix