1

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:

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:

convert Extravert.tif -grayscale Brightness  Extravert.png

But the resulting output image is not grayscale:

 identify Extravert.png
Extravert.png PNG 1113x1450 1113x1450+0+0 8-bit sRGB 2c 601B 0.000u 0:00.000

I also tried solutions suggested in this post, but still the output png is sRGB not grayscale.

How can I preserve the grayscale when converting from tif to png?

Extravert.tif (input), Extravert.png (output)

Thanks Tom

Tomasso
  • 693
  • 2
  • 9
  • 17
  • 1
    Have you tried `-define png:color-type=0`? – Mark Setchell Sep 04 '19 at 19:58
  • 1
    You realise too that there is an inevitable loss of quality trying to store a 32-bit greyscale image as PNG which only holds 16-bits maximum per channel? – Mark Setchell Sep 04 '19 at 20:17
  • Mark Setchell - Just tried "convert -quiet Extravert.tif -grayscale Brightness -define png:color-type=0 Extravert.png" - is that the right command? But I get the same result; Extravert.png PNG 1113x1450 1113x1450+0+0 8-bit sRGB 256c 1.97KB 0.000u 0:00.000 – Tomasso Sep 04 '19 at 20:22
  • Mark Setchell - How can I make 'convert' preserve 32-bits? Thanks! – Tomasso Sep 04 '19 at 20:24
  • 1
    The command I suggested with `color-type` seems to work fine for IM v7 at least. Can you upgrade? As regards storing 32-bits, I don't know what to suggest, you can't store numbers up to 4billion if you only have space for numbers up to 65,535 and that is the limit of PNG. – Mark Setchell Sep 04 '19 at 20:57
  • Unfortunately IM v7 binaries don't seem to be available for ubuntu 18.04. Building from source fails with problems in the way it's building libraries too. – Tomasso Sep 04 '19 at 21:42
  • fmw42, I added links to Extravert.tif (input) and Extravert.png (output) to the original post. I am running IM version 6.9.7-4; 'convert' does not complain about the -grayscale option. Adding "-type grayscale" option still yields sRGB according to the 'identify' command. But 'exifTool' does say "Color Type: Grayscale" - but also says "Bit Depth: 1" , whereas 'identify' says 8-bit. 'gimp' shows all values of zero in Extravert.png. – Tomasso Sep 04 '19 at 22:40

1 Answers1

1

I think your ImageMagick version 6.9.7.4 may be buggy or -grayscale was not fully developed by your version.

I cannot seem to get to your exact images at this time. Is there a problem with posting TIFs to Google Drive?

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

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.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Thanks fmw42 - can't find a more current patch for ubuntu 18.04.3, and unfortunately IM v7 build-from-source is not compiling properly on my machine either... – Tomasso Sep 05 '19 at 00:19
  • 1
    Why is it important that identify reports Gray? If the pixel data is gray is that not enough. In any case, ImageMagick reports interpreted information after reading the file into its internal format. If you want to know the actual format of the input, use EXIFTOOL – fmw42 Sep 05 '19 at 00:54