Howto convert jpg to tif losslessly (without recompressing)?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Laur

Howto convert jpg to tif losslessly (without recompressing)?

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Laur

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

Post 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.
Geremia
Posts: 2
Joined: 2011-07-04T18:35:42-07:00
Authentication code: 8675308

Re: Howto convert jpg to tif losslessly (without recompressi

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Howto convert jpg to tif losslessly (without recompressi

Post 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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Howto convert jpg to tif losslessly (without recompressi

Post 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.
Wolfgang Hugemann
Post Reply