colorsys 中的 RGB 到 HSV 错误?
RGB to HSV wrong in colorsys?
我正在使用 Python 的 colorsys 库:
import colorsys
colorsys.rgb_to_hsv(64, 208, 61)
output:(0.16666666666666666, 0, 208)
但是这个输出是错误的,这是使用 RGB 到 HSV 在线转换器的真实值:
RGB to HSV
怎么回事?
colorsys
取值范围 0
到 1
:
Coordinates in all of these color spaces are floating point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1.
您需要将每个值除以 255.
以获得预期输出:
>>> colorsys.rgb_to_hsv(64/255., 208/255., 61/255.)
(0.3299319727891157, 0.7067307692307692, 0.8156862745098039)
要避免此类错误,您可以使用 colorir。它在引擎盖下使用 colorsys,但允许格式规范:
>>> from colorir import sRGB
>>> sRGB(64, 208, 61).hsv(round_to=1)
HSV(118.8, 0.7, 0.8)
我正在使用 Python 的 colorsys 库:
import colorsys
colorsys.rgb_to_hsv(64, 208, 61)
output:(0.16666666666666666, 0, 208)
但是这个输出是错误的,这是使用 RGB 到 HSV 在线转换器的真实值: RGB to HSV
怎么回事?
colorsys
取值范围 0
到 1
:
Coordinates in all of these color spaces are floating point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1.
您需要将每个值除以 255.
以获得预期输出:
>>> colorsys.rgb_to_hsv(64/255., 208/255., 61/255.)
(0.3299319727891157, 0.7067307692307692, 0.8156862745098039)
要避免此类错误,您可以使用 colorir。它在引擎盖下使用 colorsys,但允许格式规范:
>>> from colorir import sRGB
>>> sRGB(64, 208, 61).hsv(round_to=1)
HSV(118.8, 0.7, 0.8)