473,320 Members | 1,872 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,320 software developers and data experts.

Image orientation and color information with PIL?

Does anyone know if it is possible to determine if an image is
horizontal/vertical and color or black & white using the python image
library? I have been searching this news group and the information was
not all clear on this.

Best Regards

Ty

Jul 21 '05 #1
4 7252
Hi All--

tv****@gmail.com wrote:

Does anyone know if it is possible to determine if an image is
horizontal/vertical and color or black & white using the python image
library? I have been searching this news group and the information was
not all clear on this.


How are you going to determine the orientation of an image without
sophisticated image analysis? I suspect Adobe Photoshop can do it, but
I don't know for sure. You'd have to look for things like sky, or
clouds, overcast sky, people's faces, and so on and so forth. It'd be
cool to have this available in Python, but unless the F-bot is busier
than I thought and working behind the scenes using his time machine,
it's not there now.

If you write it I'll use it;-)

Color vs B&W ought to be easy, though, by analysing the color table, if
there is one, and/or image mode. Check the PIL documentation. If you
have only searched the newsgroup then you might have overlooked the
docs.

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/worksh...oceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
Jul 21 '05 #2
>>> i = Image.open("blue.jpg")
i.size (3008, 2000) i.mode 'RGB'

'RGB' is the value for color jpeg images. I believe that for black&white
images, i.mode is 'L' (luminosity).

If you want to determine whether an existing image is landscape or portrait,
then just compare i.size[0] (width) and i.size[1] (height).

If by "determine if an image is horizontal/vertical", you want to find
the orientation data recorded by some digital cameras, you can do that
with PIL 1.1.4. According to the release notes for 1.1.4,
+ Added experimental EXIF support for JPEG files. To extract EXIF
information from a JPEG file, open the file as usual, and call the
"_getexif" method. If successful, this method returns a dictionary
mapping EXIF TIFF tags to values. If the file does not contain EXIF
data, the "_getexif" method returns None.

The "ExifTags" module contains a dictionary mapping tags to tag
names.

This interface will most likely change in future versions.

The exif tag 274 is Orientation. The values you'll see most often are 1
(Normal), 6 and 8 (90 and 270 degree rotations). Orientation can also encode
180 degree rotation, as well as any of the four rotations combined with a
mirror operation.
[k for (k,v) in ExifTags.TAGS.items() if v == 'Orientation'] [274] e = i._getexif()
if e: print e[274]

1

I have written a standalone Python module that reads and changes the EXIF orientation data. You can view it here:
http://unpy.net/cgi-bin/viewcvs.cgi/...viewcvs-markup
It is available under the terms of the GNU GPL.

Here's another page about EXIF orientation data:
http://sylvana.net/jpegcrop/exif_orientation.html

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFC2+CXJd01MZaTXX0RApN5AJ4+e+YZQ3S0y5KONR9g1g pIngkVtQCeLRPI
F//9CRC8z+igsVcTYyp8qZs=
=e3lg
-----END PGP SIGNATURE-----

Jul 21 '05 #3
if you mean that you want to figure out which way the image is
depending on the actual data in the image, then you'll most likely get
to do the image processing yourself, on the other hand, if you are
talking jpegs from a relatively new camera then I suppose that you
should be able to get that info by looking at the EXIF information.
AFAIK you can read exif with PIL, but not write.

Jul 21 '05 #4
On Mon, Jul 18, 2005 at 10:55:42AM -0600, Ivan Van Laningham wrote:
How are you going to determine the orientation of an image without
sophisticated image analysis? There is research on automatic image
orientation detection. [...] If you write it I'll use it;-)


There's research going on in this area. Here are a few papers:
http://www.dcs.shef.ac.uk/teaching/e.../abs/m3zs2.htm
http://research.microsoft.com/resear...aspx?pubid=918
there are probably many others.

I considered implementing one of these algorithms back in 2003 or so,
but instead I bought a digital camera with an orientation sensor.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFC2+FLJd01MZaTXX0RAoB/AKCodOJCroYciziq7xHzSfwthaR3rACdEUqp
QfrvksnD6fQC5h0dVqQUTys=
=0SYI
-----END PGP SIGNATURE-----

Jul 21 '05 #5

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

Similar topics

1
by: Bruce Adams | last post by:
I am using VB6 SP6. I have an application that prints charts. Specifically, it prints line charts of plant process information nightly. The code is a mix of API calls and Printer methods. I am...
1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
9
by: Deepa | last post by:
Hi All, I'm facing problem displaying image of size 5000X5000 .My window size is smaller than image size so i'm not able to see the complete image.i can use scroll bars to view the image but i...
5
by: Robert Schuldenfrei | last post by:
Hi Again, Forgive me for posting this again, but old items seem to get little review. I thought I could adjust the viewer properties without any further aid from the NG, but I was wrong. When...
1
by: Keith Bell | last post by:
I am trying to find the orientation image of a fingerprint so that I can later enhance the print and then be able to extract the minutiae points with the direction of the minutiae points. Basically...
3
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is...
1
by: sthrudel | last post by:
Hello! I'm programmatically inserting a navigation asp menu to a page, like this: // Create new Menu Menu menu = new Menu(); // Create new MenuItem MenuItem mainItem = new MenuItem();
6
by: jesper_lofgren | last post by:
Hi, I wonder if its possible to show and hide a image with javascipt. I want the image to disapear from bottom and up very smooth, maybe under 3-4sec. Is it possible ? any tips ? Thanks
6
by: RoseW | last post by:
This is a collection of images with its own style sheet to create the hover over the thumbnail and the larger image appears. http://www4.webng.com/chesleyhs/images/planting/Planting.html Narrow...
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
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...
1
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
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.