2

I use the following command in a script:

exiftran -a -i mypic.jpg

For some pictures, I get a wrong vertical offset, which is seen as a vertical line along the right border of rotated pictures. This happens with pictures taken with my phone (Galaxy Note 3).

If I open the un-rotated picture in gthumb, and ask to "rotate physically", I get this warning:

This transformation may introduce small image distortions along one or more edges, because the image dimensions are not multiples of 8.

I have also tried mogrify -auto-orient, which seems to work better.

Can someone explain why there is a vertical line on the right of some pictures rotated with exiftran?

  • 1
    I think you might need to try superuser. superuser.com/search?q=exiftran – MikeW Jul 17 '14 at 3:32
  • Why don't you just use nconvert? Never seen such an issue from it and before cameras did autorotation, I used it all the time. – Itai Jul 17 '14 at 3:55
  • It is either a bug in ExifTran, or maybe the camera is not totally standards compliant with its JPG output. I find a number of hits when googling for "lossless jpeg rotation", maybe you can try another tool. – Jeroen Kransen Jul 17 '14 at 5:16
2

The JPEG algorithm uses a combination of lossy and lossless steps. The algorithm breaks up an image into 8x8 blocks, known as Minimum Coding Units (MCU). If an image has dimensions that are not divisible by 8, MCUs along the right and bottom edges are padded. Each MCU is then processed through FFT/DCT (Fast Fourier Transform/Discrete Cosine Transform) and quantized. Quantization is the main lossy step. Then a series of lossless steps are performed, including lossless compression, are performed.

Lossless operations can be performed on JPEG by undoing the final lossless steps and performing lossless operations on the MCUs, such as rearranging them. If image dimensions are not divisible by 8 (or 16 if chroma subsampling is enabled), artifacts may appear along the edges because padded blocks will be along the wrong edge and the blocks that need padding won't be.

By default, exiftran discards these blocks. However, these blocks can be retained, and artifacts along the edges appear, if exiftran is called with the -np flag.

I suspect most digital cameras and cell phones produce images with dimensions that will not cause this problem because it makes optimal use of available resources to do so. This is the case for devices I have checked, made by Apple, Canon, FujiFilm, Lenovo, and Samsung.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.