Page 1 of 1

convert grayscale tif to grayscale png not working

Posted: 2019-09-04T13:46:39-07:00
by Tomasso
I want to convert a tif grayscale image to png grayscale image with ImageMagick 'convert' utility (ImageMagick 6.9.7-4). The input file Extravert.tif has the following characteristics:

Code: Select all

identify Extravert.tif
Extravert.tif TIFF 1113x1450 1113x1450+0+0 32-bit Grayscale Gray 6.468MB 0.010u 0:00.009
I tried using convert -grayscale option as follows:

Code: Select all

convert Extravert.tif -grayscale Brightness  Extravert.png
But the resulting output image is not grayscale:

Code: Select all

identify Extravert.png
Extravert.png PNG 1113x1450 1113x1450+0+0 8-bit sRGB 2c 601B 0.000u 0:00.000
How can I preserve the grayscale when converting from tif to png?

Re: convert grayscale tif to grayscale png not working

Posted: 2019-09-04T13:59:17-07:00
by snibgo
Your images only has two colours. Do you really care how they are stored in the file?

IM doesn't say how the pixels are stored. If you want to know that, use exiftool.

Re: convert grayscale tif to grayscale png not working

Posted: 2019-09-04T14:13:35-07:00
by Tomasso
Hm, exifTool shows that the tif pixels are stored as 32-bit floating point - perhaps this is causing the conversion problem?
If so how can I convert the 32-bit float values to Int16 or Int32?

Code: Select all

Bits Per Sample                 : 32
Compression                     : Uncompressed
Photometric Interpretation      : BlackIsZero
Strip Offsets                   : (Binary data 11357 bytes, use -b option to extract)
Samples Per Pixel               : 1
Rows Per Strip                  : 1
Strip Byte Counts               : (Binary data 7249 bytes, use -b option to extract)
Planar Configuration            : Chunky
Sample Format                   : Float

Re: convert grayscale tif to grayscale png not working

Posted: 2019-09-04T14:51:53-07:00
by snibgo
You used exiftool on your input. But you care more about the output format, so use exiftool on the output.

Re: convert grayscale tif to grayscale png not working

Posted: 2019-09-04T15:44:32-07:00
by fmw42
I think your ImageMagick version 6.9.7.4 may be buggy or -grayscale was not fully developed by your version.

Where are your images?

So I made an example. The following works fine for me on IM 6.9.10.63 Q16 Mac OSX.

Code: Select all

convert logo: -colorspace gray logo.tif
identify logo.tif
logo.tif TIFF 640x480 640x480+0+0 8-bit Grayscale Gray 33344B 0.000u 0:00.000

convert logo.tif -grayscale brightness logo.png
identify logo.png
logo.png PNG 640x480 640x480+0+0 8-bit Gray 256c 32041B 0.000u 0:00.000
Can you upgrade your version of ImageMagick or get a more current patch. Note that sometimes Linux distributions only patch for security bugs. So that could possibly explain why your version does not work.

Re: convert grayscale tif to grayscale png not working

Posted: 2019-09-05T19:25:46-07:00
by 246246
Or your 32-bit float tiff is tiled format, that is patched very recently:
https://imagemagick.org/discourse-serve ... ff#p166078