Page 1 of 1
[solved] png and gamma value
Posted: 2014-07-08T05:29:10-07:00
by thomas12
edit: subject changed to "png and gamma value"
----------------
here we discussed about PNG images with wrong byte order
viewtopic.php?f=2&t=24818
We can simple change the byte order with the new switch png:swap-bytes (thanks to glennrp)
Code: Select all
> convert -define png:swap-bytes t1.png -auto-level t3.png
with the
old IM version 6.8.8-5 Q16 x64 we get the same result with this pipe
Code: Select all
> convert -version
Version: ImageMagick 6.8.8-5 Q16 x64 2014-02-08 http://www.imagemagick.org
> convert t1.png gray:- | convert -depth 16 -endian msb -size 320x240 gray:- -auto-level t3.png
----------
with the current version of IM
6.8.9-5 Q16 x86 I get this result
Code: Select all
> convert -version
Version: ImageMagick 6.8.9-5 Q16 x86 2014-06-26 http://www.imagemagick.org
> convert t1.png gray:- | convert -depth 16 -endian msb -size 320x240 gray:- -auto-level t4.png
I get the same wrong result with (x64)
Code: Select all
> convert.exe -version
Version: ImageMagick 6.8.9-5 Q16 x64 2014-06-26 http://www.imagemagick.org
all downloads from
http://www.imagemagick.org/script/binar ... hp#windows
It's a bug?
----------------------------------------------------
curious, but this byte switching pipe works fine
Code: Select all
> convert -version
Version: ImageMagick 6.8.9-5 Q16 x64 2014-06-26 http://www.imagemagick.org
> echo ABCDEF | convert -endian msb -size "3X1" -depth 16 gray:- png:- | convert - gray:- | hexdump
00000000: 42 41 44 43 46 45 - |BADCFE|
Re: png and endian
Posted: 2014-07-08T06:54:01-07:00
by glennrp
On Ubuntu 14.04, Bash, it appears that it is "hexdump" not imagemagick that is giving you
the unexpected result:
- echo ABCDEF | hexdump
0000000 4241 4443 4645 000a
0000007
but
echo ABCDEF | hexdump -c
0000000 A B C D E F \n
Re: png and endian
Posted: 2014-07-08T07:57:38-07:00
by thomas12
great hint, in Linux/Mac I only use "hexdump -C" but I'm sitting here with a x64 windows 8 pc and a GnuWin32 hexdump.exe (without parameter C)
the same with full paths
Code: Select all
>C:\util\GnuWin32\bin\echo.exe -n ABCDED | C:\util\GnuWin32\bin\hexdump
00000000: 41 42 43 44 45 44 - |ABCDED|
00000006;
>C:\util\GnuWin32\bin\echo.exe -n ABCDED | C:\util\ImageMagick-6.8.9-Q16\convert.exe -endian msb -size "3X1" -depth 16 gray:- png:- | convert - gray:- | C:\util\GnuWin32\bin\hexdump
00000000: 42 41 44 43 44 45 - |BADCDE|
I think, the problem is
Re: png and endian
Posted: 2014-07-08T08:00:24-07:00
by thomas12
see the difference
Code: Select all
>C:\util\ImageMagick-6.8.8-Q16\convert.exe t1.png gray:- | hexdump
00000000: 2F 87 2F 88 2F 88 2F 87 - 2F 89 2F 8C 2F 8A 2F 8E |/ / / / / / / / |
00000010: 2F 8E 2F 8D 2F 8D 2F 8C - 2F 8B 2F 8B 2F 8A 2F 8A |/ / / / / / / / |
00000020: 2F 8A 2F 89 2F 89 2F 88 - 2F 87 2F 86 2F 85 2F 83 |/ / / / / / / / |
00000030: 2F 82 2F 85 2F 84 2F 87 - 2F 8A 2F 8A 2F 8A 2F 88 |/ / / / / / / / |
and now the noise generator
Code: Select all
>C:\util\ImageMagick-6.8.9-Q16\convert.exe t1.png gray:- | hexdump
00000000: E8 C0 8B C1 8B C1 E8 C0 - 2D C2 10 C4 CF C2 4E C5 | - N |
00000010: 4E C5 AF C4 AF C4 10 C4 - 70 C3 70 C3 CF C2 CF C2 |N p p |
00000020: CF C2 2D C2 2D C2 8B C1 - E8 C0 44 C0 A0 BF 55 BE | - - D U |
00000030: AE BD A0 BF FB BE E8 C0 - CF C2 CF C2 CF C2 8B C1 | |
Re: png and endian
Posted: 2014-07-09T00:44:19-07:00
by thomas12
it's a gamma problem
same sample image t1.png as above
old IM 6.8.8
Code: Select all
>C:\util\ImageMagick-6.8.8-Q16\convert.exe t1.png gray:- | hexdump | head
00000000: 2F 87 2F 88 2F 88 2F 87 - 2F 89 2F 8C 2F 8A 2F 8E |/ / / / / / / / |
00000010: 2F 8E 2F 8D 2F 8D 2F 8C - 2F 8B 2F 8B 2F 8A 2F 8A |/ / / / / / / / |
00000020: 2F 8A 2F 89 2F 89 2F 88 - 2F 87 2F 86 2F 85 2F 83 |/ / / / / / / / |
00000030: 2F 82 2F 85 2F 84 2F 87 - 2F 8A 2F 8A 2F 8A 2F 88 |/ / / / / / / / |
00000040: 2F 86 2F 88 2F 85 2F 89 - 2F 88 2F 89 2F 8B 2F 8B |/ / / / / / / / |
00000050: 2F 8B 2F 8C 2F 8B 2F 8F - 2F 8D 2F 8E 2F 8C 2F 8B |/ / / / / / / / |
00000060: 2F 8A 2F 8A 2F 8A 2F 8B - 2F 8A 2F 89 2F 8B 2F 8E |/ / / / / / / / |
00000070: 2F 91 2F 8D 2F 8E 2F 8E - 2F 8D 2F 93 2F 92 2F 90 |/ / / / / / / / |
00000080: 2F 93 2F 93 2F 91 2F 8F - 2F 8F 2F 8E 2F 8F 2F 91 |/ / / / / / / / |
00000090: 2F 91 2F 90 2F 92 2F 94 - 2F 90 2F 95 2F 92 2F 92 |/ / / / / / / / |
new IM 6.8.9 without gamma
Code: Select all
>C:\util\ImageMagick-6.8.9-Q16\convert.exe t1.png gray:- | hexdump | head
00000000: E8 C0 8B C1 8B C1 E8 C0 - 2D C2 10 C4 CF C2 4E C5 | - N |
00000010: 4E C5 AF C4 AF C4 10 C4 - 70 C3 70 C3 CF C2 CF C2 |N p p |
00000020: CF C2 2D C2 2D C2 8B C1 - E8 C0 44 C0 A0 BF 55 BE | - - D U |
00000030: AE BD A0 BF FB BE E8 C0 - CF C2 CF C2 CF C2 8B C1 | |
00000040: 44 C0 8B C1 A0 BF 2D C2 - 8B C1 2D C2 70 C3 70 C3 |D - - p p |
00000050: 70 C3 10 C4 70 C3 ED C5 - AF C4 4E C5 10 C4 70 C3 |p p N p |
00000060: CF C2 CF C2 CF C2 70 C3 - CF C2 2D C2 70 C3 4E C5 | p - p N |
00000070: 27 C7 AF C4 4E C5 4E C5 - AF C4 5F C8 C4 C7 8A C6 |' N N _ |
00000080: 5F C8 5F C8 27 C7 ED C5 - ED C5 4E C5 ED C5 27 C7 |_ _ ' N ' |
00000090: 27 C7 8A C6 C4 C7 FA C8 - 8A C6 95 C9 C4 C7 C4 C7 |' |
new IM 6.8.9 with
gamma value 0.99999 (correct)
Code: Select all
>C:\util\ImageMagick-6.8.9-Q16\convert.exe t1.png -gamma 0.99999 gray:- | hexdump | head
00000000: 2F 87 2F 88 2F 88 2F 87 - 2F 89 2F 8C 2F 8A 2F 8E |/ / / / / / / / |
00000010: 2F 8E 2F 8D 2F 8D 2F 8C - 2F 8B 2F 8B 2F 8A 2F 8A |/ / / / / / / / |
00000020: 2F 8A 2F 89 2F 89 2F 88 - 2F 87 2F 86 2F 85 2F 83 |/ / / / / / / / |
00000030: 2F 82 2F 85 2F 84 2F 87 - 2F 8A 2F 8A 2F 8A 2F 88 |/ / / / / / / / |
00000040: 2F 86 2F 88 2F 85 2F 89 - 2F 88 2F 89 2F 8B 2F 8B |/ / / / / / / / |
00000050: 2F 8B 2F 8C 2F 8B 2F 8F - 2F 8D 2F 8E 2F 8C 2F 8B |/ / / / / / / / |
00000060: 2F 8A 2F 8A 2F 8A 2F 8B - 2F 8A 2F 89 2F 8B 2F 8E |/ / / / / / / / |
00000070: 2F 91 2F 8D 2F 8E 2F 8E - 2F 8D 2F 93 2F 92 2F 90 |/ / / / / / / / |
00000080: 2F 93 2F 93 2F 91 2F 8F - 2F 8F 2F 8E 2F 8F 2F 91 |/ / / / / / / / |
00000090: 2F 91 2F 90 2F 92 2F 94 - 2F 90 2F 95 2F 92 2F 92 |/ / / / / / / / |
new IM 6.8.9 with
gamma value 1 (bad result)
Code: Select all
>C:\util\ImageMagick-6.8.9-Q16\convert.exe t1.png -gamma 1 gray:- | hexdump | head
00000000: E8 C0 8B C1 8B C1 E8 C0 - 2D C2 10 C4 CF C2 4E C5 | - N |
00000010: 4E C5 AF C4 AF C4 10 C4 - 70 C3 70 C3 CF C2 CF C2 |N p p |
00000020: CF C2 2D C2 2D C2 8B C1 - E8 C0 44 C0 A0 BF 55 BE | - - D U |
00000030: AE BD A0 BF FB BE E8 C0 - CF C2 CF C2 CF C2 8B C1 | |
00000040: 44 C0 8B C1 A0 BF 2D C2 - 8B C1 2D C2 70 C3 70 C3 |D - - p p |
00000050: 70 C3 10 C4 70 C3 ED C5 - AF C4 4E C5 10 C4 70 C3 |p p N p |
00000060: CF C2 CF C2 CF C2 70 C3 - CF C2 2D C2 70 C3 4E C5 | p - p N |
00000070: 27 C7 AF C4 4E C5 4E C5 - AF C4 5F C8 C4 C7 8A C6 |' N N _ |
00000080: 5F C8 5F C8 27 C7 ED C5 - ED C5 4E C5 ED C5 27 C7 |_ _ ' N ' |
00000090: 27 C7 8A C6 C4 C7 FA C8 - 8A C6 95 C9 C4 C7 C4 C7 |' |
and now new IM 6.8.9 with
gamma value 1.00001 (correct)
Code: Select all
>C:\util\ImageMagick-6.8.9-Q16\convert.exe t1.png -gamma 1.00001 gray:- | hexdump | head
00000000: 2F 87 2F 88 2F 88 2F 87 - 2F 89 2F 8C 2F 8A 2F 8E |/ / / / / / / / |
00000010: 2F 8E 2F 8D 2F 8D 2F 8C - 2F 8B 2F 8B 2F 8A 2F 8A |/ / / / / / / / |
00000020: 2F 8A 2F 89 2F 89 2F 88 - 2F 87 2F 86 2F 85 2F 83 |/ / / / / / / / |
00000030: 2F 82 2F 85 2F 84 2F 87 - 2F 8A 2F 8A 2F 8A 2F 88 |/ / / / / / / / |
00000040: 2F 86 2F 88 2F 85 2F 89 - 2F 88 2F 89 2F 8B 2F 8B |/ / / / / / / / |
00000050: 2F 8B 2F 8C 2F 8B 2F 8F - 2F 8D 2F 8E 2F 8C 2F 8B |/ / / / / / / / |
00000060: 2F 8A 2F 8A 2F 8A 2F 8B - 2F 8A 2F 89 2F 8B 2F 8E |/ / / / / / / / |
00000070: 2F 91 2F 8D 2F 8E 2F 8E - 2F 8D 2F 93 2F 92 2F 90 |/ / / / / / / / |
00000080: 2F 93 2F 93 2F 91 2F 8F - 2F 8F 2F 8E 2F 8F 2F 91 |/ / / / / / / / |
00000090: 2F 91 2F 90 2F 92 2F 94 - 2F 90 2F 95 2F 92 2F 92 |/ / / / / / / / |
Re: png and gamma value
Posted: 2014-07-11T01:05:31-07:00
by thomas12
I think, the cause is a new handling of embedded gamma values
image t1.png from above has a unusual
gamma of 1
Code: Select all
>identify -format %[gamma] t1.png
1
after converting the png to a text file image and then back to png
we get
gamma = 1/2.2 = 0.45455 (see
http://en.wikipedia.org/wiki/Gamma_corr ... ard_gammas )
Code: Select all
>convert t1.png -compress none t1.pgm
>convert t1.pgm t1a.png
>identify -format %[gamma] t1a.png
0.45455
and with this image t1a.png the pipe from first post works fine
Code: Select all
convert t1a.png gray:- | convert -depth 16 -endian msb -size 320x240 gray:- -auto-level t4.png
----------------
but the converting to a gray-pipe is still not correct
see my samples above
with the great differences with gamma 0.99999 / 1 / 1.00001
Re: png and gamma value
Posted: 2014-07-11T07:22:26-07:00
by snibgo
I'm not sure what is happening here, or what should happen.
I think this is happening:
Converting to "gray:" output will also change the colorspace to sRGB, if it isn't already sRGB.
Your t1.png doesn't have metadata saying it is sRGB, but has gamma=1. Therefore IM says it is RGB and converts it to sRGB for output to "gray:".
If you change the gamma, it no longer has gamma=1, so it isn't RGB. So IM assumes it doesn't need converting to sRGB.
To get consistent behaviour irrespective of your "-gamma 1.001" etc, insert "-set colorspace sRGB" or "-set colorspace RGB" before the output.
Re: png and gamma value
Posted: 2014-07-13T04:00:59-07:00
by thomas12
thanks, this is the solution
like several times before, IM changed the processing of (undefined RAW) RGB/sRGB in pipes from 6.8.8 to 6.8.9
the image is RGB
Code: Select all
$ identify t1.png
t1.png PNG 320x240 320x240+0+0 16-bit RGB 52.7KB 0.000u 0:00.000
and this works fine
Code: Select all
$ convert t1.png -set colorspace sRGB gray:- | convert -depth 16 -endian msb -size 320x240 gray:- -auto-level t3.png
changed thread subject to "solved"