Page 1 of 1

Howto convert jpg to tif losslessly (without recompressing)?

Posted: 2009-03-02T07:16:17-07:00
by Laur
I'd like to convert some jpegs to tiffs (and vice versa), however when I tried the basic convert command the images were recompressed, causing quality loss. Since a tiff can use jpeg compression, it seems like it should be possible to put the existing jpeg stream in a tiff container with no recommpression (and associated quality loss). The reverse should be possible as well, i.e. losslessly convert a jpeg compressed tiff to a plain jpeg. Bonus points if all the EXIF data can be retained. Is it possible to do this with ImageMagick? If not, is there another tool which can do so? Or is this just impossible for some reason I'm not aware of?

Thanks for any help.

Re: Howto convert jpg to tif losslessly (without recompressing)?

Posted: 2009-03-02T20:57:36-07:00
by anthony
set -compress to something other then JPEG whcih it got from the JPEG image file. For example -compress None

Note however that as the image is in a JPEG already it already has experienced some image color loss.

Re: Howto convert jpg to tif losslessly (without recompressing)?

Posted: 2009-03-03T07:05:00-07:00
by Laur
I'm not sure I'm explaining this well. If I'm not mistaken -compress None will give me an uncompressed tif file, which is not what I want. -compress JPEG will give me a JPEG compressed tif, however it will first decompress the input jpg, then recompress it, causing an additional generation loss.

What I want to do is to take an existing jpeg and convert it to a jpeg compressed tif, but without any decompression or recompression. Basically just put the compressed jpeg data stream inside of a tiff wrapper. Is this possible? It seems like it ought to be.

Re: Howto convert jpg to tif losslessly (without recompressi

Posted: 2011-07-04T18:50:55-07:00
by Geremia
Just run convert as you normally would. It appears ImageMagick tries to avoid re-compression at all costs. I tried it on an example JPG and the resulting TIFF was about the same size. Run

Code: Select all

identify -verbose your_image  | grep "Compression"
where your_image is your original JPG or the resulting TIFF. You will see it says JPEG for both the JPG and the TIFF files.

Re: Howto convert jpg to tif losslessly (without recompressi

Posted: 2011-07-04T19:31:09-07:00
by fmw42
I am no expert on this, but as far as I know IM will decompress the jpeg (lossy) and recompress when using jpg compression in a tif. So you will always get losses. I don't know if there is any way to use IM to just repackage the jpg as part of a tiff. see such comments at http://www.imagemagick.org/Usage/formats/#jpg

Re: Howto convert jpg to tif losslessly (without recompressi

Posted: 2011-07-06T23:40:31-07:00
by whugemann
I then the recompression can currently not be avoided when using IM. There is a similar, more common problem, when you try to bind a bunch uf JPEGs to a PDF. However, for PDFs, there is a special solution in form of the program JPEGtoPDF http://www.compulsivecode.com/jpegtopdf.html. Possibly there is something equivalent for bundeling JPEG to TIFFs.