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: Path | str | bytes)[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 >>> image = get_project_root() / "media" / "image" / "logo.png" >>> (stream,) = ContainerInputImage(image).out_streams >>> stream.snapshot(0, (9, 9))[..., 3] # alpha layer 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: Path | str | bytes) tuple[Tensor, Colorspace][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).
- colorspaceColorspace
The color space in which the image is defined. No conversion performed.
Raises¶
- cutcutcodec.core.exceptions.DecodeError
If it fails to read the image.
Notes¶
Does not care about colorspace, no conversions performed.
Examples¶
>>> from cutcutcodec.core.io.read_image import read_image >>> from cutcutcodec.utils import get_project_root >>> for file in sorted((get_project_root() / "media" / "image").glob("image.*")): ... image, colorspace = read_image(file) ... print(f"{file.name}: {image.shape}, {colorspace}") ... image.avif: torch.Size([64, 64, 3]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') image.bmp: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.exr: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'linear') image.heic: torch.Size([64, 64, 3]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') image.jp2: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.jpg: torch.Size([64, 64, 3]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') image.kra: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.pbm: torch.Size([64, 64, 1]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') image.pgm: torch.Size([64, 64, 1]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') image.png: torch.Size([64, 64, 4]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.pnm: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.ppm: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.psd: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.ras: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.sgi: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.tiff: torch.Size([64, 64, 3]), Colorspace("r'g'b'", 'bt709', 'iec61966-2-1, iec61966_2_1') image.webp: torch.Size([64, 64, 3]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1') image.xbm: torch.Size([64, 64, 1]), Colorspace("y'pbpr", 'bt709', 'iec61966-2-1, iec61966_2_1')