IM 6.6.5.0 Q16 HDRI Mac OSX Tiger
Create gradient:
convert -size 1x256 gradient: -rotate 90 grad1.png
This does not work to make an gaussian:
convert grad1.png -fx "exp(-(u)^2)" grad1_gauss_a.png
identify -verbose grad1_gauss_a.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 256x1+0+0
Resolution: 72x72
Print size: 3.55556x0.0138889
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 16-bit
Channel depth:
gray: 1-bit
Channel statistics:
Gray:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
But this works fine:
convert grad1.png -fx "exp(-pow(u,2))" grad1_gauss_b.png
identify -verbose grad1_gauss_b.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 256x1+0+0
Resolution: 72x72
Print size: 3.55556x0.0138889
Units: Undefined
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 16-bit
Channel depth:
gray: 16-bit
Channel statistics:
Gray:
min: 24109 (0.36788)
max: 65535 (1)
mean: 48927 (0.746578)
possible bug -fx ^ vs pow
Re: possible bug -fx ^ vs pow
Try this:
- convert grad1.png -fx "exp(-(u^2))" grad1_gauss_a.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: possible bug -fx ^ vs pow
Now this seems to work.
sig=0.5
convert grad1.png -fx "exp(-((u/$sig)^2))" grad1_gauss_a.png
identify -verbose grad1_gauss_a.png
...
Channel statistics:
Gray:
min: 1200 (0.0183108)
max: 65535 (1)
mean: 28921 (0.441307)
So perhaps I was looking at the wrong result?
But now this is not working (with a radial gradient):
convert -size 256x256 radial-gradient: -negate radgrad256.png
sig=0.5
convert radgrad256.png -fx "exp(-(u/$sig)^2)" radgrad256_gauss_b.png
identify -verbose radgrad256_gauss_b.png
...
Channel statistics:
Gray:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
But this still works:
sig=0.5
convert radgrad256.png -fx "exp(-pow((u/$sig),2))" radgrad256_gauss_a.png
identify -verbose radgrad256_gauss_a.png
...
Channel statistics:
Gray:
min: 1200 (0.0183108)
max: 65527 (0.999878)
mean: 12798.4 (0.195292)
So I am not sure if I am doing something wrong or there is some intermittent issue or what?
sig=0.5
convert grad1.png -fx "exp(-((u/$sig)^2))" grad1_gauss_a.png
identify -verbose grad1_gauss_a.png
...
Channel statistics:
Gray:
min: 1200 (0.0183108)
max: 65535 (1)
mean: 28921 (0.441307)
So perhaps I was looking at the wrong result?
But now this is not working (with a radial gradient):
convert -size 256x256 radial-gradient: -negate radgrad256.png
sig=0.5
convert radgrad256.png -fx "exp(-(u/$sig)^2)" radgrad256_gauss_b.png
identify -verbose radgrad256_gauss_b.png
...
Channel statistics:
Gray:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
But this still works:
sig=0.5
convert radgrad256.png -fx "exp(-pow((u/$sig),2))" radgrad256_gauss_a.png
identify -verbose radgrad256_gauss_a.png
...
Channel statistics:
Gray:
min: 1200 (0.0183108)
max: 65527 (0.999878)
mean: 12798.4 (0.195292)
So I am not sure if I am doing something wrong or there is some intermittent issue or what?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: possible bug -fx ^ vs pow
Looks like a parenthesis handling issue in FX. It really needs a proper parser (lex? yacc? bison?), even if a FX compiler is not yet on the cards.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: possible bug -fx ^ vs pow
Perhaps its not a bug afterall. Take a look at http://www.calculateforfree.com/sci.html. It returns the same results as -fx as follows:
- -(0.5)^2 = 0.25
-(0.5^2) = -0.25
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: possible bug -fx ^ vs pow
magick wrote:Perhaps its not a bug afterall. Take a look at http://www.calculateforfree.com/sci.html. It returns the same results as -fx as follows:
Which suggests the results of exp(-(u)^2) is expected to be different from exp(-(u^2)). Instead exp(-(u^2)) is equivalent to exp(-pow(u,2)).
- -(0.5)^2 = 0.25
-(0.5^2) = -0.25
Thanks. Strange that the parens don't seem to take precedence in -(0.5)^2 = 0.25 and behaves like (-0.5)^2 = 0.25
Not sure I am using your link correctly, but I get from it:
-(0.5)^2 = NaN
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: possible bug -fx ^ vs pow
It isn't the parenthesis precedence, but the precendence between unary minus '-' and '^' The uneray minus should be lower precedence (performed AFTER ^) just as normal + and - operators.
The problem is few languages defined this precedence in relation to other operators.
See http://en.wikipedia.org/wiki/Order_of_o ... _languages
for example which does not list 'power-of' though talks about it in the sections above.
Note the parenthesis in -(0.5)^2 should be equivalent to -0.5^2 if precedence rules are being obeyed correctly.
however whether that results in (-0.5)^2 or -(0.5^2) is a matter for the order of the precedence.
The problem is few languages defined this precedence in relation to other operators.
See http://en.wikipedia.org/wiki/Order_of_o ... _languages
for example which does not list 'power-of' though talks about it in the sections above.
Note the parenthesis in -(0.5)^2 should be equivalent to -0.5^2 if precedence rules are being obeyed correctly.
however whether that results in (-0.5)^2 or -(0.5^2) is a matter for the order of the precedence.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: possible bug -fx ^ vs pow
magick wrote:Under normal left-to-right associativity, -(0.5)^2 is 0.25, however, in Fortran its interpretted as -0.25. We'll investigate supporting the later interpretation in the next few days.
It is not urgent or really needed as long it is explained somewhere.
Re: possible bug -fx ^ vs pow
We can reproduce the problem you posted and have a patch in ImageMagick 6.6.5-4 Beta available by sometime tomorrow. Thanks.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: possible bug -fx ^ vs pow
It has been updated, however i would like to point out that "Debug()" seems to give a indication of how the unary minus is being handled.
Note how the unary minus now expands to be "-1.0" multiplier. And that by precedence ^ is now higher than multiply.
Continuing this, using parenthesis to modify the precedence...
If you are not certain of the order - apply parenthesis, including the operation you want to take precedence.
However the FX page does not list "-(unary)" in its precedence list. (same level as multiply).
As such the parenthesis around the single element no-longer matters, which is as it should be.convert null: -channel R -fx 'debug(-(0.5)^2)' null:
[0,0].red: -1.0*(0.5)^2=-0.25
convert null: -channel R -fx 'debug(-0.5^2)' null:
[0,0].red: -1.0*0.5^2=-0.25
Note how the unary minus now expands to be "-1.0" multiplier. And that by precedence ^ is now higher than multiply.
Continuing this, using parenthesis to modify the precedence...
Which shows parenthesis is doing as it should.convert null: -channel R -fx 'debug(-(0.5^2))' null:
[0,0].red: -1.0*(0.5^2)=-0.25
convert null: -channel R -fx 'debug((-0.5)^2)' null:
[0,0].red: (-1.0*0.5)^2=0.25
If you are not certain of the order - apply parenthesis, including the operation you want to take precedence.
However the FX page does not list "-(unary)" in its precedence list. (same level as multiply).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/