Want to convert images into HSL format

Fredrik Lundh fredrik at pythonware.com
Mon Mar 18 17:27:06 CET 2002


"F. GEIGER" wrote:

> PIL can supply me with RGB data of an image. Does anybody know, how I can
> PIL have to transform this into the HSL (aka HSI) model?
>
> I'm new to image processing, but if I understand the chapter Introducint
> PIL -> Concepts -> Mode right, HSL is not mentioned there. Well, I have to
> admit, the only two color modes of the mentioned ones I understand are RGB
> and CMYK.

PIL doesn't support HLS images.

if you only need HLS values for individual pixels, you can use
the colorsys module in Python's standard library:

>>> import Image
>>> im = Image.open("lenna.im")
>>> im.mode
'RGB'
>>> im.getpixel((0, 0))
(226, 161, 119)
>>> import colorsys
>>> colorsys.rgb_to_hls(*[x/255.0 for x in im.getpixel((0, 0))])
(0.065420560747663545, 0.67647058823529416, 0.64848484848484833)

see the library reference for details.

</F>





More information about the Python-list mailing list