Math Calculations on string constants

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Math Calculations on string constants

Post by fmw42 »

Fx includes the constant QuantumRange. Use it to scale Fx values to the quantum-depth of the ImageMagick release.
Yes, I had never noticed that before. This will be very useful to replace several lines of code in many of my scripts.

However, I am still puzzled how to do any calculation using fx escapes acting upon a string constant such as %{mean] for example.

What I came up with is three awkward alternates and am hoping there is a simpler way.

Code: Select all

mean=`convert image -format "%[mean]" info:`
convert xc: -format "%[fx:255*$mean/quantumrange]" info:
which I can then merge into one awkward command line either as

Code: Select all

echo "scale=0; $(convert image -format "%[mean]" info:) * 255/quantumrange" | bc
or

Code: Select all

convert xc: -format "%[fx:int($(convert image -format "%[mean]" info:)*255/quantumrange)]" info:
This calculation is not anything particular but just an example. I am looking for some way perhaps of doing it more compactly, such as (which does not work):

Code: Select all

convert image -format "%[fx:%[mean]*255/quantumrange}" info:
Is anything like this possible?

Thanks for any suggestions or improvements

Fred
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Math Calculations on string constants

Post by magick »

Grab ImageMagick 6.4.0-11 from ftp://magick.imagemagick.org/pub/ImageMagick/beta in about an hour. Fx now includes 'mean' and 'std':
  • convert logo: -format '%[fx:QuantumRange*mean]' info:
    59085.2
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Math Calculations on string constants

Post by fmw42 »

Thanks. That is terrific.

Don't mean to be a bother, but if it is not too much to ask, could you include the min and max as well. (or next release if you already have -11 finalized)

Fred
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Math Calculations on string constants

Post by magick »

We added

image.depth = image depth
image.minima = image minima
image.maxima = image maxima
image.mean = image mean
image.standard_deviation = image standard deviation

The patch will be available in just a few hours.
Post Reply