random_shift_batch

Function random_shift_batch 

Source
pub fn random_shift_batch(
    images: &[f32],
    batch_size: usize,
    channels: usize,
    height: usize,
    width: usize,
    pad: usize,
    seed: u64,
) -> Result<Vec<f32>, RloxError>
Expand description

Random shift: pad image with zeros, then crop a random (H, W) window.

For each image in the batch, a random offset (dy, dx) is sampled uniformly from [0, 2*pad]. The output pixel at (y, x) is taken from the padded image at (y + dy, x + dx), which corresponds to the original image pixel at (y + dy - pad, x + dx - pad) if in bounds, or zero otherwise.

§Arguments

  • images - flat (B * C * H * W) f32 array
  • pad - number of zero-pad pixels on each side
  • seed - ChaCha8 RNG seed for reproducibility

§Returns

New flat array of same length as input.