Re: Image orientation and color information with PIL?

2005-07-20 Thread tvmaly
Jeff, this was exactly what I was looking for.  I wrote a script with
this code and it worked perfectly.

  Thanks 

 Ty

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image orientation and color information with PIL?

2005-07-18 Thread Ivan Van Laningham
Hi All--

[EMAIL PROTECTED] 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 BW 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/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image orientation and color information with PIL?

2005-07-18 Thread Jeff Epler
 i = Image.open(blue.jpg)
 i.size
(3008, 2000)
 i.mode
'RGB'

'RGB' is the value for color jpeg images.  I believe that for blackwhite
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/aethertool/disorient.py?rev=1.2content-type=text/vnd.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


pgpbJ5BO1Z3ui.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Image orientation and color information with PIL?

2005-07-18 Thread Simon Dahlbacka
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.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image orientation and color information with PIL?

2005-07-18 Thread Jeff Epler
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/eproj/msc2004/abs/m3zs2.htm
http://research.microsoft.com/research/pubs/view.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


pgpJZsejWH68l.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list