Image printing#
- kornia.image.image_to_string(image, max_width=256)[source]#
Render one image tensor as an xterm-256 ANSI text string, without printing it.
text = image_to_string(image)takes a(3, H, W)RGB or(1, H, W)gray image and returns the text that shows it in a terminal. Each pixel is two spaces on the nearest xterm-256 background color, one line per image row. An image wider thanmax_widthpixels is first resized to that width.- Convention:
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.
The color of a pixel is the nearest of the 240 fixed xterm-256 colors (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.
The resize keeps the aspect ratio, so a line is at most
2 * 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:
See also
print_image(): prints the string, and also takes the path of an image file.Image.print(): prints anImage, converting BGR and channels-last data first.
- kornia.image.print_image(image, max_width=96)[source]#
Print an image tensor or an image file to the terminal in xterm-256 colors.
print_image(image)printsimage_to_string()of a(3, H, W)or(1, H, W)tensor, or of a file loaded withload_image()asImageLoadType.RGB8.
- Convention:
See the Convention block of
image_to_string(), which renders the image.
- 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:
See also
image_to_string(): returns the text instead of printing it.Image.print(): prints anImage, converting BGR and channels-last data first.