473,657 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7304
Hi All--

tv****@gmail.co m 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("blu e.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.i tems() 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+CXJd0 1MZaTXX0RApN5AJ 4+e+YZQ3S0y5KON R9g1gpIngkVtQCe LRPI
F//9CRC8z+igsVcTYy p8qZs=
=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+FLJd0 1MZaTXX0RAoB/AKCodOJCroYcizi q7xHzSfwthaR3rA CdEUqp
QfrvksnD6fQC5h0 dVqQUTys=
=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
10951
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 currently migrating to a new PC running XP. The charting application is hanging on a single line of code: Printer.Orientation = vbPRORLandscape It throws an error '484', "Problem getting information from the printer. Make sure printer is set up...
1
2596
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 topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
9
4086
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 need to rotate the image and the see the result everytime. For this my boss has given me suggestion to display only 20% of the image on window ,and rotation has to be applied to original copy.
5
9430
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 I print my reports to a file or directly to the printer, the orientation is landscape. This was set in the report itself using Designer | Printer Setup and setting the printer to landscape. When I send the report to the viewer, using the...
1
2972
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 the way I was doing it was to take every pixel and find the orientation of the block of pixels around it using sobel. And do this for every pixel. Then smooth it. But this is not working and maybe I am doing it completely wrong. Has anyone done...
3
2294
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 placed around the ball and which one of those images is displayed. Each pool cue image is in a slightly different orientation and the correct one is chosen to match the orientation of the cursor around the ball. Holding down the left mouse button...
1
12009
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
8304
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
2137
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 images stay over to the right rather than being in the middle over even in the same spacing as the wider images. The two images at the bottom are the examples Is there a way of having some information in the stylesheet to accomodate if is a...
0
8399
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
8312
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,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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
5632
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();...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2732
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
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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.