[Image-SIG] Examining the Palette and Image Properties
Lucas
rollbak at gmail.com
Mon Apr 6 05:33:02 CEST 2009
Hello,
I think what you have to do instead of img.info is to call img.mode,
this will give you the type of image (RGB, ARGB, P (indexed), etc).
In a 'P' mode image you can make the following:
myimg = im.palette
data = myimg.getdata()
data is a tuple with the following structure:
(mode, str)
mode: is the color mode, eg: RGB, ARGB...
list: is a string that contains the values of the palette colors, once
following each other, and you have to parse it by your own depending
on the mode.
eg:
print data
('RGB', "\x80\x00\x00\x00\x00\x00\x00\x80\x00.....")
The you can decode this with the following code:
decoded = [ord(component) for component in data[1]]
print decoded
[128, 0, 0, 0, 0, 0, 0, 128, 0,...]
because of the mode is RGB the colors of our palette are:
R G B
128, 0, 0
0, 0, 0
0, 128, 0
.....
I hope i was clear enough.
Lucas.
On Sat, Apr 4, 2009 at 9:43 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Suppose img is a PIL image. img.palette is then an instance, say, myimg. How
> do I display what is in it? mimg.hello_in_there()?
>
> Is the depth contained in the palette? PIL-handbook-2.pdf (1.1.3) has no
> PaletteImage description, which is where I would expect to find out about
> palette methods. Where other than looking in the PIL would I find a
> description? Maybe this is basic Python OOP as a means to find out? Doc?
>
> When I use img.info on various images I see in a program I'm using, I see
> this:
> # wagon.gif: {'compression': 'raw', 'dpi': (1, 1)}
> # sentintel image: {}
> # moon_surface.tif: {'compression': 'raw', 'dpi': (1, 1)}
> # v....bmp : {'compression': 0}
>
> sentinel image is an image created by the hardware that interfaces with the
> software, and is 640x480 by 8-bits. v....bmp is one of the output files from
> the h/w that I've saved as bmp. Is there a description somewhere of what
> the dictionary output contains? I guess it's sort of obvious, but do other
> formats have more?
>
> --
>
> Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
> (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
>
>
> The Obama Administration plans to double the production
> in solar energy from 1% to 2% of the total energy
> supply in the next few years. One nuclear reaction
> would do the same. Heard on Bill Wattenburg, KGO-AM
>
> "Less than all cannot satisfy Man." -- William Blake
>
>
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
--
Lucas Shrewsbury
----------------------------------------------------
Open Your Mind, Use Open Source
More information about the Image-SIG
mailing list