Tensorflow CIELAB 颜色 space 范围
Tensorflow CIELAB color space bounds
我有以下脚本,它以 RGB 格式拍摄图像并将其转换为 Lab 颜色 space:
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
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 之间归一化的浮点数。
您可以调用 tf.image.convert_image_dtype
对您的图像进行归一化(如果您的输入是整数而目标输出是浮点数,该函数会自动将其归一化到 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
我有以下脚本,它以 RGB 格式拍摄图像并将其转换为 Lab 颜色 space:
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
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 之间归一化的浮点数。
您可以调用 tf.image.convert_image_dtype
对您的图像进行归一化(如果您的输入是整数而目标输出是浮点数,该函数会自动将其归一化到 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