Lab written as txt:

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.

Lab written as txt:

Postby snibgo » 2013-08-15T22:17:23+00:00

There seems to be a bug writing txt: format from Lab images, in IM versions dating back to v6.8.0.

IM writes and reads integers with an offset of Quantum/2, but negative values are written as zero. Thus writing a Lab txt file and reading it back in will yield different values.

When reading txt files, any values < 0 or > 32767 are treated as negative, and this is reasonable.

Test cases (IM v6.8.6-0, Windows):

Text file lab_test_neg contains:
Code: Select all
# ImageMagick pixel enumeration: 10,1,65535,cielab
0,0: (59712,    0,        0)
1,0: (59712,    10,       0)
2,0: (59712,    100,      0)
3,0: (59712,    1000,     0)
4,0: (59712,    -10,      0)
5,0: (59712,    -100,     0)
6,0: (59712,    -1000,    0)
7,0: (59712,    32767,    0)
8,0: (59712,    32768,    0)
9,0: (59712,    0,        0)


Reading test:
Code: Select all
%I%convert ^
  txt:lab_test_neg.txt ^
  -set colorspace Lab ^
  txt:

Result of reading test:

Code: Select all
D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\convert   txt:lab_test_neg.txt   -set colorspace Lab txt:
# ImageMagick pixel enumeration: 10,1,65535,cielab
0,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,0%,0%)
1,0: (59712,   10,    0)  #E940000A0000  cielab(91.1147%,0.015259%,0%)
2,0: (59712,  100,    0)  #E94000640000  cielab(91.1147%,0.15259%,0%)
3,0: (59712, 1000,    0)  #E94003E80000  cielab(91.1147%,1.5259%,0%)
4,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,-0.015259%,0%)
5,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,-0.15259%,0%)
6,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,-1.5259%,0%)
7,0: (59712,32767,    0)  #E9407FFF0000  cielab(91.1147%,49.9992%,0%)
8,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,-50.0008%,0%)
9,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,0%,0%)

The cielab percentages are good, so I think IM correctly reads Lab txt files.


Writing test:
Code: Select all
%I%convert ^
  -size 1x10 ^
  gradient:rgb(0%%,100%%,100%%)-rgb(100%%,100%%,0%%) ^
  -colorspace Lab ^
  -write txt: ^
  -colorspace sRGB ^
  txt:


Result:
Code: Select all
D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\convert   -size 1x10   gradient:rgb(0%,100%,100%)-rgb(100%,100%,0%)   -colorspace Lab   -write txt:   -colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,10,65535,cielab
0,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,-18.8556%,-5.54665%)
0,1: (59282,    0,    0)  #E79200000000  cielab(90.4585%,-21.5946%,-0.158694%)
0,2: (59032,    0, 3529)  #E69800000DC9  cielab(90.0771%,-23.5309%,5.38491%)
0,3: (58996,    0, 7242)  #E67400001C4A  cielab(90.0221%,-24.4221%,11.0506%)
0,4: (59190,    0,10978)  #E73600002AE2  cielab(90.3182%,-24.1459%,16.7514%)
0,5: (59623,    0,14625)  #E8E700003921  cielab(90.9789%,-22.6978%,22.3163%)
0,6: (60296,    0,18005)  #EB8800004655  cielab(92.0058%,-20.1923%,27.4739%)
0,7: (61203,    0,20870)  #EF1300005186  cielab(93.3898%,-16.8276%,31.8456%)
0,8: (62330,    0,22971)  #F37A000059BB  cielab(95.1095%,-12.8344%,35.0515%)
0,9: (63658,    0,24281)  #F8AA00005ED9  cielab(97.1359%,-8.45197%,37.0504%)
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: (    0,65535,65534)  #0000FFFFFFFE  srgb(0%,100%,99.9985%)
0,1: ( 7291,65535,58254)  #1C7BFFFFE38E  srgb(11.1254%,100%,88.8899%)
0,2: (14565,65535,50972)  #38E5FFFFC71C  srgb(22.2248%,100%,77.7783%)
0,3: (21845,65535,43691)  #5555FFFFAAAB  srgb(33.3333%,100%,66.6682%)
0,4: (29126,65535,36408)  #71C6FFFF8E38  srgb(44.4434%,100%,55.555%)
0,5: (36407,65535,29127)  #8E37FFFF71C7  srgb(55.5535%,100%,44.445%)
0,6: (43690,65535,21846)  #AAAAFFFF5556  srgb(66.6667%,100%,33.3349%)
0,7: (50972,65535,14563)  #C71CFFFF38E3  srgb(77.7783%,100%,22.2217%)
0,8: (58254,65535, 7284)  #E38EFFFF1C74  srgb(88.8899%,100%,11.1147%)
0,9: (65534,65535,    2)  #FFFEFFFF0002  srgb(99.9985%,100%,0.0030518%)

