Page 1 of 1

Gray to tiff does not preserve depth

Posted: 2010-05-31T21:59:17-07:00
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.

Re: Gray to tiff does not preserve depth

Posted: 2010-06-01T05:45:52-07:00
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).

Re: Gray to tiff does not preserve depth

Posted: 2010-06-01T20:27:51-07:00
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.

Re: Gray to tiff does not preserve depth

Posted: 2010-06-02T06:14:13-07:00
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.