I want to adjust the colour levels of an image in python. I can use any python library that can easily be installed on my Ubuntu desktop. I want to do the same as ImageMagick’s -level ( http://www.imagemagick.org/www/command-line-options.html#level ). PIL (Python Image Library) doesn’t seem to have it. I have been calling convert on the image and then reading in the file back again, but that seems wasteful. Is there a better / faster way?
I want to adjust the colour levels of an image in python. I can
Share
If I understood correctly the
-leveloption of ImageMagick, then thelevel_imagefunction I provide should do what you want.Two things to note:
The code:
If there is some way to do the RGB→HSV conversion (and vice versa) using PIL, then one can split into the H, S, V bands, use the
.pointmethod of the V band and convert back to RGB, speeding up the process by a lot; however, I haven’t found such a way.