The input image canvas
Normalization parameters (mean, std, size)
The input tensor name for the ONNX model (default: 'input.1')
Object with input tensor ready for ONNX inference
When canvas context creation fails
const canvas = document.createElement('canvas');
// ... draw image to canvas ...
const params = {
mean: [0.485, 0.456, 0.406], // ImageNet mean
std: [0.229, 0.224, 0.225], // ImageNet std
size: [320, 320] // Model input size
};
const input = normalizeImage(canvas, params);
const results = await session.run(input);
Normalize image for ONNX model input.
Resizes the image to the target size and applies normalization using mean/std values. The normalization process includes dynamic scaling and ImageNet-style preprocessing. Output is in CHW format (channels, height, width) as required by ONNX models.