Skip to main content

Image

Struct Image 

Source
pub struct Image { /* private fields */ }
Expand description

An image representation wrapping NumRS2 arrays.

Images store pixel data as f64 values in the range [0.0, 1.0]. Grayscale images have shape [height, width], RGB images have shape [height, width, 3], and RGBA images have shape [height, width, 4].

Implementations§

Source§

impl Image

Source

pub fn from_grayscale( width: usize, height: usize, data: &[f64], ) -> Result<Self, NumRs2Error>

Creates a new grayscale image from raw pixel data.

§Arguments
  • width - Image width in pixels
  • height - Image height in pixels
  • data - Pixel values in row-major order, expected in [0.0, 1.0]
§Errors

Returns NumRs2Error::ValueError if data length does not match width * height

Source

pub fn from_rgb( width: usize, height: usize, data: &[f64], ) -> Result<Self, NumRs2Error>

Creates a new RGB image from raw pixel data.

§Arguments
  • width - Image width in pixels
  • height - Image height in pixels
  • data - Pixel values in row-major order with 3 channels per pixel
§Errors

Returns NumRs2Error::ValueError if data length does not match width * height * 3

Source

pub fn zeros_grayscale(width: usize, height: usize) -> Self

Creates a grayscale image filled with zeros (black).

§Arguments
  • width - Image width in pixels
  • height - Image height in pixels
Source

pub fn from_array( data: Array<f64>, color_space: ColorSpace, ) -> Result<Self, NumRs2Error>

Creates an image from a pre-built Array and color space.

§Arguments
  • data - The array containing pixel data
  • color_space - The color space of the image
§Errors

Returns NumRs2Error::ValueError if the array shape is inconsistent with the color space

Source

pub fn width(&self) -> usize

Returns the width of the image in pixels.

Source

pub fn height(&self) -> usize

Returns the height of the image in pixels.

Source

pub fn color_space(&self) -> ColorSpace

Returns the color space of the image.

Source

pub fn data(&self) -> &Array<f64>

Returns a reference to the underlying array data.

Source

pub fn data_mut(&mut self) -> &mut Array<f64>

Returns a mutable reference to the underlying array data.

Source

pub fn channels(&self) -> usize

Returns the number of channels in the image.

Source

pub fn get_pixel( &self, row: usize, col: usize, channel: usize, ) -> Result<f64, NumRs2Error>

Gets a pixel value at the specified position.

For grayscale images, returns a single value. For RGB images, channel must be specified (0=R, 1=G, 2=B).

§Errors

Returns NumRs2Error::IndexError if coordinates are out of bounds

Source

pub fn set_pixel( &mut self, row: usize, col: usize, channel: usize, value: f64, ) -> Result<(), NumRs2Error>

Sets a pixel value at the specified position.

§Errors

Returns NumRs2Error::IndexError if coordinates are out of bounds

Source

pub fn to_grayscale(&self) -> Result<Self, NumRs2Error>

Converts an RGB image to grayscale using luminance weights.

Uses the ITU-R BT.709 formula: Y = 0.2126R + 0.7152G + 0.0722*B

§Errors

Returns NumRs2Error::InvalidOperation if the image is already grayscale

Source

pub fn clamp(&self) -> Self

Clamps all pixel values to the range [0.0, 1.0].

Source

pub fn to_vec(&self) -> Vec<f64>

Returns the flat pixel data as a vector.

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Image

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnsafeUnpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V