Skip to main content

AugOp

Enum AugOp 

Source
pub enum AugOp {
    RandomCrop {
        crop_size: usize,
    },
    CenterCrop {
        crop_size: usize,
    },
    HorizontalFlip {
        prob: f32,
    },
    Resize {
        target: usize,
    },
    ColorJitter {
        brightness: f32,
        contrast: f32,
        saturation: f32,
    },
    RandomGrayscale {
        prob: f32,
    },
    Normalize {
        mean: [f32; 3],
        std: [f32; 3],
    },
}
Expand description

Enum-dispatched augmentation operations — no dyn Trait, no heap boxing.

Each variant carries the hyperparameters it needs. Stochastic operations receive a mutable LcgRng reference at call time via AugOp::apply.

Variants§

§

RandomCrop

Randomly crop to [channels, crop_size, crop_size].

Fields

§crop_size: usize
§

CenterCrop

Deterministic centre crop to [channels, crop_size, crop_size].

Fields

§crop_size: usize
§

HorizontalFlip

Randomly flip the image horizontally with the given probability.

Fields

§prob: f32
§

Resize

Bilinear resize to [channels, target, target].

Fields

§target: usize
§

ColorJitter

Colour jitter: brightness, contrast, saturation perturbation magnitudes.

Fields

§brightness: f32
§contrast: f32
§saturation: f32
§

RandomGrayscale

Convert to grayscale with the given probability (RGB images only).

Fields

§prob: f32
§

Normalize

Channel-wise normalisation: (x - mean[c]) / std[c].

Fields

§mean: [f32; 3]
§std: [f32; 3]

Implementations§

Source§

impl AugOp

Source

pub fn apply( &self, img: &[f32], channels: usize, h: usize, w: usize, rng: &mut LcgRng, ) -> VisionResult<(Vec<f32>, usize, usize)>

Apply this augmentation to a CHW image.

§Parameters
  • img: flat [channels × h × w] input buffer.
  • channels: number of channels (e.g., 3 for RGB).
  • h, w: spatial height and width of the input image.
  • rng: mutable RNG for stochastic operations; deterministic ops ignore it.
§Returns

(new_img, new_h, new_w) — the transformed image and its (possibly updated) spatial dimensions. channels is never changed.

§Errors

Propagates errors from the underlying operation functions (invalid dimensions, mismatched buffers, non-positive std, etc.).

Trait Implementations§

Source§

impl Clone for AugOp

Source§

fn clone(&self) -> AugOp

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 AugOp

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for AugOp

§

impl RefUnwindSafe for AugOp

§

impl Send for AugOp

§

impl Sync for AugOp

§

impl Unpin for AugOp

§

impl UnsafeUnpin for AugOp

§

impl UnwindSafe for AugOp

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<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> 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.