mt.opencv.ansi
Converting an RGB image into ANSI format.
Functions
to_ansi()
: Converts an RGB image into ANSI format for displaying on a terminal.get_screen_imgres()
: Gets the image resolution that fits the current screen, with some margin.
- mt.opencv.ansi.to_ansi(img, imgres=None, margin=7)
Converts an RGB image into ANSI format for displaying on a terminal.
Given an image, the function first determines the resolution to which the image will be resized. After resizing to the new resolution, each pixel is converted into a white space with a 24-bit color, using ANSI encoding. Note that each white space is viewed as a 4x8 block, encouraging the width to be twice larger than expected.
- Parameters:
img (numpy.ndarray) – an RGB uint8 image
imgres (list, optional) – pair of [width, height] defining the target resolution. If not specified, we estimate from the current terminal.
margin (int) – Only valid if imgres is None. The argument specifies the number of letters in both width and height to be preserved as margin
- Returns:
a multi-line string that can be printed to a terminal
- Return type:
str
- mt.opencv.ansi.get_screen_imgres(margin: int = 7) list
Gets the image resolution that fits the current screen, with some margin.
- Parameters:
margin (int) – Only valid if imgres is None. The argument specifies the number of letters in both width and height to be preserved as margin
- Returns:
imgres – pair of [max_width, max_height] defining the maximum resolution that fits the current screen
- Return type:
list