Pillow: Value range of the HSV mode

Created on 13 Feb 2019  路  12Comments  路  Source: python-pillow/Pillow

What did you do?

When I tried to find is there a specific color point in the image, I find there is not clear comment in the pillow document.

What did you expect to happen?

I hope I could find the HSV value range in Pillow.

What actually happened?

I am not sure the value range of HSV in Pillow. I read the pillow document, but it only says the HSV model is 3*8 pixels, Hue, Saturation, Value color space. Unfortunately, there are different HSV models with different value range I found on google. That confused me.

Could you give more explanation in the document?

What are your OS, Python and Pillow versions?

  • OS: Windows 7
  • Python: 2.7
  • Pillow: 5.3.0

Pillow Concepts

Documentation

All 12 comments

Any thoughts on https://pillow.readthedocs.io/en/latest/reference/ImageColor.html?highlight=hsv#color-names?

Thanks for your help.

That page implies the value range of the HSV mode in Pillow is not CSS3-style, but the real value range is still unclear.

I did some tests.

image

image

The color should be red if it is CSS3-style, but the true value for red is

image

image

I guess the value range for HSV model is H: 0-255, S: 0-255, V:0-255, Maybe?

HSV isn't a mode for Image.new(mode, size, color):

image

Use something like this, where HSV is the usual 0-360, 0-100%, 0-100%:

from PIL import Image, ImageColor

Image.new(mode="RGB", size=(100, 100), color=ImageColor.getrgb("hsv(0, 100%, 100%)")).show()

image

HSV isn't a mode for Image.new(mode, size, color):

image

Use something like this, where HSV is the usual 0-360, 0-100%, 0-100%:

from PIL import Image, ImageColor

Image.new(mode="RGB", size=(100, 100), color=ImageColor.getrgb("hsv(0, 100%, 100%)")).show()

image

Thanks a lot. It is really helpful.

I wrote some extra code to show the problem.

image

image

When I used the getpixel in the HSV mode, the return values are between 0-255, which is not consistent with the common value ranges and this may lead to problems when users define color ranges. I think this difference should be pointed out in the document or update the getpixel for the HSV mode.

There's no such thing as HSV mode for Pillow images. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html

You cannot convert to HSV mode. This is documented: https://pillow.readthedocs.io/en/stable/reference/Image.html

You have an RGB mode image (print(im.mode)) and the getpixel values are RGB.

There's no such thing as HSV mode for Pillow images. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html

You cannot convert to HSV mode. This is documented: https://pillow.readthedocs.io/en/stable/reference/Image.html

You have an RGB mode image (print(im.mode)) and the getpixel values are RGB.

Sorry, my bad. I did not read the comment of convert carefully.

The page says HSV is supported by the current release
image

In practice, I found that if I convert the image to HSV mode it can work and the color value of the pixel is different from the value in RGB mode.
image

image

If I convert the same image to HSL mode, the code cannot run.
image

If Pillow images cannot convert to HSV, why the convert can work for HSV but cannot work for HSL? It is strange.

Sorry, it does indeed say HSV there! Will check again!

Any thoughts on pillow.readthedocs.io/en/latest/reference/ImageColor.html?highlight=hsv#color-names?

Thanks for your help.

That page implies the value range of the HSV mode in Pillow is not CSS3-style, but the real value range is still unclear.

I did some tests.

image

image

The color should be red if it is CSS3-style, but the true value for red is

image

image

I guess the value range for HSV model is H: 0-255, S: 0-255, V:0-255, Maybe?

Yes, that's right, all three are 0-255 here. Sorry for the confusion!

Fundamentally, anything in Pillow that鈥檚 not explicitly bigger or smaller is an 8bit per channel image.

Is there any reason to range between 0-255 on values that should be degrees and percentage ? Range from 0-1 or the actual range is fundamentally less confusing.. even if the doc try to fill that gap.

I suspect it would just have been for similarity with the other modes. Even if we did agree that HSV should be 0-1, Pillow values backwards compatibility highly, so I don't think a change like adjusting the value range for a mode would make it in, given that it otherwise works.

They're 0-255 because they're 8 bit ints, the same as all of the other multichannel images in Pillow.

Was this page helpful?
0 / 5 - 0 ratings