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].
CenterCrop
Deterministic centre crop to [channels, crop_size, crop_size].
HorizontalFlip
Randomly flip the image horizontally with the given probability.
Resize
Bilinear resize to [channels, target, target].
ColorJitter
Colour jitter: brightness, contrast, saturation perturbation magnitudes.
RandomGrayscale
Convert to grayscale with the given probability (RGB images only).
Normalize
Channel-wise normalisation: (x - mean[c]) / std[c].
Implementations§
Source§impl AugOp
impl AugOp
Sourcepub fn apply(
&self,
img: &[f32],
channels: usize,
h: usize,
w: usize,
rng: &mut LcgRng,
) -> VisionResult<(Vec<f32>, usize, usize)>
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.).