Converting from jpg to tif, then tif to tif ruins colors.

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
tryl

Converting from jpg to tif, then tif to tif ruins colors.

Post by tryl »

Hi

I need to run a lot of programs (ImageMagick and others) on the same jpg image, so I want to convert it to a tif as working format.

Running

Code: Select all

convert picture.jpg picture.tif
produces a perfect result. But if I then run

Code: Select all

convert picture.tif newpicture.tif
which should produce the same result, newpicture.tif is converted to something that looks like 16 colors.

When running the tif to tif conversion (which is run completely separate from the jpg to tif conversion) i get the error message:

Code: Select all

convert: Caution: quantization tables are too coarse for baseline JPEG. `JPEGLib'.
lwhistler
Posts: 23
Joined: 2010-09-15T15:33:29-07:00
Authentication code: 8675308

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by lwhistler »

Why not just copy the file?


cp picture.tif newpicture.tif

-------
tryl

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by tryl »

I want to run some operations on it (e.g. -colorspace gray), but this reduces the example to the simplest form.
lwhistler
Posts: 23
Joined: 2010-09-15T15:33:29-07:00
Authentication code: 8675308

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by lwhistler »

I'm not sure if this would work:


convert picture.jpg -colorspace gray picture.tif
lwhistler
Posts: 23
Joined: 2010-09-15T15:33:29-07:00
Authentication code: 8675308

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by lwhistler »

This is interesting:

http://www.imagemagick.org/Usage/formats/#tiff
and
http://www.imagemagick.org/Usage/formats/#jpg_lossless

Looks like lossless jpg is the way to go with ImageMagick, instead of tiff's.



----
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by Drarakel »

tryl wrote:When running the tif to tif conversion (which is run completely separate from the jpg to tif conversion) i get the error message:

Code: Select all

convert: Caution: quantization tables are too coarse for baseline JPEG. `JPEGLib'.
Are you sure that this warning comes from the second conversion (TIFF to TIFF), and not from the first conversion? With a current ImageMagick version, such a message can occur with certain JPG->TIFF conversions. But maybe you have an older ImageMagick version (or an older libtiff or jpeg library)...
Anyway: This is usually an effect of an input JPG having a very low quality. (With a current version, this happens if IM identifies a quality value of 23 or below.) The resulting TIFF should be still ok, but it's less compatible - some viewers might have problems with that.
What viewer did you use for these TIFF files? And: What ImageMagick version do you have (on which operating system)? If the version is old, then try to upgrade first.
tryl wrote:Running

Code: Select all

convert picture.jpg picture.tif
produces a perfect result.
Even if you had no error: I wouldn't recommend the above command line - at least if you use the TIFF files as intermediate format. ImageMagick usually tries to use the compression method and the 'quality value' from the input file for a conversion (if you don't specify a certain compression). JPG compression can also be used in TIFF files - thus a standard JPG->TIFF conversion will result in a lossy recompression (which degrades the quality). I recommend using a compression that's not lossy - e.g. the ZIP compression (for a low filesize):

Code: Select all

convert picture.jpg -compress zip -quality 90 picture.tif
If you don't care about the filesize of your intermediate files, but about speed, then just use no compression:

Code: Select all

convert picture.jpg -compress none picture.tif
tryl

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by tryl »

Drarakel wrote:I wouldn't recommend the above command line - at least if you use the TIFF files as intermediate format. ImageMagick usually tries to use the compression method and the 'quality value' from the input file for a conversion (if you don't specify a certain compression). JPG compression can also be used in TIFF files - thus a standard JPG->TIFF conversion will result in a lossy recompression (which degrades the quality). I recommend using a compression that's not lossy - e.g. the ZIP compression (for a low filesize):

Code: Select all

convert picture.jpg -compress zip -quality 90 picture.tif
If you don't care about the filesize of your intermediate files, but about speed, then just use no compression:

Code: Select all

convert picture.jpg -compress none picture.tif
Thank you Drarakel for this insight that I was completely unaware of. I don't care about file size and -compress none solves my problem perfectly.

Thank you very much!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Converting from jpg to tif, then tif to tif ruins colors

Post by anthony »

From IM Examples, Formats, TIFF
http://www.imagemagick.org/Usage/formats/#tiff
JPEG to TIFF conversion...

convert image.jpg image.tif

This will either save the image inside the TIFF file using JPEG compression
(whcih was inherited from the JPE input. Or it will error such as...

Error: "JPEG compression support not configured"

This is caused by the TIFF library not including JPEG compression support.

Either way THIS IS BAD.

You can get around this problem by changing the setting to use a different
compression algorithm:

convert image.jpg -compress zip image.tif
convert image.jpg -compress lzw image.tif
convert image.jpg +compress image.tif

WARNING: -compress Group4 with a TIFF works, but ONLY if you remove all
transparent and semi-transparent pixels from the image. Typically you can
make sure this is done the same way as JPEG images above, using
-background {color} -flatten
just before the final save.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply