cutcutcodec.core.io.read_image.read_image

cutcutcodec.core.io.read_image.read_image(filename: str | bytes | Path) Tensor[source]

Read the image and make it compatible with Video Frame.

Parameters

filenamepathlike

The pathlike of the image file.

Returns

imagetorch.Tensor

The image in float32 of shape (height, width, channels).

Raises

cutcutcodec.core.exceptions.DecodeError

If it fails to read the image.

Examples

>>> from cutcutcodec.core.io.read_image import read_image
>>> from cutcutcodec.utils import get_project_root
>>> for file in sorted((get_project_root().parent / "media" / "image").glob("image.*")):
...     image = read_image(file)
...     print(f"{file.name}: {tuple(image.shape)}")
...
image.avif: (64, 64, 3)
image.bmp: (64, 64, 3)
image.exr: (64, 64, 3)
image.heic: (64, 64, 3)
image.jp2: (64, 64, 3)
image.jpg: (64, 64, 3)
image.kra: (64, 64, 3)
image.pbm: (64, 64, 1)
image.pgm: (64, 64, 1)
image.png: (64, 64, 3)
image.pnm: (64, 64, 3)
image.ppm: (64, 64, 3)
image.psd: (64, 64, 3)
image.ras: (64, 64, 3)
image.sgi: (64, 64, 3)
image.tiff: (64, 64, 3)
image.webp: (64, 64, 3)
image.xbm: (64, 64, 1)