[][src]Trait ndarray_vision::core::traits::PixelBound

pub trait PixelBound {
    fn min_pixel() -> Self;
fn max_pixel() -> Self;
fn discrete_levels() -> Option<usize>; }

When working with pixel data types may have odd bitdepths or not use the full range of the value. We can't assume every image with u8 ranges from [0..255]. Additionally, floating point representations of pixels normally range from [0.0..1.0]. PixelBound is an attempt to solve this issue.

Unfortunately, type aliases don't really create new types so if you wanted to create a pixel with a reduced bound you'd have to create something like:

struct LimitedU8(u8);
impl PixelBound for LimitedU8 {
    fn min_pixel() -> Self {
        LimitedU8(16u8)
    }
     
    fn max_pixel() -> Self {
        LimitedU8(160u8)
    }
}

And then implement the required numerical traits just calling the
corresponding methods in `u8`

Required methods

fn min_pixel() -> Self

The minimum value a pixel can take

fn max_pixel() -> Self

The maximum value a pixel can take

fn discrete_levels() -> Option<usize>

Returns the number of discrete levels. This is an option because it's deemed meaningless for types like floats which suffer from rounding issues

Loading content...

Implementations on Foreign Types

impl PixelBound for f64[src]

impl PixelBound for f32[src]

impl PixelBound for u8[src]

impl PixelBound for u16[src]

impl PixelBound for u32[src]

impl PixelBound for u64[src]

impl PixelBound for u128[src]

impl PixelBound for i8[src]

impl PixelBound for i16[src]

impl PixelBound for i32[src]

impl PixelBound for i64[src]

impl PixelBound for i128[src]

Loading content...

Implementors

Loading content...