[][src]Trait nshare::RefNdarray3

pub trait RefNdarray3 {
    type Out;
    pub fn ref_ndarray3(self) -> Self::Out;
}

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

Loading content...

Required methods

pub fn ref_ndarray3(self) -> Self::Out[src]

Loading content...

Implementations on Foreign Types

impl<'a, P> RefNdarray3 for &'a ImageBuffer<P, Vec<P::Subpixel>> where
    P: Pixel + 'static, 
[src]

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);

type Out = ArrayView3<'a, P::Subpixel>

Loading content...

Implementors

Loading content...