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

    Parameters

    • canvas: HTMLCanvasElement

      The input image canvas

    • params: NormalizationParams

      Normalization parameters (mean, std, size)

    • inputName: string = 'input.1'

      The input tensor name for the ONNX model (default: 'input.1')

    Returns {
        [inputName: string]: ort.Tensor;
    }

    Object with input tensor ready for ONNX inference

    • [inputName: string]: ort.Tensor

    Throws

    When canvas context creation fails

    Example

    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);