I'm trying to automate the enhancement of some images that are to be transfered to a digital frame. I have code in place that resizes, adds a date/time to the least-significant (least details) corner of the image and pastes together pairs of portrait images to avoid displaying a single portrait in the frame's 41:20 low resolution screen.
I've implemented a brightness-stretching filter for those pictures where the lighting wasn't so good, using the colorsys.rgb_to_hsv
function to calculate H, S, V bands, operating on the V one and then converting back to RGB before saving a JPEG in the digital frame. Obviously, the conversion takes a lot of time, even using itertools
tricks; I managed to improve things using psyco
.
However, I noticed an example for the PIL Image.convert
where RGB can be converted to XYZ color space using a 4×4 matrix as a second argument to the convert
method, and I got to wonder:
How can I convert RGB to HSV (and then HSV back to RGB) using a custom matrix in the convert
method call? (Minor rounding errors are not important in this case, so I don't mind that each band will be expressed as a series of 0…255 integers)
Thank you in advance.
ImageOps.autocontrast
function; however, I want to be able to expand the filter as needed (e.g. maybe spice up the saturation a little), and that is why I want a quick method for RGB↔HSV). - tzot