使用python将RGB值转换为等效的HSV值 [英] convert RGB values to equivalent HSV values using python
问题描述
我想使用python将RGB值转换为HSV。我得到了一些代码示例,结果是S和V值大于100.(例如: http://code.activestate.com/recipes/576554-covert-color-space-from-hsv-to-rgb- and-rgb-to-hsv / )。任何人都有一个更好的代码,将RGB转换为HSV,反之亦然
I want to convert RGB values to HSV using python. I got some code samples, which gave the result with the S and V values greater than 100. (example : http://code.activestate.com/recipes/576554-covert-color-space-from-hsv-to-rgb-and-rgb-to-hsv/ ) . anybody got a better code which convert RGB to HSV and vice versa
谢谢
推荐答案
您是否尝试过使用 colorsys 库?
colorsys模块在
RGB(红绿蓝)颜色空间中表示的颜色之间定义颜色
值的
双向转换
计算机显示器和另外三个
坐标系:YIQ,HLS(Hue
亮度饱和度)和HSV(Hue
饱和度值)
The colorsys module defines bidirectional conversions of color values between colors expressed in the RGB (Red Green Blue) color space used in computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness Saturation) and HSV (Hue Saturation Value)
示例(取自上面的链接):
Example (taken from the above link):
>>> import colorsys
>>> colorsys.rgb_to_hsv(.3, .4, .2)
(0.25, 0.5, 0.4)
>>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4)
(0.3, 0.4, 0.2)
这篇关于使用python将RGB值转换为等效的HSV值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!