Question: is rotating by 90, 180, 270 destructive
Question: is rotating by 90, 180, 270 destructive
i.e. is there quality loss when rotating "orthogonally"?
I understand it's inevitable when rotating by other "non-orthogonal" amounts, but theoretically, an image could be rotated without data loss when rotating by multiples of 90 degrees.
Can anybody confirm or deny how Image Magick works in this regard?
Thx,
R
I understand it's inevitable when rotating by other "non-orthogonal" amounts, but theoretically, an image could be rotated without data loss when rotating by multiples of 90 degrees.
Can anybody confirm or deny how Image Magick works in this regard?
Thx,
R
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Question: is rotating by 90, 180, 270 destructive
There is no quality loss when you begin and end with a lossless format. If you use a lossy format, such as jpeg, there can be loss simply by loading and saving an image. This is true for most image processing applications. A jpeg image that meets certain requirements can be rotated losslessly using specialized tools.
Re: Question: is rotating by 90, 180, 270 destructive
Subject format: jpeg.
So, if I understood you correctly, Image Magick will "re-jpeg the jpeg" when rotating by say 90 degrees, rather than "transposing" the data losslessly. i.e. it is not a "specialized tool" as per your definition.
Is that correct?
If so, do you know of such a specialized tool for windows (and/or mac-nix) command-line?
Rob
So, if I understood you correctly, Image Magick will "re-jpeg the jpeg" when rotating by say 90 degrees, rather than "transposing" the data losslessly. i.e. it is not a "specialized tool" as per your definition.
Is that correct?
If so, do you know of such a specialized tool for windows (and/or mac-nix) command-line?
Rob
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Question: is rotating by 90, 180, 270 destructive
IM decodes the jpeg into pixels, rotates, and codes into jpeg. This coding is always lossy. A lower-level tool that understands jpeg more intimately will twiddle the jpeg data to do the rotation. jpegtran is one such tool.
Four rotations in IM gives a difference of 2172.36 (0.0331481), ie 3.3%.
Four rotations in jpegtran gives a difference of 0.
Code: Select all
%IM%convert rose: rose.jpg
%IM%convert rose.jpg -rotate 90 r1.jpg
%IM%convert r1.jpg -rotate 90 r2.jpg
%IM%convert r2.jpg -rotate 90 r3.jpg
%IM%convert r3.jpg -rotate 90 r4.jpg
%IM%compare -metric RMSE rose.jpg r4.jpg NULL:
jpegtran -rotate 90 rose.jpg r1.jpg
jpegtran -rotate 90 r1.jpg r2.jpg
jpegtran -rotate 90 r2.jpg r3.jpg
jpegtran -rotate 90 r3.jpg r4.jpg
%IM%compare -metric RMSE rose.jpg r4.jpg NULL:
Four rotations in jpegtran gives a difference of 0.
snibgo's IM pages: im.snibgo.com
Re: Question: is rotating by 90, 180, 270 destructive
Awesome - thanks! (and I dunno why I didn't think to do the 4 rotation test - good thinking ).
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Question: is rotating by 90, 180, 270 destructive
But beware. I've just seen that the results r2.jpg and r3.jpg from jpegtran are wrong! It self-corrects for r4.jpg.
My copy of jpegtrans is rather old. Maybe the problem has been fixed in more recent versions.
My copy of jpegtrans is rather old. Maybe the problem has been fixed in more recent versions.
snibgo's IM pages: im.snibgo.com
Re: Question: is rotating by 90, 180, 270 destructive
Thanks again snibgo.
I am using the latest version of jpegtran (Windows .exe) and it seems to rotate OK, I think (?), but loses the icc profile in the process .
ICC profiles seem to be particularly problematic for many softwares, still, even in this supposedly modern age .
Cheers,
Rob
I am using the latest version of jpegtran (Windows .exe) and it seems to rotate OK, I think (?), but loses the icc profile in the process .
ICC profiles seem to be particularly problematic for many softwares, still, even in this supposedly modern age .
Cheers,
Rob
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Question: is rotating by 90, 180, 270 destructive
There have been bugs with jpg and icc profiles. You can search the forum with the link above for "jpg icc" in the bugs forum and find out. Here is one that was only recently fixed. viewtopic.php?f=3&t=23756&p=100831&hili ... cc#p100831
You do not say what version of IM you are using or I missed it. You should always identify your IM version and platform when asking questions. Also search the forum if you are having trouble.
You do not say what version of IM you are using or I missed it. You should always identify your IM version and platform when asking questions. Also search the forum if you are having trouble.
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Question: is rotating by 90, 180, 270 destructive
Try -copy all to keep profiles, etc.areohbee wrote: I am using the latest version of jpegtran (Windows .exe) and it seems to rotate OK, I think (?), but loses the icc profile in the process
rose is 70x46, which is not divisible by a 8 or 16 pixel jpeg block size. This makes it a bad test case. I think IM defaults to chroma subsampling resulting in a 16x8 block size.snibgo wrote: convert rose: rose.jpg
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Question: is rotating by 90, 180, 270 destructive
see http://www.imagemagick.org/Usage/formats/#jpg_write for the IM defaults and options for -sampling-factor for JPG
Re: Question: is rotating by 90, 180, 270 destructive
There we go - thanks GreenKoopa.Try -copy all to keep profiles, etc.
And thanks to everyone - you've been most helpful.
PS - I'm using IM v6.7.3 - 16 bits (win7/64) now, but I may upgrade soon if icc difficulties are all sorted out.
Cheers,
Rob