Convert JPEG from progressive to baseline losslessly

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.

Convert JPEG from progressive to baseline losslessly

Postby Nemo_bis » 2012-10-24T17:28:34+00:00

I hope this is the correct section, forgive me if it's not.

I need to convert some progressive/interlaced JPEGs to baseline format. A simple "convert" or "convert -interlace none" does it, but I've been told «I'm fairly certain that convert is performing a conversion from the DCT domain into the real space domain and then just recompress as a non-progressive JPG. This will indeed lead to round-off errors causing a degradation in image quality». Can the conversion be lossless?

Background: the conversion is for them to be more easily processable by imagemagick itself (interlaced images take too much memory to convert); I've considered "safe" for cheap processing by IM only JPEGs with SOF tag "0x0 = Baseline DCT, Huffman coding" and I'm trying to convert all the others (which are all interlaced in some way according to "identify -verbose" as well, it seems). Even more background here, probably not interesting.
Nemo_bis
 
Posts: 4
Joined: 2012-06-16T01:13:18+00:00

Re: Convert JPEG from progressive to baseline losslessly

Postby fmw42 » 2012-10-24T17:55:09+00:00

As I understand it, IM will decompress and recompress for a convert from jpg to jpg, even if you are not changing interlacing or progressive modes. You would need to use some non-IM tools, if there are any that allow for mode changes without decompression and recompression. see http://www.imagemagick.org/Usage/formats/#jpg_lossless

If I have misunderstood or there are JPG experts who know otherwise, feel free to correct my comments.
User avatar
fmw42
 
Posts: 14995
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Convert JPEG from progressive to baseline losslessly

Postby henrywho » 2012-10-25T06:57:37+00:00

Use jpegtran. I remember that it can do so in a lossless way.
henrywho
 
Posts: 187
Joined: 2011-08-17T06:46:40+00:00

Re: Convert JPEG from progressive to baseline losslessly

Postby Nemo_bis » 2012-10-25T08:35:50+00:00

henrywho wrote:Use jpegtran. I remember that it can do so in a lossless way.

Thank you, I didn't see anything in the docs but looks like a null transform works, like
Code: Select all
jpegtran in.jpg > out.jpg

or, to be safe:
Code: Select all
jpegtran -perfect in.jpg > out.jpg

It "works" as in it produces a non-interlaced image from an interlaced one (and three times faster than convert), but I'm not able to say if this has been lossless. I can assume it was?
Nemo_bis
 
Posts: 4
Joined: 2012-06-16T01:13:18+00:00

Re: Convert JPEG from progressive to baseline losslessly

Postby Dane Vandeputte » 2012-10-25T13:35:02+00:00

Nemo_bis wrote:It "works" as in it produces a non-interlaced image from an interlaced one (and three times faster than convert), but I'm not able to say if this has been lossless. I can assume it was?

Yes, it has been lossless. The -perfect isn't necessary in this case, but it doesn't hurt. Also, if you want to keep all of the original metadata intact, you should use -copy all. If you want to make sure that the resulting files are as small as possible, you can use -optimize, although the processing time may increase a bit.
Digital image processing and photography enthusiast :)
User avatar
Dane Vandeputte
 
Posts: 14
Joined: 2012-07-01T18:26:53+00:00
Location: Illinois, USA

Re: Convert JPEG from progressive to baseline losslessly

Postby Nemo_bis » 2012-10-25T13:38:14+00:00

Dane Vandeputte wrote:
Nemo_bis wrote:It "works" as in it produces a non-interlaced image from an interlaced one (and three times faster than convert), but I'm not able to say if this has been lossless. I can assume it was?

Yes, it has been lossless. The -perfect isn't necessary in this case, but it doesn't hurt. Also, if you want to keep all of the original metadata intact, you should use -copy all. If you want to make sure that the resulting files are as small as possible, you can use -optimize, although the processing time may increase a bit.

Thank you very much.
Nemo_bis
 
Posts: 4
Joined: 2012-06-16T01:13:18+00:00

Re: Convert JPEG from progressive to baseline losslessly

Postby Dane Vandeputte » 2012-10-25T20:00:11+00:00

Nemo_bis wrote:Thank you very much.

You're most welcome. :)
Digital image processing and photography enthusiast :)
User avatar
Dane Vandeputte
 
Posts: 14
Joined: 2012-07-01T18:26:53+00:00
Location: Illinois, USA


Return to Digital Image Processing

Who is online

Users browsing this forum: No registered users and 1 guest