473,765 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image python

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

Oct 1 '07 #1
1 1947
On Mon, Oct 01, 2007 at 11:21:09AM -0700, or*****@gmail.c om wrote:
hi
I want understanding pictures colorfull
for examle colorfull or black-white
image.google.co m 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("gra y.png")
im.mode
'L'
>>im = Image.open("col or.jpeg")
im.mode
'RGB'
>>im = Image.open("ano ther_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("col or.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(lambd a 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
4548
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 systems. I'd prefer to use something distributed with Python, if possible, but will install the library that makes this functionality easy as a second choice. Thanks! Scott --
2
2619
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 someone a suggestion how else I could write a little script that computes the total area of a large nuber of image files in a folder? I should check texturespace for 3D Models, and would like to avoid copy pasting them all into Photoshop...
9
2804
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 have tried several variations on passing this parameter to the DLL and I am not having much luck. This is going to call other functions later for OCR, but I want to get a simple one working first. Here is my code: (Very basic)
17
10041
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
4817
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 clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions:
8
5606
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 a raw data format used in astronomy. Anyway, I followed the example in the PIL documentation online, and I also had a look at the FITs image stub file included with PIL 1.1.5. I cooked up something that should work (or nearly work), but I keep...
5
6881
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" widget in Tkinter? Here is my first attempt with just trying to print out the image data: ----------------- def pasteImg(tgt): global clipboardEnabled if not clipboardEnabled: return
0
2049
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 Python and in the intricacies of image files has written a routine to decode originally the UK Landranger maps, so that they can be used with other mapping and GPS programs apart from the restricted Memory Map viewer. You can get the details in...
0
1463
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 managed size on click SET box to right of above line click positives (OK APPLY etc.) all way out, system will probably reboot
1
1975
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, I decided on python (seeing on how its easy to learn, and already on the phone), and for the server code I decided on PHP (that was also an easy decision). The problem I keep running into involves the image display: the data seems to be passed...
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.