Gray to tiff does not preserve depth

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
tsbischof

Gray to tiff does not preserve depth

Post by tsbischof »

On openSUSE 11.2, using ImageMagick 6.5.4-8 or svn revision 2052.

I have some grayscale images stored as arrays of shorts which I would like to convert to tiff files. However, I have found that the depth of the tiff files created by ImageMagick is 1, rather than 16. Sample command:
convert -size 512x512 -depth 16 gray:test.dat test.tiff

(test.dat can be found at http://rapidshare.com/files/393886626/test.dat.html. The range of intensities is small, but we often use ImageJ for viewing and thus the scaling is performed automatically.)

Conversion to other formats (png, for example) does preserve the depth of the original gray image. Also, converting an image from png to gray to tiff preserves the depth, but tiff to gray to tiff fails:
convert -size 512x512 -depth 16 gray:test.dat good.png
convert -size 512x512 -depth 16 gray:test.dat ppm:- | convert ppm:- good.tiff
convert good.tiff gray:- | convert -depth 16 -size 512x512 gray:- bad.tiff

Is there something about the tiff format that I am missing, or is this a bug in ImageMagick itself? Thanks for any help.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Gray to tiff does not preserve depth

Post by magick »

The image file is 1048576 bytes whereas a 512x512 image at 16-bits requires 524288 bytes. Have you tried with a depth of 32? Have you tried adding the endian option (e.g. -endian msb).
tsbischof

Re: Gray to tiff does not preserve depth

Post by tsbischof »

Sorry about that, I meant to upload this file:
http://rapidshare.com/files/394259939/test.dat.html

As for using a depth of 32 or the endian options, I have not found a combination which converts the correctly (the original file has a short as the final two bytes of a four-byte block), so I wrote a routine to remove the unused bytes. This version (uploaded here) converts correctly to png, but conversion directly to tiff runs into issues.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Gray to tiff does not preserve depth

Post by magick »

Your image converts ok with the latest ImageMagick release:
  • convert -size 512x512 -depth 16 gray:test.dat ppm:- | convert ppm:- good.tiff
    convert -size 512x512 -depth 16 gray:test.dat bad.tiff
    compare -metric rmse bad.tiff good.tiff null:
    0 (0)
Our recommendation is to upgrade your release of ImageMagick.
Post Reply