Jota
Jota

Reputation: 737

RGB to HSV wrong in colorsys?

I'm using the colorsys lib of Python:

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

output:(0.16666666666666666, 0, 208)

But this output is wrong, this is the true value using a RGB to HSV online converter: RGB to HSV

What's going on?

Upvotes: 4

Views: 6421

Answers (1)

Dan D.
Dan D.

Reputation: 74655

colorsys takes its values in the range 0 to 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.

You need to divide each of the values by 255. to get the expected output:

>>> colorsys.rgb_to_hsv(64/255., 208/255., 61/255.)
(0.3299319727891157, 0.7067307692307692, 0.8156862745098039)

Upvotes: 12

Related Questions