Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python RGB array to HSL and back [duplicate]

Tags:

python

c

rgb

well i've seen some code to convert RGB to HSL; but how to do it fast in python.

Its strange to me, that for example photoshop does this within a second on a image, while in python this often takes forever. Well at least the code i use; so think i'm using wrong code to do it

In my case my image is a simple but big raw array [r,g,b,r,g,b,r,g,b ....]

I would like this to be [h,s,l,h,s,l,h,s,l .......]

Also i would like to be able to do hsl to rgb

the image is actually 640x 480 pixels; Would it require some library or wrapper around c code (i never created a wrapper) to get it done fast ?

like image 770
user613326 Avatar asked Sep 03 '26 19:09

user613326


1 Answers

For manipulating image data, many use the Python Imaging Library. However, it doesn't handle HSL colour. Luckily, Python comes with a library called colorsys. Here's an example of colorsys being used to convert between colour modes on a per-pixel level: http://effbot.org/librarybook/colorsys.htm

colorsys also provides a function to convert HSL to RGB: http://docs.python.org/library/colorsys.html

like image 153
Gavin Anderegg Avatar answered Sep 05 '26 09:09

Gavin Anderegg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!