使用colorsys从RGB到HSV

2024-05-20 19:36:07 发布

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

我正在尝试制作一个跟踪程序,该程序获取图像并显示具有指定颜色的对象所在的位置:

示例:https://imgur.com/a/8LR40

要做到这一点,我正在使用RGB,但它是真的很难与它合作,所以我想把它转换成一个色调,以便更容易与之合作。我试图使用colorsys,但在做了一些研究后,我不知道它想要什么参数,它给了什么。我试着用colorizer.org找到一个匹配项,但是我得到了一些不连续的结果。

>>> import colorsys
>>> colorsys.rgb_to_hsv(45,201,18)
(0.3087431693989071, 0.9104477611940298, 201)

alredy colorsys并没有像文档中描述的那样工作,因为在https://docs.python.org/2/library/colorsys.html处,它说输出总是一个介于0和1之间的浮点数,但是值是201。这也是不可能的,因为在标准HSV中,该值介于0和100之间。

我的问题是: colorsys期望输入什么? 如何将输出转换为标准HSV?(色调=0-360,饱和度=0-100,值=0-100)


Tags: 对象httpsorg图像程序com示例参数
1条回答
网友
1楼 · 发布于 2024-05-20 19:36:07

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.

https://docs.python.org/3/library/colorsys.html

必须从0-255缩放到0-1,或者用255除以RGB值。如果使用python 2,请确保不要进行楼层划分。

相关问题 更多 >