def image_to_string(image: Tensor, max_width: int = 256) -> str:
    """Obtain the closest xterm-256 approximation string from an image tensor.

    The tensor shall be either 0~1 float type or 0~255 long type.

    Args:
        image: an RGB image with shape :math:`3HW`.
        max_width: maximum width of the input image.

    """
    KORNIA_CHECK_IS_IMAGE(image, None, raises=True)
    KORNIA_CHECK_SHAPE(image, ["C", "H", "W"])

    if image.dtype not in [float16, float32, float64]:
        image = image / 255.0  # In case of resizing.

    if image.shape[-1] > max_width:
        image = kornia.geometry.resize(image, (image.size(-2) * max_width // image.size(-1), max_width))

    image = (image * 255).long()

    res = ""
    for y in range(image.size(-2)):
        for x in range(image.size(-1)):
            r, g, b = image[:, y, x]
            h = f"{r:2x}{g:2x}{b:2x}"
            short, _ = rgb2short(h)
            res += f"\033[48;5;{short}m  "
        res += "\033[0m\n"
    return res
Obtain the closest xterm-256 approximation string from an image tensor.

    The tensor shall be either 0~1 float type or 0~255 long type.

    Args:
        image: an RGB image with shape :math:`3HW`.
        max_width: maximum width of the input image.

    
kornia/utils/image_print.py