"distortion" can't be used in fx

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

"distortion" can't be used in fx

Post by snibgo »

We can do a "compare" in a magick command like this:

Code: Select all

magick rose: rose: -metric RMSE -compare -format %[distortion] info:

0
The "distortion" is always a number, but for some reason we can't use it in an fx expression:

Code: Select all

magick rose: rose: -metric RMSE -compare -format %[fx:distortion] info:

magick: unable to parse expression `distortion' @ error/fx.c/FxGetSymbol/1833.
Being able to use it in an fx expression would simplify things when we need to compare the distortion number to a limit. Can this be corrected, please?

Tested with IM v7.0.7-28 on Windows 8.1.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "distortion" can't be used in fx

Post by fmw42 »

None of the %[xxx] can be used in an expression in fx: computations. You need to store them in a variable and then use the variable in the fx: computation. I would agree that it is too bad. I think it was done that way, since most of the single lower and upper case letters were used already in the string formats. I am not sure if it is even possible to add more names to -fx. If possible that would be nice. But note that for example %[mean] has range 0 to quantum range and %[fx:mean] is in the range 0 to 1. Though that is not something that could not be overcome as %[fx:mean*quantumrange].
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "distortion" can't be used in fx

Post by snibgo »

I think the change required is simple, in FxGetSymbol() in fx.c. But I could be wrong. I can multiply by QuantumRange if I need to. For example:

Code: Select all

magick rose: rose: -metric RMSE -compare -format %[depth] info:
8

magick rose: rose: -metric RMSE -compare -format %[fx:depth] info:
0.000244144

magick rose: rose: -metric RMSE -compare -format %[fx:depth*quantumrange] info:
16
(I don't know why the last result is 16, not 8?)
snibgo's IM pages: im.snibgo.com
Post Reply