JPEG compression for grayscale TIFF images does not work

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
zanderoc

JPEG compression for grayscale TIFF images does not work

Post by zanderoc »

When using JPEG compression inside a TIFF file format, grayscale images are unusually large, much larger than a color copy. This seems to be a BUG. We have used the following version of ImageMagick:

Code: Select all

Version: ImageMagick 6.6.1-4 2010-04-21 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
We have applied three conversion steps to the following three images:
  • fractal.color.tif - original color image in uncompressed TIFF format
  • fractal.gray.tif - derived grayscale image (from fractal.color.tif) in uncompressed TIFF format
  • fractal.gray.one-red-pixel.tif - fractal.gray.tif converted to rgb color format with one red pixel embedded
Using these images, we have converted them to (1) JPEG, (2) TIFF with JPEG compression and (3) pyramidal TIFF with JPEG compression using these commands:

Code: Select all

(1) convert IMAGE.tif -quality 70 IMAGE.jpg
(2) convert IMAGE.tif -format tiff -compress jpeg -quality 70 IMAGE.jpg.tif
(3) convert IMAGE.tif -define tiff:tile-geometry=128x128 -format tiff -compress jpeg -quality 70 ptif:IMAGE.jpg.pyr.tif
The resulting file sizes are as follows (listing re-sorted with original image first):

Code: Select all

-rw-r--r-- 1 anybody users 2359676 2010-04-22 12:30 fractal.color.tif
-rw-r--r-- 1 anybody users   59847 2010-04-22 12:31 fractal.color.jpg
-rw-r--r-- 1 anybody users  165257 2010-04-22 12:34 fractal.color.jpg.tif
-rw-r--r-- 1 anybody users   69211 2010-04-22 12:35 fractal.color.jpg.pyr.tif

-rw-r--r-- 1 anybody users  786806 2010-04-22 12:30 fractal.gray.tif
-rw-r--r-- 1 anybody users   53652 2010-04-22 12:33 fractal.gray.jpg
-rw-r--r-- 1 anybody users  787530 2010-04-22 12:33 fractal.gray.jpg.tif
-rw-r--r-- 1 anybody users  264474 2010-04-22 12:35 fractal.gray.jpg.pyr.tif

-rw-r--r-- 1 anybody users 2359690 2010-04-22 12:39 fractal.gray.one-red-pixel.tif
-rw-r--r-- 1 anybody users   55539 2010-04-22 12:43 fractal.gray.one-red-pixel.jpg
-rw-r--r-- 1 anybody users  168901 2010-04-22 12:43 fractal.gray.one-red-pixel.jpg.tif
-rw-r--r-- 1 anybody users   71303 2010-04-22 12:44 fractal.gray.one-red-pixel.jpg.pyr.tif
While the grayscale image converts well to JPEG, with the JPEG compressed TIFF file, there is no compression visible. With the pyramidal TIFF images, we did not get the necessary JPEG compression when the source was a grayscale image either. For reporting this bug, we used an image with relatively small image dimensions (1024x768). Creating a pyramidal TIFF with these dimensions resulted in a corrupted image. Images with larger dimensions (>4k x 4k) were processed fine (except for the JPEG compression bug, which still appears with larger pyramidal JPEG compressed TIFF files). I will create a new thread for this image corruption bug.
zanderoc

Re: JPEG compression for grayscale TIFF images does not work

Post by zanderoc »

No reply, yet? Anyone who can help?

Here is another example, that may demonstrate the issue better:

Code: Select all

-rw-r--r-- 1 anybody users 19621852 2010-04-26 12:52 4173699_00351.tif
-rw-r--r-- 1 anybody users 26705410 2010-04-26 13:19 4173699_00351.gray.jpg.pyr.tif
-rw-r--r-- 1 anybody users  8085488 2010-04-26 13:18 4173699_00351.color.jpg.pyr.tif
4173699_00351.tif is a grayscale uncompressed TIFF file (size 4844x4044 pixels). This has been converted to a pyramidal JPEG compressed image with the following two commands. Please note that after converting to RGB color and embedding one colored pixel, the image compresses as it should. In grayscale, it does not compress.

Code: Select all

convert 4173699_00351.tif -colorspace rgb -depth 8 -fill "#ff0000" -draw "point 1,1" -define tiff:tile-geometry=128x128 -format tiff -compress jpeg -quality 70 ptif:4173699_00351.color.jpg.pyr.tif
convert 4173699_00351.tif -define tiff:tile-geometry=128x128 -format tiff -compress jpeg -quality 70 ptif:4173699_00351.gray.jpg.pyr.tif
This behavior is not dependent on the pyramidal tiling of the image. The bug shows simply by compressing an image in JPEG and embedding this into a TIFF:

Code: Select all

convert 4173699_00351.tif -format TIFF -compress jpeg -quality 70 4173699_00351.gray.jpg.tif
convert 4173699_00351.tif -colorspace rgb -depth 8 -fill "#ff0000" -draw "point 1,1" -format tiff -compress jpeg -quality 70 4173699_00351.color.jpg.tif
This results in the following file sizes:

Code: Select all

-rw-r--r-- 1 anybody users 19621852 2010-04-26 12:52 4173699_00351.tif
-rw-r--r-- 1 anybody users 19621862 2010-04-26 13:26 4173699_00351.gray.jpg.tif
-rw-r--r-- 1 anybody users  5785757 2010-04-26 13:27 4173699_00351.color.jpg.tif
Again, the image with one colored pixel compresses really well, whereas the grayscale image does NOT compress.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: JPEG compression for grayscale TIFF images does not work

Post by magick »

Apologies. We think the problem is fixed in ImageMagick 6.6.1-5, the current release. Download it and let us know if you have further problems.
Post Reply