Skip to main content

sam2_preprocess_image

Function sam2_preprocess_image 

Source
pub fn sam2_preprocess_image(rgb: &[u8], h_in: usize, w_in: usize) -> Vec<f32>
Expand description

Square-resize an RGB u8 image to 1024×1024 (bilinear, no aspect- ratio preservation), /255, then ImageNet-normalise. Returns a contiguous [3, 1024, 1024] NCHW f32 buffer.

Matches SAM2Transforms in the reference exactly: Resize((1024, 1024)) (PIL bilinear) → ToTensor (/255) → Normalize(mean=[0.485,0.456,0.406], std=[0.229,0.224,0.225]).