Re: Accuracy problems with -evaluate, -fx, -function
Posted: 2011-07-02T16:40:08-07:00
by fmw42
I get similar results in IM 6.7.0.10 Q16 Mac OSX Tiger from the following commands:
convert test.pgm -evaluate pow 2 -depth 16 txt:
convert test.pgm -gamma 0.5 -depth 16 txt:
convert test.pgm fx "u*u" -depth 16 txt:
convert test.pgm test.pgm -compose multiply -composite -depth 16 txt:
For example the two items in red come from (12^2 and 10^2)
# ImageMagick pixel enumeration: 9,9,65535,gray
0,0: ( 0, 0, 0) #000000000000 black
1,0: ( 145, 145, 145) #009100910091 gray(0.221256%,0.221256%,0.221256%)
2,0: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
3,0: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
4,0: ( 9, 9, 9) #000900090009 gray(0.0137331%,0.0137331%,0.0137331%)
5,0: ( 101, 101, 101) #006500650065 gray(0.154116%,0.154116%,0.154116%)
6,0: ( 1306, 1306, 1306) #051A051A051A gray(1.99283%,1.99283%,1.99283%)
7,0: ( 7983, 7983, 7983) #1F2F1F2F1F2F gray(12.1813%,12.1813%,12.1813%)
8,0: ( 4128, 4128, 4128) #102010201020 gray(6.29892%,6.29892%,6.29892%)
0,1: ( 9, 9, 9) #000900090009 gray(0.0137331%,0.0137331%,0.0137331%)
1,1: ( 9, 9, 9) #000900090009 gray(0.0137331%,0.0137331%,0.0137331%)
2,1: ( 1, 1, 1) #000100010001 gray(0.0015259%,0.0015259%,0.0015259%)
3,1: ( 16, 16, 16) #001000100010 gray(0.0244144%,0.0244144%,0.0244144%)
4,1: ( 82, 82, 82) #005200520052 gray(0.125124%,0.125124%,0.125124%)
5,1: ( 145, 145, 145) #009100910091 gray(0.221256%,0.221256%,0.221256%)
6,1: ( 3390, 3390, 3390) #0D3E0D3E0D3E gray(5.17281%,5.17281%,5.17281%)
7,1: ( 6132, 6132, 6132) #17F417F417F4 gray(9.35683%,9.35683%,9.35683%)
8,1: ( 3750, 3750, 3750) #0EA60EA60EA6 gray(5.72213%,5.72213%,5.72213%)
0,2: ( 403, 403, 403) #019301930193 gray(0.614939%,0.614939%,0.614939%)
1,2: ( 9, 9, 9) #000900090009 gray(0.0137331%,0.0137331%,0.0137331%)
2,2: ( 9, 9, 9) #000900090009 gray(0.0137331%,0.0137331%,0.0137331%)
3,2: ( 198, 198, 198) #00C600C600C6 gray(0.302129%,0.302129%,0.302129%)
4,2: ( 122, 122, 122) #007A007A007A gray(0.18616%,0.18616%,0.18616%)
5,2: ( 364, 364, 364) #016C016C016C gray(0.555428%,0.555428%,0.555428%)
6,2: ( 5519, 5519, 5519) #158F158F158F gray(8.42145%,8.42145%,8.42145%)
7,2: ( 5371, 5371, 5371) #14FB14FB14FB gray(8.19562%,8.19562%,8.19562%)
8,2: ( 735, 735, 735) #02DF02DF02DF gray(1.12154%,1.12154%,1.12154%)
0,3: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
1,3: ( 82, 82, 82) #005200520052 gray(0.125124%,0.125124%,0.125124%)
2,3: ( 82, 82, 82) #005200520052 gray(0.125124%,0.125124%,0.125124%)
3,3: ( 49, 49, 49) #003100310031 gray(0.0747692%,0.0747692%,0.0747692%)
4,3: ( 227, 227, 227) #00E300E300E3 gray(0.34638%,0.34638%,0.34638%)
5,3: ( 1613, 1613, 1613) #064D064D064D gray(2.46128%,2.46128%,2.46128%)
6,3: ( 6777, 6777, 6777) #1A791A791A79 gray(10.341%,10.341%,10.341%)
7,3: ( 7111, 7111, 7111) #1BC71BC71BC7 gray(10.8507%,10.8507%,10.8507%)
8,3: ( 4798, 4798, 4798) #12BE12BE12BE gray(7.32128%,7.32128%,7.32128%)
0,4: ( 1, 1, 1) #000100010001 gray(0.0015259%,0.0015259%,0.0015259%)
1,4: ( 327, 327, 327) #014701470147 gray(0.49897%,0.49897%,0.49897%)
2,4: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
3,4: ( 0, 0, 0) #000000000000 black
4,4: ( 101, 101, 101) #006500650065 gray(0.154116%,0.154116%,0.154116%)
5,4: ( 2831, 2831, 2831) #0B0F0B0F0B0F gray(4.31983%,4.31983%,4.31983%)
6,4: ( 6612, 6612, 6612) #19D419D419D4 gray(10.0893%,10.0893%,10.0893%)
7,4: ( 3508, 3508, 3508) #0DB40DB40DB4 gray(5.35286%,5.35286%,5.35286%)
8,4: ( 2226, 2226, 2226) #08B208B208B2 gray(3.39666%,3.39666%,3.39666%)
0,5: ( 25, 25, 25) #001900190019 gray(0.0381476%,0.0381476%,0.0381476%)
1,5: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
2,5: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
3,5: ( 1098, 1098, 1098) #044A044A044A gray(1.67544%,1.67544%,1.67544%)
4,5: ( 364, 364, 364) #016C016C016C gray(0.555428%,0.555428%,0.555428%)
5,5: ( 4128, 4128, 4128) #102010201020 gray(6.29892%,6.29892%,6.29892%)
6,5: ( 7983, 7983, 7983) #1F2F1F2F1F2F gray(12.1813%,12.1813%,12.1813%)
7,5: ( 6943, 6943, 6943) #1B1F1B1F1B1F gray(10.5943%,10.5943%,10.5943%)
8,5: ( 1235, 1235, 1235) #04D304D304D3 gray(1.88449%,1.88449%,1.88449%)
0,6: ( 16, 16, 16) #001000100010 gray(0.0244144%,0.0244144%,0.0244144%)
1,6: ( 101, 101, 101) #006500650065 gray(0.154116%,0.154116%,0.154116%)
2,6: ( 122, 122, 122) #007A007A007A gray(0.18616%,0.18616%,0.18616%)
3,6: ( 848, 848, 848) #035003500350 gray(1.29397%,1.29397%,1.29397%)
4,6: ( 2133, 2133, 2133) #085508550855 gray(3.25475%,3.25475%,3.25475%)
5,6: ( 7983, 7983, 7983) #1F2F1F2F1F2F gray(12.1813%,12.1813%,12.1813%)
6,6: ( 6943, 6943, 6943) #1B1F1B1F1B1F gray(10.5943%,10.5943%,10.5943%)
7,6: ( 2725, 2725, 2725) #0AA50AA50AA5 gray(4.15808%,4.15808%,4.15808%)
8,6: ( 1235, 1235, 1235) #04D304D304D3 gray(1.88449%,1.88449%,1.88449%)
0,7: ( 145, 145, 145) #009100910091 gray(0.221256%,0.221256%,0.221256%)
1,7: ( 25, 25, 25) #001900190019 gray(0.0381476%,0.0381476%,0.0381476%)
2,7: ( 16, 16, 16) #001000100010 gray(0.0244144%,0.0244144%,0.0244144%)
3,7: ( 1694, 1694, 1694) #069E069E069E gray(2.58488%,2.58488%,2.58488%)
4,7: ( 6450, 6450, 6450) #193219321932 gray(9.84207%,9.84207%,9.84207%)
5,7: ( 6450, 6450, 6450) #193219321932 gray(9.84207%,9.84207%,9.84207%)
6,7: ( 2520, 2520, 2520) #09D809D809D8 gray(3.84527%,3.84527%,3.84527%)
7,7: ( 1694, 1694, 1694) #069E069E069E gray(2.58488%,2.58488%,2.58488%)
8,7: ( 170, 170, 170) #00AA00AA00AA gray(0.259403%,0.259403%,0.259403%)
0,8: ( 1, 1, 1) #000100010001 gray(0.0015259%,0.0015259%,0.0015259%)
1,8: ( 36, 36, 36) #002400240024 gray(0.0549325%,0.0549325%,0.0549325%)
2,8: ( 198, 198, 198) #00C600C600C6 gray(0.302129%,0.302129%,0.302129%)
3,8: ( 1613, 1613, 1613) #064D064D064D gray(2.46128%,2.46128%,2.46128%)
4,8: ( 4524, 4524, 4524) #11AC11AC11AC gray(6.90318%,6.90318%,6.90318%)
5,8: ( 5081, 5081, 5081) #13D913D913D9 gray(7.75311%,7.75311%,7.75311%)
6,8: ( 3750, 3750, 3750) #0EA60EA60EA6 gray(5.72213%,5.72213%,5.72213%)
7,8: ( 969, 969, 969) #03C903C903C9 gray(1.4786%,1.4786%,1.4786%)
8,8: ( 82, 82, 82) #005200520052 gray(0.125124%,0.125124%,0.125124%)
Re: Accuracy problems with -evaluate, -fx, -function
Posted: 2011-07-06T13:13:38-07:00
by fmw42
I think you have to account for the scaling between 0-1 and quantum range (twice - once manually and once because of the scaling that IM does automatically on output) in your convert command.
That is IM is multiplying 9/255 * 9/255 then multiply by 255 on output. So you need to provide another multiply by 255
convert -size 1x1 xc:"gray(9)" -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 9, 9, 9) #090909 rgb(9,9,9)
convert -size 1x1 xc:"gray(9)" -evaluate pow 2 -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 0, 0, 0) #000000 black
IM 6.7.0.10 Q16 Mac OSX Tiger.
whereas:
convert -size 1x1 xc:"gray(9)" -evaluate pow 2 -evaluate multiply 255 -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 81, 81, 81) #515151 rgb(81,81,81)
convert -size 1x1 xc:"gray(3)" -evaluate pow 2 -evaluate multiply 255 -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 9, 9, 9) #090909 rgb(9,9,9)
convert -size 1x1 xc:"gray(15)" -evaluate pow 2 -evaluate multiply 255 -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (225,225,225) #E1E1E1 rgb(225,225,225)
convert -size 1x1 xc:"gray(15)" -evaluate pow 2 -evaluate multiply 0.99221789883 -depth 16 txt:
# ImageMagick pixel enumeration: 1,1,65535,rgb
0,0: ( 225, 225, 225) #00E100E100E1 rgb(0.343328%,0.343328%,0.343328%)
convert -size 1x1 xc:"gray(25)" -evaluate pow 2 -evaluate multiply 0.99221789883 -depth 16 txt:
# ImageMagick pixel enumeration: 1,1,65535,rgb
0,0: ( 625, 625, 625) #027102710271 rgb(0.953689%,0.953689%,0.953689%)
where .00221789883 = 255*255/65535
For -fx, you need to do the scaling twice so that fx sees 9x9.
convert -size 1x1 xc:"gray(9)" -depth 8 -format "%[fx:u*u]" info:
0.00124567
whereas
convert -size 1x1 xc:"gray(9)" -depth 8 -format "%[fx:255*255*u*u]" info:
81
convert xc: -format "%[fx:9*9]" info:
81