[−][src]Trait ndarray_vision::core::traits::PixelBound
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