Image printing#
- kornia.image.image_to_string(image, max_width=256)[source]#
Obtain the closest xterm-256 approximation string from an image torch.Tensor.
Each pixel is shown with the nearest of the 240 fixed xterm-256 colours (codes 16-255, the 6x6x6 cube and the gray ramp) by RGB distance, measured from its unrounded 0-255 value; codes 0-15 are defined by the terminal and are not used.
- Convention:
The image is \((C, H, W)\) with 1 or 3 channels. A float image is read in [0, 1] and an integer one in [0, 255], so integer 255 and float 1.0 print alike; a value outside the range raises.
Each pixel prints as two spaces on its background colour, one text line per image row. An image wider than
max_widthpixels is first resized tomax_widthpixels wide, keeping its aspect ratio, so a line is at most2 * max_widthterminal columns wide.
- Parameters:
- Raises:
ImageError – if the tensor is not an image with 1 or 3 channels, such as
(H, W)(also aValueError).ShapeError – if a tensor with 1 or 3 channels is not
(C, H, W), such as a batch (also aValueError).ValueCheckError – if a float tensor has values outside [0, 1], or an integer one outside [0, 255].
- Return type:
- kornia.image.print_image(image, max_width=96)[source]#
Print an image to the terminal.
- Convention:
See the Convention block of
image_to_string(), which renders the image;max_widthdefaults to 96 here and to 256 there. A path is loaded withload_image()asImageLoadType.RGB8.
- Parameters:
- Raises:
TypeError – if
imageis neither a path nor a tensor.ImageError – if the tensor is not an image with 1 or 3 channels, such as
(H, W)(also aValueError).ShapeError – if a tensor with 1 or 3 channels is not
(C, H, W), such as a batch (also aValueError).ValueCheckError – if a float tensor has values outside [0, 1], or an integer one outside [0, 255].
FileNotFoundError – if the path does not exist. Other errors of
kornia.io.load_image()pass through.
- Return type: