ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> image-sig
image-sig
[Image-SIG] Palette and alpha
by Andres Moreira other posts by this author
Oct 26 2009 11:49AM messages near this date
Re: [Image-SIG] tiff with 16bit/channel | Re: [Image-SIG] 64bit windows OS
Hi all, 

 I'm using the below code to extract colors, but now, I need to extract colours with 
 the alpha channel. 

 I've read the PIL Doc and googling a lot, and I didn't find any information of 
 how to load a RGBA palette, so the extractcolours method can couple with image
 alpha sections.
 
    def load_palette(colour_map):
        mapim = Image.open(colour_map)
        palette = [color[:3] for _, color in mapim.getcolors()]

        # Flatten colors to be accepted by PIL
        palette = tuple(reduce(lambda a, b: a+b, palette))

        # create palette
        self.impalette = Image.new("P", (1, 1)) 
        self.impalette.putpalette(palette)

    def extractcolours(filename):
        pilimage = Image.open(filename)
        im_quantized = pilimage.convert("RGB").quantize(palette=self.impalette)
        im_in_rgba = im_quantized.convert("RGBA", dither=self.dither)
        return im_in_rgba.getcolors()
     
 What I've get with this code for images with transparency is the list of colours, 
 and the one colour : (0,0,0,255) (and all the ohters colors with alpha = 255)

 The convert tool from Imagemagick, return me the list of colours with all the 
 non-(0,0,0) colours with alpha channel = 255 and (0,0,0,0). 
 So with this list, I can couple with the aplha sections removed from my results.

 It's possible to do this with PIL?

 Thanks a lot.

Andres
_______________________________________________
Image-SIG maillist  -  Image-SIG@[...].org
http://mail.python.org/mailman/listinfo/image-sig

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved