Discussion:
PIL: jpeg comment
Gerrit Holl
2003-12-23 22:17:24 UTC
Permalink
Hi,

how do I read a JPEG comment with the Python Imaging Library?

yours,
Gerrit Holl.
--
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/
--
http://mail.python.org/mailman/listinfo/python-list
Jeff Kunce
2004-01-02 04:20:19 UTC
Permalink
I don't know for sure, but try looking in the "app" attribute (a
dictionary) of an image object. For example:
im = Image.open('myimage.jpg')
print im.app
EXIF data is stored there, so maybe comments are, too

--Jeff
-----Original Message-----
On Behalf Of Gerrit Holl
Sent: Tuesday, December 23, 2003 4:17 PM
Subject: [Image-SIG] PIL: jpeg comment
Hi,
how do I read a JPEG comment with the Python Imaging Library?
yours,
Gerrit Holl.
--
http://people.nl.linux.org/~gerrit/english/
_______________________________________________
http://mail.python.org/mailman/listinfo/image-sig
_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Fredrik Lundh
2004-01-02 17:12:27 UTC
Permalink
Post by Jeff Kunce
I don't know for sure, but try looking in the "app" attribute (a
im = Image.open('myimage.jpg')
print im.app
EXIF data is stored there, so maybe comments are, too
this has been added in 1.1.5, but earlier versions ignore the comment
markers. here's a patch:

==== //modules/pil/PIL/JpegImagePlugin.py#6 - f:\pythonware\modules\pil\PIL\JpegImagePlugin.py ====
@@ -87,6 +89,15 @@
else:
self.info["adobe_transform"] = adobe_transform

+def COM(self, marker):
+ #
+ # Comment marker. Store these in the APP dictionary.
+
+ s = self.fp.read(i16(self.fp.read(2))-2)
+
+ self.app["COM"] = s # compatibility
+ self.applist.append(("COM", s))
+
def SOF(self, marker):
#
# Start of frame marker. Defines the size and mode of the
@@ -208,7 +219,7 @@
0xFFFB: ("JPG11", "Extension 11", None),
0xFFFC: ("JPG12", "Extension 12", None),
0xFFFD: ("JPG13", "Extension 13", None),
- 0xFFFE: ("COM", "Comment", Skip)
+ 0xFFFE: ("COM", "Comment", COM)
}

</F>




_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Chris Barker
2004-01-26 17:54:22 UTC
Permalink
HI all,

is it possible , with {PIL (or any other Python-based tool) to do simple
manipulations to a JPEG, without decompressing it. What I'm imagining is
simply rotation and cropping, at the moment.

My understanding of JPEG compression is that if you compress and
de-compress multiple times, more information is lost each time. If I
understand this right, it seems a shame to degrade an image just to
rotate or crop it.

As an example, I'm imagining a python version of jpegr jpegtrans/jpegcrop:

http://sylvana.net/jpegcrop/

thanks,

-Chris
--
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

***@noaa.gov


_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Aaron Optimizer Digulla
2004-01-26 18:24:40 UTC
Permalink
How about calling jpegtrans via system()?
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.philmann-dark.de/

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Chris Barker
2004-01-26 19:30:06 UTC
Permalink
Post by Aaron Optimizer Digulla
How about calling jpegtrans via system()?
That's what I'm doing at the moment, but I'm hoping for a more self
contained, cross platfrom approach.

-Chris
--
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

***@noaa.gov


_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Chris Cogdon
2004-01-26 19:45:50 UTC
Permalink
Post by Chris Barker
My understanding of JPEG compression is that if you compress and
de-compress multiple times, more information is lost each time. If I
understand this right, it seems a shame to degrade an image just to
rotate or crop it.
The way that I understand JPEG is that the encoding for any particular
pixel depends on 'state' that is set up from the previous pixels. In
other words, if you were to crop off 1 or 2 pixels at the left hand
side of the image, all the following pixels MUST be re-encoded... which
means you get the re-compression that you were trying to avoid.

Doubly so for rotations.

In my view, JPEG images were never intended to be re-edited.
--
("`-/")_.-'"``-._ Chris Cogdon <***@cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL


_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Smurf
2004-01-26 20:35:05 UTC
Permalink
Hi,
Post by Chris Cogdon
The way that I understand JPEG is that the encoding for any particular
pixel depends on 'state' that is set up from the previous pixels. In
other words, if you were to crop off 1 or 2 pixels at the left hand
side of the image, all the following pixels MUST be re-encoded... which
means you get the re-compression that you were trying to avoid.
Doubly so for rotations.
JPEG is based on 8x8 cells. (Hence the blocky artefacts.)

So you can in fact chop them by 8-pixel boundaries, and 90-degree rotate
them by swapping the coefficients in the individual blocks as well as
the blocks themselves, and probably some other minor stuff.

JPEG2000, now, that's a wholly different kettle of fish.
--
Matthias Urlichs | noris network AG | http://smurf.noris.de/

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Chris Cogdon
2004-01-26 22:35:19 UTC
Permalink
Post by Smurf
Hi,
Post by Chris Cogdon
The way that I understand JPEG is that the encoding for any particular
pixel depends on 'state' that is set up from the previous pixels. In
other words, if you were to crop off 1 or 2 pixels at the left hand
side of the image, all the following pixels MUST be re-encoded... which
means you get the re-compression that you were trying to avoid.
Doubly so for rotations.
JPEG is based on 8x8 cells. (Hence the blocky artefacts.)
So you can in fact chop them by 8-pixel boundaries, and 90-degree rotate
them by swapping the coefficients in the individual blocks as well as
the blocks themselves, and probably some other minor stuff.
I don't think it's as simple as that.

Firstly, even within the 8x8 cells, you need to rotate THAT as an
element, meaning the association within the surrounding pixels is
changed.

Secondly, there is SOME 'holistic information' kept from cell to cell,
or at least across the entire picture; I've seen corrupted JPEGs where
the 'base colour' after a particular point has gone wildly awry.

So... while I think it's a great goal, I believe doing editing beyond
simply adding or subtracting profile information cannot be achieved
without decoding then encoding again.
--
("`-/")_.-'"``-._ Chris Cogdon <***@cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL


_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Smurf
2004-01-27 01:44:34 UTC
Permalink
Hi,
Post by Chris Cogdon
Post by Smurf
them by swapping the coefficients in the individual blocks as well as
the blocks themselves, and probably some other minor stuff.
I don't think it's as simple as that.
Firstly, even within the 8x8 cells, you need to rotate THAT as an
element, meaning the association within the surrounding pixels is
changed.
That's what I believe I said.
Post by Chris Cogdon
So... while I think it's a great goal, I believe doing editing beyond
simply adding or subtracting profile information cannot be achieved
without decoding then encoding again.
jpegtools can do it, so it's evidently possible.
(I didn't say it was easy. :- / )
--
Matthias Urlichs | noris network AG | http://smurf.noris.de/

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
David Smith
2004-01-28 06:34:30 UTC
Permalink
Post by Chris Cogdon
Post by Chris Cogdon
In
other words, if you were to crop off 1 or 2
Post by Chris Cogdon
pixels at the left hand
Post by Chris Cogdon
side of the image, all the following pixels MUST
be re-encoded...
Post by Chris Cogdon
Post by Chris Cogdon
which
means you get the re-compression that you were
trying to avoid.

True.
Post by Chris Cogdon
Post by Chris Cogdon
Doubly so for rotations.
If the image is rotated 90 degrees CCW, the new
horizontal coefficients are the old vertical, while
the new vertical coefficients have to encode a mirror
reversal of the old horizontal coefficients. I don't
know whether this can be done without changing
quantized coefficients.
Post by Chris Cogdon
Secondly, there is SOME 'holistic information' kept
from cell to cell,
or at least across the entire picture; I've seen
corrupted JPEGs where
the 'base colour' after a particular point has gone
wildly awry.
That's true of any losslessly compressed file that
gets corrupted in transmission.

Jpeg's information loss consists of quantizing and
thresholding the coefficients in the 8x8 block. The
compression (entropy encoding) of those coefficients
(which uses context from previously encoded blocks)
proceeds without further loss.

HTH, but I don't claim to be an expert.

David Smith


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
David Smith
2004-01-28 06:42:46 UTC
Permalink
Post by David Smith
Post by Chris Cogdon
Doubly so for rotations.
If the image is rotated 90 degrees CCW, the new
horizontal coefficients are the old vertical, while
the new vertical coefficients have to encode a
mirror
reversal of the old horizontal coefficients. I
don't
know whether this can be done without changing
quantized coefficients.
Come to think of it, mirror reversal causes 1-d DCT
coefficients to be negated, suggesting rotation can be
done without further loss. But 2-d coeffs, I'm still
not sure.

David Smith


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig

Joel Rodrigues
2004-01-01 07:12:10 UTC
Permalink
Hi,

The best option in Python may be to use EXIF.py (& exiftool.py) from

http://home.cfl.rr.com/genecash/digital_camera.html


Cheers & Happy New Year !
- joel
Post by Gerrit Holl
Hi,
how do I read a JPEG comment with the Python Imaging Library?
yours,
Gerrit Holl.
--
http://people.nl.linux.org/~gerrit/english/
_______________________________________________
http://mail.python.org/mailman/listinfo/image-sig
_____________________________________________________________________
Envie de discuter en "live" avec vos amis ? T�l�charger MSN Messenger
http://www.ifrance.com/_reloc/m la 1�re messagerie instantan�e de France


_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Loading...