colorsys中RGB到HSV错误?

2024-04-26 11:57:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是Python的colorsys库:

import colorsys
colorsys.rgb_to_hsv(64, 208, 61)

output:(0.16666666666666666, 0, 208)

但是这个输出是错误的,这是使用RGB到HSV在线转换器的真实值: RGB to HSV

怎么回事?在


Tags: toimportoutput错误rgbhsvcolorsys
1条回答
网友
1楼 · 发布于 2024-04-26 11:57:15

colorsys取值范围为01

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)

相关问题 更多 >