Page 1 of 1
Math Calculations on string constants
Posted: 2008-04-25T21:36:26-07:00
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
Re: Math Calculations on string constants
Posted: 2008-04-26T14:02:21-07:00
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
Re: Math Calculations on string constants
Posted: 2008-04-26T15:30:14-07:00
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
Re: Math Calculations on string constants
Posted: 2008-04-26T17:14:20-07:00
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.