The sRGB values are more or less correct.

The cielab percentages are more or less correct, remembering that mid-values in a and b channels are 0%. But all negative a or b percentages are shown with integer zero.

So the bug I'd like fixing is that negative integers when written shouldn't be clipped to zero.

(The Luv colorspace isn't offset by Quantum/2, so never goes negative and doesn't have this problem.)
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3100
Joined: 2010-01-23T23:01:33+00:00

Re: Lab written as txt:

Postby magick » 2013-08-16T09:28:03+00:00

Here are the before and after results for HDRI sRGB => Lab => sRGB:

Code: Select all
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: (    0,65535,65535)  #0000FFFFFFFF  cyan
0,1: ( 7282,65535,58253)  #1C72FFFFE38D  srgb(11.1111%,100%,88.8889%)
0,2: (14563,65535,50972)  #38E3FFFFC71C  srgb(22.2222%,100%,77.7778%)
0,3: (21845,65535,43690)  #5555FFFFAAAA  srgb(85,255,170)
0,4: (29127,65535,36408)  #71C7FFFF8E38  srgb(44.4444%,100%,55.5556%)
0,5: (36408,65535,29127)  #8E38FFFF71C7  srgb(55.5556%,100%,44.4444%)
0,6: (43690,65535,21845)  #AAAAFFFF5555  srgb(170,255,85)
0,7: (50972,65535,14563)  #C71CFFFF38E3  srgb(77.7778%,100%,22.2222%)
0,8: (58253,65535, 7282)  #E38DFFFF1C72  srgb(88.8889%,100%,11.1111%)
0,9: (65535,65535,    0)  #FFFFFFFF0000  yellow
# ImageMagick pixel enumeration: 1,10,65535,cielab
0,0: (59712,    0,    0)  #E94000000000  cielab(91.1152%,-18.8549%,-5.54738%)
0,1: (59282,    0,    0)  #E79200000000  cielab(90.4578%,-21.5952%,-0.158643%)
0,2: (59032,    0, 3529)  #E69800000DC9  cielab(90.077%,-23.5312%,5.38474%)
0,3: (58996,    0, 7242)  #E67400001C4A  cielab(90.0218%,-24.4224%,11.0513%)
0,4: (59190,    0,10978)  #E73600002AE2  cielab(90.3182%,-24.1455%,16.7512%)
0,5: (59623,    0,14625)  #E8E700003921  cielab(90.9793%,-22.6976%,22.3169%)
0,6: (60296,    0,18005)  #EB8800004655  cielab(92.0062%,-20.1927%,27.4745%)
0,7: (61203,    0,20870)  #EF1300005186  cielab(93.3894%,-16.8274%,31.8452%)
0,8: (62330,    0,22971)  #F37A000059BB  cielab(95.1096%,-12.8347%,35.052%)
0,9: (63658,    0,24281)  #F8AA00005ED9  cielab(97.1365%,-8.45184%,37.0509%)
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: (    0,65535,65535)  #0000FFFFFFFF  srgb(-5.98795e-05%,100%,100%)
0,1: ( 7282,65535,58253)  #1C72FFFFE38D  srgb(11.1111%,100%,88.8889%)
0,2: (14563,65535,50972)  #38E3FFFFC71C  srgb(22.2222%,100%,77.7778%)
0,3: (21845,65535,43690)  #5555FFFFAAAA  srgb(33.3333%,100%,66.6667%)
0,4: (29127,65535,36408)  #71C7FFFF8E38  srgb(44.4444%,100%,55.5556%)
0,5: (36408,65535,29127)  #8E38FFFF71C7  srgb(55.5556%,100%,44.4444%)
0,6: (43690,65535,21845)  #AAAAFFFF5555  srgb(66.6667%,100%,33.3333%)
0,7: (50972,65535,14563)  #C71CFFFF38E3  srgb(77.7778%,100%,22.2222%)
0,8: (58253,65535, 7282)  #E38DFFFF1C72  srgb(88.8889%,100%,11.1111%)
0,9: (65535,65535,    0)  #FFFFFFFF0000  srgb(100%,100%,-4.11654e-05%)

