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
impl Image
Sourcepub fn from_grayscale(
width: usize,
height: usize,
data: &[f64],
) -> Result<Self, NumRs2Error>
pub fn from_grayscale( width: usize, height: usize, data: &[f64], ) -> Result<Self, NumRs2Error>
Sourcepub fn zeros_grayscale(width: usize, height: usize) -> Self
pub fn zeros_grayscale(width: usize, height: usize) -> Self
Creates a grayscale image filled with zeros (black).
§Arguments
width- Image width in pixelsheight- Image height in pixels
Sourcepub fn from_array(
data: Array<f64>,
color_space: ColorSpace,
) -> Result<Self, NumRs2Error>
pub fn from_array( data: Array<f64>, color_space: ColorSpace, ) -> Result<Self, NumRs2Error>
Sourcepub fn color_space(&self) -> ColorSpace
pub fn color_space(&self) -> ColorSpace
Returns the color space of the image.
Sourcepub fn data_mut(&mut self) -> &mut Array<f64>
pub fn data_mut(&mut self) -> &mut Array<f64>
Returns a mutable reference to the underlying array data.
Sourcepub fn get_pixel(
&self,
row: usize,
col: usize,
channel: usize,
) -> Result<f64, NumRs2Error>
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
Sourcepub fn set_pixel(
&mut self,
row: usize,
col: usize,
channel: usize,
value: f64,
) -> Result<(), NumRs2Error>
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
Sourcepub fn to_grayscale(&self) -> Result<Self, NumRs2Error>
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
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.