convert grayscale tif to grayscale png not working

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
Tomasso
Posts: 3
Joined: 2019-09-04T12:00:51-07:00
Authentication code: 1152

convert grayscale tif to grayscale png not working

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert grayscale tif to grayscale png not working

Post 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.
snibgo's IM pages: im.snibgo.com
Tomasso
Posts: 3
Joined: 2019-09-04T12:00:51-07:00
Authentication code: 1152

Re: convert grayscale tif to grayscale png not working

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert grayscale tif to grayscale png not working

Post by snibgo »

You used exiftool on your input. But you care more about the output format, so use exiftool on the output.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert grayscale tif to grayscale png not working

Post 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.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: convert grayscale tif to grayscale png not working

Post by 246246 »

Or your 32-bit float tiff is tiled format, that is patched very recently:
https://imagemagick.org/discourse-serve ... ff#p166078
Post Reply