Now the Q16 unsigned short results:

Code: Select all
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: (    0,65535,65535)  #0000FFFFFFFF  cyan
0,1: ( 7282,65535,58253)  #1C72FFFFE38D  srgb(11.1116%,100%,88.8884%)
0,2: (14563,65535,50972)  #38E3FFFFC71C  srgb(22.2217%,100%,77.7783%)
0,3: (21845,65535,43690)  #5555FFFFAAAA  srgb(85,255,170)
0,4: (29127,65535,36408)  #71C7FFFF8E38  srgb(44.445%,100%,55.555%)
0,5: (36408,65535,29127)  #8E38FFFF71C7  srgb(55.555%,100%,44.445%)
0,6: (43690,65535,21845)  #AAAAFFFF5555  srgb(170,255,85)
0,7: (50972,65535,14563)  #C71CFFFF38E3  srgb(77.7783%,100%,22.2217%)
0,8: (58253,65535, 7282)  #E38DFFFF1C72  srgb(88.8884%,100%,11.1116%)
0,9: (65535,65535,    0)  #FFFFFFFF0000  yellow
# ImageMagick pixel enumeration: 1,10,65535,cielab
0,0: (59712,    0,    0)  #E94000000000  cielab(91.1147%,-18.8556%,-5.54665%)
0,1: (59282,    0,    0)  #E79200000000  cielab(90.4585%,-21.5946%,-0.158694%)
0,2: (59032,    0, 3529)  #E69800000DC9  cielab(90.0771%,-23.5309%,5.38491%)
0,3: (58996,    0, 7242)  #E67400001C4A  cielab(90.0221%,-24.4221%,11.0506%)
0,4: (59190,    0,10978)  #E73600002AE2  cielab(90.3182%,-24.1459%,16.7514%)
0,5: (59623,    0,14625)  #E8E700003921  cielab(90.9789%,-22.6978%,22.3163%)
0,6: (60296,    0,18005)  #EB8800004655  cielab(92.0058%,-20.1923%,27.4739%)
0,7: (61203,    0,20870)  #EF1300005186  cielab(93.3898%,-16.8276%,31.8456%)
0,8: (62330,    0,22971)  #F37A000059BB  cielab(95.1095%,-12.8344%,35.0515%)
0,9: (63658,    0,24281)  #F8AA00005ED9  cielab(97.1359%,-8.45197%,37.0504%)
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: (    0,65535,65534)  #0000FFFFFFFE  srgb(0%,100%,99.9985%)
0,1: ( 7291,65535,58254)  #1C7BFFFFE38E  srgb(11.1254%,100%,88.8899%)
0,2: (14565,65535,50972)  #38E5FFFFC71C  srgb(22.2248%,100%,77.7783%)
0,3: (21845,65535,43691)  #5555FFFFAAAB  srgb(33.3333%,100%,66.6682%)
0,4: (29126,65535,36408)  #71C6FFFF8E38  srgb(44.4434%,100%,55.555%)
0,5: (36407,65535,29127)  #8E37FFFF71C7  srgb(55.5535%,100%,44.445%)
0,6: (43690,65535,21846)  #AAAAFFFF5556  srgb(66.6667%,100%,33.3349%)
0,7: (50972,65535,14563)  #C71CFFFF38E3  srgb(77.7783%,100%,22.2217%)
0,8: (58254,65535, 7284)  #E38EFFFF1C74  srgb(88.8899%,100%,11.1147%)
0,9: (65534,65535,    2)  #FFFEFFFF0002  srgb(99.9985%,100%,0.0030518%)

Note, some Lab values do not map directly into the sRGB colorspace. Given the above, exactly which values do you think are incorrect and what value should they be?
User avatar
magick
Site Admin
 
Posts: 9547
Joined: 2003-05-31T11:32:55+00:00

Re: Lab written as txt:

