cutcutcodec.core.io.read_image
Read an image with opencv.
Classes
|
Decode an image. |
Functions
|
Read the image and make it compatible with Video Frame. |
Details
- class cutcutcodec.core.io.read_image.ContainerInputImage(filename: str | bytes | Path)[source]
Decode an image.
Attributes
- filenamepathlib.Path
The path to the physical file that contains the extracted image stream (readonly).
Examples
>>> from cutcutcodec.core.io.read_image import ContainerInputImage >>> from cutcutcodec.utils import get_project_root >>> (stream,) = ContainerInputImage(get_project_root() / "examples" / "logo.png").out_streams >>> stream.snapshot(0, (9, 9))[..., 3] tensor([[0.0000, 0.0415, 0.5152, 0.8748, 0.9872, 0.8744, 0.5164, 0.0422, 0.0000], [0.0418, 0.7853, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.7851, 0.0420], [0.5156, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.5141], [0.8749, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.8732], [0.9871, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.9861], [0.8745, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.8727], [0.5150, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.5137], [0.0417, 0.7838, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.7842, 0.0413], [0.0000, 0.0411, 0.5139, 0.8732, 0.9865, 0.8729, 0.5144, 0.0417, 0.0000]]) >>>
Initialise and create the class.
Parameters
- filenamepathlike
Path to the file to be decoded.
Raises
- cutcutcodec.core.exceptions.DecodeError
If it fail to extract any multimedia stream from the provided file.
- 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)