Trait nshare::RefNdarray3
source · [−]pub trait RefNdarray3 {
type Out;
fn ref_ndarray3(self) -> Self::Out;
}
Expand description
Borrows a 3d type to a ndarray 2d array type.
Coordinates are in (channel, row, col)
, where channel is typically a color channel,
or they are in (z, y, x)
.
This uses an associated type to avoid ambiguity for the compiler. By calling this, the compiler always knows the returned type.
Associated Types
Required methods
fn ref_ndarray3(self) -> Self::Out
Implementations on Foreign Types
use image::{RgbImage, Rgb};
use nshare::RefNdarray3;
use ndarray::s;
let mut vals = RgbImage::new(2, 4);
vals[(1, 0)] = Rgb([0, 255, 0]);
let nd = vals.ref_ndarray3();
// ndarray uses (channel, row, col), so the dims get flipped.
assert_eq!(nd.dim(), (3, 4, 2));
// The first row green should sum to 255.
assert_eq!(nd.slice(s![1, 0, ..]).sum(), 255);
// The first row red should sum to 0.
assert_eq!(nd.slice(s![0, 0, ..]).sum(), 0);