Postby snibgo » 2013-08-16T12:38:59+00:00

Yes, that shows the problem. I have reddened the incorrect values, for just the Q16 version. The corresponding hex values are also wrong.

# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: ( 0,65535,65535) #0000FFFFFFFF cyan
0,1: ( 7282,65535,58253) #1C72FFFFE38D srgb(11.1116%,100%,88.8884%)
0,2: (14563,65535,50972) #38E3FFFFC71C srgb(22.2217%,100%,77.7783%)
0,3: (21845,65535,43690) #5555FFFFAAAA srgb(85,255,170)
0,4: (29127,65535,36408) #71C7FFFF8E38 srgb(44.445%,100%,55.555%)
0,5: (36408,65535,29127) #8E38FFFF71C7 srgb(55.555%,100%,44.445%)
0,6: (43690,65535,21845) #AAAAFFFF5555 srgb(170,255,85)
0,7: (50972,65535,14563) #C71CFFFF38E3 srgb(77.7783%,100%,22.2217%)
0,8: (58253,65535, 7282) #E38DFFFF1C72 srgb(88.8884%,100%,11.1116%)
0,9: (65535,65535, 0) #FFFFFFFF0000 yellow
# ImageMagick pixel enumeration: 1,10,65535,cielab
0,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,-18.8556%,-5.54665%)
0,1: (59282, 0, 0) #E79200000000 cielab(90.4585%,-21.5946%,-0.158694%)
0,2: (59032, 0, 3529) #E69800000DC9 cielab(90.0771%,-23.5309%,5.38491%)
0,3: (58996, 0, 7242) #E67400001C4A cielab(90.0221%,-24.4221%,11.0506%)
0,4: (59190, 0,10978) #E73600002AE2 cielab(90.3182%,-24.1459%,16.7514%)
0,5: (59623, 0,14625) #E8E700003921 cielab(90.9789%,-22.6978%,22.3163%)
0,6: (60296, 0,18005) #EB8800004655 cielab(92.0058%,-20.1923%,27.4739%)
0,7: (61203, 0,20870) #EF1300005186 cielab(93.3898%,-16.8276%,31.8456%)
0,8: (62330, 0,22971) #F37A000059BB cielab(95.1095%,-12.8344%,35.0515%)
0,9: (63658, 0,24281) #F8AA00005ED9 cielab(97.1359%,-8.45197%,37.0504%)
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: ( 0,65535,65534) #0000FFFFFFFE srgb(0%,100%,99.9985%)
0,1: ( 7291,65535,58254) #1C7BFFFFE38E srgb(11.1254%,100%,88.8899%)
0,2: (14565,65535,50972) #38E5FFFFC71C srgb(22.2248%,100%,77.7783%)
0,3: (21845,65535,43691) #5555FFFFAAAB srgb(33.3333%,100%,66.6682%)
0,4: (29126,65535,36408) #71C6FFFF8E38 srgb(44.4434%,100%,55.555%)
0,5: (36407,65535,29127) #8E37FFFF71C7 srgb(55.5535%,100%,44.445%)
0,6: (43690,65535,21846) #AAAAFFFF5556 srgb(66.6667%,100%,33.3349%)
0,7: (50972,65535,14563) #C71CFFFF38E3 srgb(77.7783%,100%,22.2217%)
0,8: (58254,65535, 7284) #E38EFFFF1C74 srgb(88.8899%,100%,11.1147%)
0,9: (65534,65535, 2) #FFFEFFFF0002 srgb(99.9985%,100%,0.0030518%)


The formula for the integer cielab values should be something like
int_value = percent_value /100 * 65535

