473,241 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

image python

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

Oct 1 '07 #1
1 1924
On Mon, Oct 01, 2007 at 11:21:09AM -0700, or*****@gmail.com wrote:
hi
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
http://www.pythonware.com/products/pil/

example:
>>from PIL import Image
im = Image.open("gray.png")
im.mode
'L'
>>im = Image.open("color.jpeg")
im.mode
'RGB'
>>im = Image.open("another_gray.jpeg")
im.mode
'L'

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.mode
'RGB'

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))
set([30])
>len(set((30, 30, 30)))
1

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
image.

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

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!

flo.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Scott Brady Drummonds | last post by:
Can anyone recommend the easiest way of generating thumbnail images using a Python library? I've seen that the Python Image Library (PIL) seems to do this but it isn't installed on my available...
2
by: haddock | last post by:
hi all Is it possible to access the size (with and height) of a .tga image in python? From the documentation I would say no, but I'm pretty new to python... if the answer really is no, has...
9
by: Chris Jankowski | last post by:
Hi all, I am still new to using Python, so bare with me. I am trying to call a DLL from my program to use some of it's functions. The only parameter is supposed to be a pointer to an image. I...
17
by: PyPK | last post by:
Hi I am looking for a simple tiff Image reader/writer in python.Can anyone point me to the right one.
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
8
by: jbrewer | last post by:
I'm trying to read in a FITs image file for my research, and I decided that writing a file decoder for the Python imaging library would be the easiest way to accomplish this for my needs. FITs is...
5
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text"...
0
by: Independent | last post by:
Python programmers may find the application to decoding an encrypted map image format known as Memory Map to produce a standard PNG image file interesting. Someone obviously very well versed in...
0
by: norseman | last post by:
Daniel de Sousa Barros wrote: ================================================ Click Start/settings/control panel/system/advanced/settings(in \ performance area)/advanced/change set System...
1
by: zandrew | last post by:
Hello there everyone. For a summer project I'm doing, I have to use a phone to pass an image I've taken (on the phone) to a dedicated server I've made on a local ubuntu machine. For the upload code,...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.