pub struct ImagePreprocessor { /* private fields */ }Expand description
Builder for an image preprocessing pipeline.
See the module-level docs for the intended flow. An instance is cheap to clone so a single pre-built preprocessor can be shared across threads.
Implementations§
Source§impl ImagePreprocessor
impl ImagePreprocessor
Sourcepub fn new(target_width: u32, target_height: u32) -> Self
pub fn new(target_width: u32, target_height: u32) -> Self
Create a new preprocessor for a given output size.
Sourcepub fn with_pixel_layout(self, layout: PixelLayout) -> Self
pub fn with_pixel_layout(self, layout: PixelLayout) -> Self
Set the input pixel layout. Default is PixelLayout::Rgb.
Sourcepub fn with_tensor_layout(self, layout: TensorLayout) -> Self
pub fn with_tensor_layout(self, layout: TensorLayout) -> Self
Set the output tensor layout. Default is TensorLayout::Nchw.
Sourcepub fn with_input_range(self, range: InputRange) -> Self
pub fn with_input_range(self, range: InputRange) -> Self
Set the scalar range of the source image. Default is InputRange::U8.
Sourcepub fn with_imagenet_normalization(self) -> Self
pub fn with_imagenet_normalization(self) -> Self
Apply ImageNet mean [0.485, 0.456, 0.406] and std [0.229, 0.224, 0.225].
Sourcepub fn target_width(&self) -> u32
pub fn target_width(&self) -> u32
Target width in pixels.
Sourcepub fn target_height(&self) -> u32
pub fn target_height(&self) -> u32
Target height in pixels.
Sourcepub fn process_u8_rgb(
&self,
pixels: &[u8],
src_w: u32,
src_h: u32,
) -> MlResult<Vec<f32>>
pub fn process_u8_rgb( &self, pixels: &[u8], src_w: u32, src_h: u32, ) -> MlResult<Vec<f32>>
Process a raw u8 RGB(3-channel) buffer of size src_w * src_h * 3.
The output is a flattened Vec<f32> containing a single image
(no batch dimension). Call ImagePreprocessor::batch_shape to
learn the logical shape.
§Errors
Returns MlError::Preprocess if:
pixels.len() != src_w * src_h * 3,- either dimension (source or target) is zero.
Sourcepub fn batch_shape(&self) -> Vec<usize>
pub fn batch_shape(&self) -> Vec<usize>
Return the logical shape of the output tensor with a leading
batch dim of 1. Matches the flat buffer returned by
ImagePreprocessor::process_u8_rgb.
Trait Implementations§
Source§impl Clone for ImagePreprocessor
impl Clone for ImagePreprocessor
Source§fn clone(&self) -> ImagePreprocessor
fn clone(&self) -> ImagePreprocessor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ImagePreprocessor
impl RefUnwindSafe for ImagePreprocessor
impl Send for ImagePreprocessor
impl Sync for ImagePreprocessor
impl Unpin for ImagePreprocessor
impl UnsafeUnpin for ImagePreprocessor
impl UnwindSafe for ImagePreprocessor
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
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 more