Skip to main content

ImageArray

Trait ImageArray 

Source
pub trait ImageArray<P: Pixel, ImageContainer> {
    // Required methods
    fn as_ndarray(&self) -> ArrayView3<'_, ImageContainer>;
    fn as_ndarray_mut(&mut self) -> ArrayViewMut3<'_, ImageContainer>;
    fn to_ndarray(self) -> Array3<ImageContainer>;
    fn from_ndarray<D: Dimension>(
        array: Array<ImageContainer, D>,
    ) -> Result<ImageBuffer<P, Vec<ImageContainer>>, Error>;
}
Expand description

Conversion methods for working with ndarrays.

Views and standard-layout ownership conversions reuse the original allocation. Non-standard layouts are copied into image row order.

Required Methods§

Source

fn as_ndarray(&self) -> ArrayView3<'_, ImageContainer>

Cast the ImageBuffer as an ArrayView3.

  • Y index is the row
  • X index is the columns
  • Z index is the channel

So when referencing: array[[y, x, z]]

This does not copy the data, as it is a reference to the actual data in the buffer.

Source

fn as_ndarray_mut(&mut self) -> ArrayViewMut3<'_, ImageContainer>

Cast the ImageBuffer as an ArrayViewMut3.

  • Y index is the row
  • X index is the columns
  • Z index is the channel

So when referencing: array[[y, x, z]]

This does not copy the data, as it is a reference to the actual data in the buffer.

Source

fn to_ndarray(self) -> Array3<ImageContainer>

Interpret the ImageBuffer as an Array3.

  • Y index is the row
  • X index is the columns
  • Z index is the channel

So when referencing: array[[y, x, z]]

This does not copy the data, but it does consume the buffer.

Source

fn from_ndarray<D: Dimension>( array: Array<ImageContainer, D>, ) -> Result<ImageBuffer<P, Vec<ImageContainer>>, Error>

Convert the provided array into the ImageBuffer

  • Y index is the row
  • X index is the columns
  • Z index is the channel

So when referencing: array[[y, x, z]]

This consumes the array. Standard layouts reuse its allocation; other layouts are copied into row-major pixel order.

§Errors

Returns Error::Dimensions if the array is not 2D or 3D, or its size does not fit into the image dimensions, Error::ChannelMismatch if the channel count differs from the pixel type, and Error::ImageConstructFailed if the buffer cannot back an image.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<P, C> ImageArray<P, C> for ImageBuffer<P, Vec<C>>
where P: Pixel<Subpixel = C>, C: Clone + Copy,

Available on crate feature image only.
Source§

fn as_ndarray(&self) -> ArrayView3<'_, C>

Source§

fn to_ndarray(self) -> Array3<C>

Source§

fn from_ndarray<D: Dimension>( array: Array<C, D>, ) -> Result<ImageBuffer<P, Vec<C>>, Error>

Source§

fn as_ndarray_mut(&mut self) -> ArrayViewMut3<'_, C>

Implementors§