471,624 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

image python

I want understanding pictures colorfull
for examle colorfull or black-white
image.google.com there are understand it .Can I understand it

Oct 1 '07 #1
1 1853
On Mon, Oct 01, 2007 at 11:21:09AM -0700, or*****@gmail.com wrote:
I want understanding pictures colorfull
for examle colorfull or black-white
image.google.com there are understand it.
i'm not sure if i understand your question. assuming you want to decide if
an image has only grayscale or multi-channel color data you could use
the python image library

>>from PIL import Image
im = Image.open("gray.png")
>>im = Image.open("color.jpeg")
>>im = Image.open("another_gray.jpeg")

but this doesn't tell you if color.jpeg really uses non-gray colors...

if you really want to do an expensive search, if an RGB image contains
only gray colors, you could do something like that:
>>im = Image.open("color.jpeg")

im.getcolors() returns a list like [(color_count, (red, green, blue)),

to only select the channel values one could do:
>>colors = set(lambda cv: cv[1], im.getcolors())
lets define a gray color as a color with all three color channels having the
same value like (30, 30, 30). to detect if a sequence has only equal items
one could create a set of this sequence and see how many items the set
contains afterwards:
>>set((30, 30, 30))
>len(set((30, 30, 30)))

to check if an rgb image uses only grayscale colors we can do
>>map(lambda cv: len(set(cv[1])), im.getcolors())
[1, 1, 1, 1, ....
the returned list contain only 1's if there are only gray values in the

to easyly show this we can again create a set from this list:
>>set(map(lambda cv: len(set(cv[1])), im.getcolors()))

so "im" is an grayscale image even though it has three channels.

this method does not always work:
- with indexed image data,
- with another definition/understanding of "gray" pixels

but maybe PIL can help you anyway!


Florian Schmidt // www.fastflo.de
Oct 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Scott Brady Drummonds | last post: by
2 posts views Thread by haddock | last post: by
9 posts views Thread by Chris Jankowski | last post: by
17 posts views Thread by PyPK | last post: by
8 posts views Thread by Chris Dewin | last post: by
8 posts views Thread by jbrewer | last post: by
5 posts views Thread by exhuma.twn | last post: by
reply views Thread by norseman | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.