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.
Nemo_bis
Posts: 4
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Convert JPEG from progressive to baseline losslessly

Postby Nemo_bis » 2012-10-24T17:28:34-07: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.

User avatar
fmw42
Posts: 15296
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: Convert JPEG from progressive to baseline losslessly

Postby fmw42 » 2012-10-24T17:55:09-07: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.

henrywho
Posts: 187
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Convert JPEG from progressive to baseline losslessly

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

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

Nemo_bis
Posts: 4
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Re: Convert JPEG from progressive to baseline losslessly

Postby Nemo_bis » 2012-10-25T08:35:50-07: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?

User avatar
Dane Vandeputte
Posts: 14
Joined: 2012-07-01T18:26:53-07:00
Authentication code: 13
Location: Illinois, USA

Re: Convert JPEG from progressive to baseline losslessly

Postby Dane Vandeputte » 2012-10-25T13:35:02-07: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 :)

Nemo_bis
Posts: 4
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Re: Convert JPEG from progressive to baseline losslessly

Postby Nemo_bis » 2012-10-25T13:38:14-07: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.

User avatar
Dane Vandeputte
Posts: 14
Joined: 2012-07-01T18:26:53-07:00
Authentication code: 13
Location: Illinois, USA

Re: Convert JPEG from progressive to baseline losslessly

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

Nemo_bis wrote:Thank you very much.

You're most welcome. :)
Digital image processing and photography enthusiast :)


Return to “Digital Image Processing”

Who is online

Users browsing this forum: No registered users and 0 guests