Page 1 of 1

Grayscale too dark

Posted: 2016-04-15T13:19:07-07:00
by honkifyoulikeme
Once again the same issue. Convering grayscale PNM to PNG makes the image dark. Apparently messed up colorspace conversion (linear vs. non linear).

All I want is the EXACT pixel values in the PNM to also be available in the PNG.

I've found

This: viewtopic.php?f=4&t=21269
and this: https://www.imagemagick.org/discourse-s ... hp?t=21275

However, no solutions proposed in those threads of work for me:

convert in.pnm -colorspace sRGB out.png
convert in.pnm -colorspace RGB -colorspace out.png

out.png is always darker.

Current shitty workaround:

convert in.pnm -gamma 2.2002200220022003 out.png

where 2.2 is 1 / 0.4545. While this is close, it doesn't give me the exact pixel values. I really, really, really, really need the EXACT values, no conversion nonsense. How can I do this? I would like to attach example files, but apparently I can't in this forum...

Re: Grayscale too dark

Posted: 2016-04-15T13:22:07-07:00
by honkifyoulikeme
I've uploaded a tar.gz file with all the image examples to pastebin: http://pastebin.com/tgWrnbCt

Grab it (the content between the "start" and "end" lines) and do

$ openssl base64 -d <in.txt >out.tar.gz
$ tar xfvz out.tar.gz

Re: Grayscale too dark

Posted: 2016-04-15T14:26:03-07:00
by fmw42
What version of IM and what platform? Grayscale has changed over the years from non-linear to linear and back to non-linear. See viewtopic.php?f=4&t=21269. PNM (PGM) I believe is linear gray. See http://www.imagemagick.org/script/formats.php

try

Code: Select all

convert image.pnm -set colorspace RGB -colorspace sRGB image.png

Re: Grayscale too dark

Posted: 2016-04-15T16:44:11-07:00
by snibgo
honkifyoulikeme wrote:All I want is the EXACT pixel values in the PNM to also be available in the PNG. ... I really, really, really, really need the EXACT values, no conversion nonsense.
With current versions of IM, what you read is what you'll get. Are your values linear RGB or non-linear sRGB? After reading, set the colourspace accordingly: "-set colorspace sRGB" or whatever. This won't change values.