Thanks a lot. I thought there had to be one, but I never found it. This will come in very handy
Espen, >There is a function for this. from the handbook: >ImageOps.colorize(image, black, white) => image > >Colorize grayscale image. The black and white arguments should be RGB >tuples or color names; this function calculates a colour wedge mapping >all black pixels in the source image to the first colour, and all >white pixels to the second colour. > >call it with your color for black and white for white, it accepts all >"standard" color specifications, such as "#ff2253" or (255, 0, 0). > >On Thu, Feb 11, 2010 at 3:50 AM, <jcup...@gmail.com> wrote: >> On 10 February 2010 11:01, Espen Moe-Nilssen <es...@medialog.no> wrote: >>> We are making an open source project, http://plone.org/products/subskins >>> I have been trying over and over again to find a way to let PIL colorize an >>> image. >>> It should work like this: >>> 1) I have a greyscale image >>> 2) A color is selected, for example "#123456" >>> 3) The image is colorized in this way: >>> Whatever was white is still white >>> Whatever was black (100%) is now "#123456" >>> Whaterver was grey (50%) is now 50% of "#123456" >>> I have tried a lot of different approaches, but the colors always come out >>> too dark. Is there a way to do this ? >> >> You need to split the image into luminance (your greyscale image) and >> colour (the constant colour you want to apply). >> >> If you imagine the RGB space as a cube, the neutral axis (all the grey >> colours) is a straight line from (0, 0, 0) to (255, 255, 255). What >> you want to do is translate that line (ie. keep the angle of the thing >> the same, just translate the whole line up/down/left/right/fwd/back) >> so that it passes through #123456 instead. Any bits that go over 255 >> or under 0 need to be clipped. >> >> This is easy in CIELAB space, but still OK in RGB. >> >> John >> _______________________________________________ >> Image-SIG maillist - image-...@python.org >> http://mail.python.org/mailman/listinfo/image-sig >> -- Espen Moe-Nilssen Grieg Medialog AS _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig