gpt4 book ai didi

python - Tensorflow CIELAB 颜色空间边界

转载 作者:行者123 更新时间:2023-12-04 08:13:53 34 4
gpt4 key购买 nike

我有以下脚本,可以获取 RGB 图像并将其转换为 Lab 颜色空间:

import tensorflow as tf
import tensorflow_io as tfio

img = tf.io.read_file(tf.keras.utils.get_file("tf", "https://upload.wikimedia.org/wikipedia/commons/e/e5/TensorFlow_Logo_with_text.png"))
img = tf.image.decode_png(img, channels=3)
img = tf.image.resize(img, [512, 512])
lab = tfio.experimental.color.rgb_to_lab(img)

lab = lab.numpy()
lab.shape # (512, 512, 3)

lab[:, :, 0].min() # 3660.3594
lab[:, :, 0].max() # 9341.573

lab[:, :, 1].min() # -49.76082
lab[:, :, 1].max() # 4273.1514

lab[:, :, 2].min() # -1256.8489
lab[:, :, 2].max() # 6293.9043

Wiki CIELAB color space :

LAB space is three-dimensional, and covers the entire range of human color perception, or gamut. It is based on the opponent color model of human vision, where red/green forms an opponent pair, and blue/yellow forms an opponent pair. The lightness value, L*, also referred to as "Lstar," defines black at 0 and white at 100. The a* axis is relative to the green–red opponent colors, with negative values toward green and positive values toward red. The b* axis represents the blue–yellow opponents, with negative numbers toward blue and positive toward yellow.

The a* and b* axes are unbounded, and depending on the reference white they can easily exceed ±150 to cover the human gamut. Nevertheless, software implementations often clamp these values for practical reasons. For instance, if integer math is being used it is common to clamp a* and b* in the range of -128 to 127.

为什么不是 0 <= lab[:, :, 0].min() <= lab[:, :, 0].max() <= 100真的吗?

最佳答案

函数 tfio.experimental.color.rgb_to_lab 期望它的输入是一个在 0 和 1 之间归一化的 float 。

您可以调用 tf.image.convert_image_dtype 对您的图像进行归一化(如果您的输入是一个整数而您的目标输出是一个 float ,该函数将自动将其归一化到 0 到 1 之间)。

import tensorflow as tf
import tensorflow_io as tfio

img = tf.io.read_file(tf.keras.utils.get_file("tf", "https://upload.wikimedia.org/wikipedia/commons/e/e5/TensorFlow_Logo_with_text.png"))
img = tf.image.decode_png(img, channels=3)
img = tf.image.convert_image_dtype(img, dtype=tf.float32)
img = tf.image.resize(img, [512, 512])
lab = tfio.experimental.color.rgb_to_lab(img)

lab = lab.numpy()

并检查 L 维度:

>>> lab[:,:,0].min()
33.678085
>>> lab[:,:,0].max()
100.0

关于python - Tensorflow CIELAB 颜色空间边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65809222/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com