Page 1 of 1

[RESOLVED] problem with PNG vs TIF displacement image

Posted: 2014-09-15T18:40:26-07:00
by fmw42
Mac OSX Snow Leopard

Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-08-27 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib


I am getting a very strange result from a displacement map saved as PNG compared to the same displacement map saved as TIF. The commands for doing the displacement are identical except for the format of the displacement maps and those compare closely.

PNG displacement image:
http://www.fmwconcepts.com/misc_tests/d ... splace.png

TIF displacement image:
http://www.fmwconcepts.com/misc_tests/d ... place.tiff

Code: Select all

compare -metric rmse displace.png displace.tiff null:
62.1675 (0.000948616)

Image to be displaced:
Image


Commands:

roll="+43.8596+0"
length2="51.1111"
pwidth="3157.89"
pheight="450"
height1="323.77"
xc="1578.94"
radius2="93.77"
width="300"

convert -respect-parenthesis \
\( gabby.jpg -write mpr:comp +delete mpr:comp \
-gravity center -background none -extent ${pwidth}x${pheight} -roll $roll \
-resize 100x${length2}% -background none -gravity northwest -extent ${pwidth}x${height1} \) \
displace.png -channel rgba -alpha on -virtual-pixel transparent -gravity northwest \
-define compose:args=${xc}x${radius2} -compose displace -composite -compose over \
-gravity center -crop ${width}x${height1}+0+0 +repage testpng.jpg

Image


convert -respect-parenthesis \
\( gabby.jpg -write mpr:comp +delete mpr:comp \
-gravity center -background none -extent ${pwidth}x${pheight} -roll $roll \
-resize 100x${length2}% -background none -gravity northwest -extent ${pwidth}x${height1} \) \
displace.tiff -channel rgba -alpha on -virtual-pixel transparent -gravity northwest \
-define compose:args=${xc}x${radius2} -compose displace -composite -compose over \
-gravity center -crop ${width}x${height1}+0+0 +repage testtif.jpg

Image


P.S. I suppose it is possible that the problem is when saving the displacement maps. But the code is the same except for the format.

I have a vertical displacement image and a horizontal displacement image both in .MPC format. The commands to save as the final displacement maps are:

Code: Select all

convert $tmpA4 $tmpA3 \( -clone 0 -fill black -colorize 100 \) -colorspace sRGB -combine -alpha set PNG32:displace.png

convert $tmpA4 $tmpA3 \( -clone 0 -fill black -colorize 100 \) -colorspace sRGB -combine -alpha set displace.tiff

Re: problem with PNG vs TIF displacement image

Posted: 2014-09-15T19:07:19-07:00
by snibgo
The TIFF is 16 bit; the PNG is 8 bit, with evident quantisation. For example, looking at a sample of pixels, the same area from each:

Code: Select all

