[Image-SIG] ImagePalette class problem

Fredrik Lundh fredrik at pythonware.com
Wed Jun 6 11:19:37 CEST 2007

Francisco José Seva Mora wrote:

> Hello!! I'm trying to use the  ImagePalette class from PIL ( python 
> image library ) to load a dicom image that I have decoded. I read the 
> official documentation and many other articles from blogs and webs but 
> many of them are copies of the official documentation.
> I'm trying to use this class to set the right palette to the image 
> because I think the default palette  don't have  the  necesary   scale  
> to represent the image.

the easiest way to add a palette to an image is to create a mode "L" 
image, and then use the "putpalette" method:

     im = ...
     im.putpalette([r0, g0, b0, r1, b1, g1, ..., r255, g255, b255])

(you can use a 768-byte string as well).

hope this helps.


More information about the Image-SIG mailing list