Question

I wanted to convert from rgb to hsv but the results seem to be unexpected

Following is the code

   import colorsys

   print colorsys.rgb_to_hsv(144, 190, 255)

and it prints following

    (0.5, 0, 255)

where I was expecting it to be

    (215,44,100)

or

    (215,0.44,1.0)

any idea???

Thanks a lot

Was it helpful?

Solution

The documentation of colorsys explains that all colour space coordinates are floating point numbers between 0.0 and 1.0 – rescale your values accordingly to get the desired results:

>>> h, s, v = colorsys.rgb_to_hsv(144/255., 190/255., 255/255.)
>>> 360 * h, 100 * s, 100 * v
(215.13513513513513, 43.529411764705884, 100.0)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top