F:\web\im>%IM%convert displace.tiff -crop 20x1+1600+100 txt:
# ImageMagick pixel enumeration: 20,1,65535,srgba
0,0: (50.576%,17.3602%,0%,1)  #81792C710000  srgba(50.576%,17.3602%,0%,1)
1,0: (50.6035%,17.3709%,0%,1)  #818B2C780000  srgba(50.6035%,17.3709%,0%,1)
2,0: (50.631%,17.38%,0%,1)  #819D2C7E0000  srgba(50.631%,17.38%,0%,1)
3,0: (50.6584%,17.3907%,0%,1)  #81AF2C850000  srgba(50.6584%,17.3907%,0%,1)
4,0: (50.6859%,17.4014%,0%,1)  #81C12C8C0000  srgba(50.6859%,17.4014%,0%,1)
5,0: (50.7134%,17.4136%,0%,1)  #81D32C940000  srgba(50.7134%,17.4136%,0%,1)
6,0: (50.7408%,17.4258%,0%,1)  #81E52C9C0000  srgba(50.7408%,17.4258%,0%,1)
7,0: (50.7683%,17.4365%,0%,1)  #81F72CA30000  srgba(50.7683%,17.4365%,0%,1)
8,0: (50.7958%,17.4502%,0%,1)  #82092CAC0000  srgba(50.7958%,17.4502%,0%,1)
9,0: (50.8232%,17.464%,0%,1)  #821B2CB50000  srgba(50.8232%,17.464%,0%,1)
10,0: (50.8507%,17.4777%,0%,1)  #822D2CBE0000  srgba(50.8507%,17.4777%,0%,1)
11,0: (50.8797%,17.4914%,0%,1)  #82402CC70000  srgba(50.8797%,17.4914%,0%,1)
12,0: (50.9071%,17.5067%,0%,1)  #82522CD10000  srgba(50.9071%,17.5067%,0%,1)
13,0: (50.9346%,17.5219%,0%,1)  #82642CDB0000  srgba(50.9346%,17.5219%,0%,1)
14,0: (50.9621%,17.5372%,0%,1)  #82762CE50000  srgba(50.9621%,17.5372%,0%,1)
15,0: (50.9895%,17.554%,0%,1)  #82882CF00000  srgba(50.9895%,17.554%,0%,1)
16,0: (51.0185%,17.5692%,0%,1)  #829B2CFA0000  srgba(51.0185%,17.5692%,0%,1)
17,0: (51.046%,17.5875%,0%,1)  #82AD2D060000  srgba(51.046%,17.5875%,0%,1)
18,0: (51.0735%,17.6043%,0%,1)  #82BF2D110000  srgba(51.0735%,17.6043%,0%,1)
19,0: (51.1009%,17.6226%,0%,1)  #82D12D1D0000  srgba(51.1009%,17.6226%,0%,1)

F:\web\im>%IM%convert displace.png -crop 20x1+1600+100 txt:
# ImageMagick pixel enumeration: 20,1,255,srgba
0,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
1,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
2,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
3,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
4,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
5,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
6,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
7,0: (129,44,0,1)  #812C00  srgba(129,44,0,1)
8,0: (130,44,0,1)  #822C00  srgba(130,44,0,1)
9,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
10,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
11,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
12,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
13,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
14,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
15,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
16,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
17,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
18,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
19,0: (130,45,0,1)  #822D00  srgba(130,45,0,1)
The TIFF varies more smoothly than the PNG.

If you convert the 16-bit tiff to a 16-bit png, I suspect they will give the same displacement results.

Re: problem with PNG vs TIF displacement image

Posted: 2014-09-15T19:24:30-07:00
by fmw42
Thanks snibgo. I had not considered that, since I had used PNG for other displacement images and they worked just fine on the same image. I will try adding -depth 16 to the PNG before saving and see if that helps.

Re: problem with PNG vs TIF displacement image

Posted: 2014-09-15T19:31:22-07:00
by fmw42
Saving the PNG as 16-bits does not help. I will have to see where the conversion to 8-bits is going on.

Re: problem with PNG vs TIF displacement image

Posted: 2014-09-15T19:42:24-07:00
by fmw42
It would appear to be a bug in PNG writer. All 3 images that go into the displacement map are 16-bit. But even if I add -depth 16 before PNG32:displace.png, the files seems to be saved as 8-bit.

Re: problem with PNG vs TIF displacement image

Posted: 2014-09-15T19:46:38-07:00
by snibgo
"PNG32:" means 32 bits total, with 4 channels, thus 8 bits/channel/pixel. Try without a prefix, or maybe PNG64: (I don't know if that's a valid option).

Re: problem with PNG vs TIF displacement image

Posted: 2014-09-15T20:16:21-07:00
by fmw42
Yes, I don't know what I was doing with PNG32. It seemed to work with other displacements I was doing. I guess they did not need the accuracy. But you are right. I need PNG64, which is 16-bit and acceptable and would provide more accuracy.

Removing PNG32: and just saving to displace.png, seems to work just fine to keep the result as 16-bit.

Thanks snibgo.