def upscale_image(
    image: torch.Tensor,
    size: tuple,
    mode: ImageUpscaleMode = ImageUpscaleMode.PADDING,
) -> torch.Tensor:
    """Upscale image to desired size using padding or interpolation.

    Args:
        image: Input image tensor
        size: Target size as ``(height, width)``
        mode: Upscaling mode, either ``"padding"`` or ``"interpolation"``

    Returns:
        torch.Tensor: Upscaled image

    Examples:
        >>> image = torch.rand(1, 3, 512, 512)
        >>> upscaled = upscale_image(image, (555, 555), "padding")
        >>> upscaled.shape
        torch.Size([1, 3, 555, 555])

        >>> upscaled = upscale_image(image, (555, 555), "interpolation")
        >>> upscaled.shape
        torch.Size([1, 3, 555, 555])
    """
    image_h, image_w = image.shape[2:]
    resize_h, resize_w = size

    if mode == ImageUpscaleMode.PADDING:
        pad_h = resize_h - image_h
        pad_w = resize_w - image_w

        image = F.pad(image, [0, pad_w, 0, pad_h])
    elif mode == ImageUpscaleMode.INTERPOLATION:
        image = F.interpolate(input=image, size=(resize_h, resize_w))
    else:
        msg = f"Unknown mode {mode}. Only padding and interpolation is available."
        raise ValueError(msg)

    return image
Upscale image to desired size using padding or interpolation.

    Args:
        image: Input image tensor
        size: Target size as ``(height, width)``
        mode: Upscaling mode, either ``"padding"`` or ``"interpolation"``

    Returns:
        torch.Tensor: Upscaled image

    Examples:
        >>> image = torch.rand(1, 3, 512, 512)
        >>> upscaled = upscale_image(image, (555, 555), "padding")
        >>> upscaled.shape
        torch.Size([1, 3, 555, 555])

        >>> upscaled = upscale_image(image, (555, 555), "interpolation")
        >>> upscaled.shape
        torch.Size([1, 3, 555, 555])
    
src/anomalib/data/utils/tiler.py