decode_webp#
- torchcodec.decoders.decode_webp(source: str | Path | bytes | Tensor, *, mode: Literal['UNCHANGED', 'GRAY', 'GRAY_ALPHA', 'RGB', 'RGB_ALPHA'] | ImageReadMode = 'RGB', output_dtype: dtype | Literal['auto'] = torch.uint8) Tensor[source]#
Decode a WebP image into a
[N]CHWtensor.The output shape is
(C, H, W)for a still WebP and(N, C, H, W)for an animated one (N frames).Example
from torchcodec.decoders import decode_webp img = decode_webp("image.webp")
- Parameters:
source (str,
pathlib.Path, bytes, ortorch.Tensor) – The encoded WebP data: a path (strorpathlib.Path), abytesobject, or a 1-D uint8torch.Tensorof the raw encoded bytes.mode (str or ImageReadMode, optional) – Desired color mode of the output image. Can be one of
"UNCHANGED","GRAY","GRAY_ALPHA","RGB", or"RGB_ALPHA". Default is"RGB".output_dtype (torch.dtype or
"auto", optional) – desired dtype of the output image tensor. Accepted values aretorch.uint8(default),torch.uint16, and"auto". Since WebP is an 8-bit format,"auto"andtorch.uint8are equivalent.torch.uint16emulates a 16-bit output by scaling the 8-bit values to the full 16-bit range (0-255 -> 0-65535).
- Returns:
The decoded image, of shape
(C, H, W)(still) or(N, C, H, W)(animated).- Return type:
Examples using
decode_webp: