Tensorflow CIELAB 色彩空间边界

pie*_*ipi 3 python rgb cielab tensorflow tensorflow2.0

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

\n
import tensorflow as tf\nimport tensorflow_io as tfio\n\nimg = tf.io.read_file(tf.keras.utils.get_file("tf", "https://upload.wikimedia.org/wikipedia/commons/e/e5/TensorFlow_Logo_with_text.png"))\nimg = tf.image.decode_png(img, channels=3)\nimg = tf.image.resize(img, [512, 512])\nlab = tfio.experimental.color.rgb_to_lab(img)\n\nlab = lab.numpy()\nlab.shape  # (512, 512, 3)\n\nlab[:, :, 0].min()  # 3660.3594\nlab[:, :, 0].max()  # 9341.573\n\nlab[:, :, 1].min()  # -49.76082\nlab[:, :, 1].max()  # 4273.1514\n\nlab[:, :, 2].min()  # -1256.8489\nlab[:, :, 2].max()  # 6293.9043\n
Run Code Online (Sandbox Code Playgroud)\n

维基 CIELAB 色彩空间

\n
\n

LAB 空间是三维的,涵盖了人类色彩感知的整个范围或色域。它基于人类视觉的对手色模型,其中红色/绿色形成对手对,蓝色/黄色形成对手对。亮度值 L*,也称为“Lstar”,定义黑色为 0,白色为 100。a* 轴相对于 green\xe2\x80\x93red 对手颜色,负值朝向绿色,正值朝向绿色走向红色。b*轴代表蓝色\xe2\x80\x93黄色对手,负数朝向蓝色,正数朝向黄色。

\n

a* 和 b* 轴是无界的,并且根据参考白色,它们可以轻松超过 \xc2\xb1150 以覆盖人类色域。然而,出于实际原因,软件实现通常会限制这些值。例如,如果使用整数数学,通常会将 a* 和 b* 限制在 -128 到 127 的范围内。

\n
\n

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

\n

Les*_*rel 5

该函数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()
Run Code Online (Sandbox Code Playgroud)

并检查L尺寸:

>>> lab[:,:,0].min()
33.678085
>>> lab[:,:,0].max()
100.0
Run Code Online (Sandbox Code Playgroud)