So the correct integer values will be (shown in green, but I haven't calculated the correct hex values):

# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: ( 0,65535,65535) #0000FFFFFFFF cyan
0,1: ( 7282,65535,58253) #1C72FFFFE38D srgb(11.1116%,100%,88.8884%)
0,2: (14563,65535,50972) #38E3FFFFC71C srgb(22.2217%,100%,77.7783%)
0,3: (21845,65535,43690) #5555FFFFAAAA srgb(85,255,170)
0,4: (29127,65535,36408) #71C7FFFF8E38 srgb(44.445%,100%,55.555%)
0,5: (36408,65535,29127) #8E38FFFF71C7 srgb(55.555%,100%,44.445%)
0,6: (43690,65535,21845) #AAAAFFFF5555 srgb(170,255,85)
0,7: (50972,65535,14563) #C71CFFFF38E3 srgb(77.7783%,100%,22.2217%)
0,8: (58253,65535, 7282) #E38DFFFF1C72 srgb(88.8884%,100%,11.1116%)
0,9: (65535,65535, 0) #FFFFFFFF0000 yellow
# ImageMagick pixel enumeration: 1,10,65535,cielab
0,0: (59712,-12357, -3635) #E940???????? cielab(91.1147%,-18.8556%,-5.54665%)
0,1: (59282,-14152, -104) #E792???????? cielab(90.4585%,-21.5946%,-0.158694%)
0,2: (59032,-15421, 3529) #E698????0DC9 cielab(90.0771%,-23.5309%,5.38491%)
0,3: (58996,-16005, 7242) #E674????1C4A cielab(90.0221%,-24.4221%,11.0506%)
0,4: (59190,-15824,10978) #E736????2AE2 cielab(90.3182%,-24.1459%,16.7514%)
0,5: (59623,-14875,14625) #E8E7????3921 cielab(90.9789%,-22.6978%,22.3163%)
0,6: (60296,-13233,18005) #EB88????4655 cielab(92.0058%,-20.1923%,27.4739%)
0,7: (61203,-11028,20870) #EF13????5186 cielab(93.3898%,-16.8276%,31.8456%)
0,8: (62330,-7756,22971) #F37A????59BB cielab(95.1095%,-12.8344%,35.0515%)
0,9: (63658,-5539,24281) #F8AA????5ED9 cielab(97.1359%,-8.45197%,37.0504%)
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: ( 0,65535,65534) #0000FFFFFFFE srgb(0%,100%,99.9985%)
0,1: ( 7291,65535,58254) #1C7BFFFFE38E srgb(11.1254%,100%,88.8899%)
0,2: (14565,65535,50972) #38E5FFFFC71C srgb(22.2248%,100%,77.7783%)
0,3: (21845,65535,43691) #5555FFFFAAAB srgb(33.3333%,100%,66.6682%)
0,4: (29126,65535,36408) #71C6FFFF8E38 srgb(44.4434%,100%,55.555%)
0,5: (36407,65535,29127) #8E37FFFF71C7 srgb(55.5535%,100%,44.445%)
0,6: (43690,65535,21846) #AAAAFFFF5556 srgb(66.6667%,100%,33.3349%)
0,7: (50972,65535,14563) #C71CFFFF38E3 srgb(77.7783%,100%,22.2217%)
0,8: (58254,65535, 7284) #E38EFFFF1C74 srgb(88.8899%,100%,11.1147%)
0,9: (65534,65535, 2) #FFFEFFFF0002 srgb(99.9985%,100%,0.0030518%)

The same principle applies to the HDRI results.

Thanks.
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3100
Joined: 2010-01-23T23:01:33+00:00

Re: Lab written as txt:

Postby snibgo » 2013-08-16T13:56:18+00:00

Another simple round-trip test RGB -> Lab-> txt_file -> RGB:
Code: Select all
%I%convert ^
  -size 1x10 ^
  gradient:rgb(0%%,100%%,100%%)-rgb(100%%,100%%,0%%) ^
  -write rgb0.png ^
  -colorspace Lab ^
  -write txt:lab_text.txt ^
  +delete ^
  lab_text.txt ^
  -set colorspace Lab ^
  -colorspace sRGB ^
  rgb1.png

%IM%compare -metric RMSE rgb0.png rgb1.png NULL:

The comparison result should be (very near) zero. It was in v6.7.9 but not in subsequent versions.
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3100
Joined: 2010-01-23T23:01:33+00:00

Re: Lab written as txt:

Postby magick » 2013-08-16T17:09:14+00:00

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.6-9 Beta available by sometime tomorrow. Thanks.
User avatar
magick
Site Admin
 
Posts: 9547
Joined: 2003-05-31T11:32:55+00:00

Re: Lab written as txt:

Postby snibgo » 2013-08-16T17:42:13+00:00

Excellent. Thanks.
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3100
Joined: 2010-01-23T23:01:33+00:00


Return to Bugs

Who is online

Users browsing this forum: No registered users and 4 guests

cron