[Solved] fx operator + while() option doubt

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

[Solved] fx operator + while() option doubt

Post by markmarques »

I am trying to use a small script with the latest version 6.7.6 in windows ...
to calculate the gamma value something like

Code: Select all

 
for /f "tokens=*" %%a in ('convert %1 -format "%%[fx:(log(mean)/log(0.5))]" info: ') DO  set gamma=%%a
for /f "tokens=*" %%a in ('convert null: -format "%%[fx: mgama= %gamma: =% ; while ( mgama > 3.5, mgama = mgama / 2 )  ]" info: ') DO set gamma=%%a
convert %1 -gamma %gamma%  PNG:%1.png
but the previous code does not work ... I get:
"The syntax of the command is incorrect "
If I try something like

Code: Select all

for /f "tokens=*" %%a in ('convert null: -format "%%[fx: while ( %gamma% > 3.5, %gamma% / 2 )  ]" info: ') DO set gamma=%%a
I freezes the batch processing ...
Any ideas ?

According to the docs in fx operator
" while(condition,expression): interate while the condition is not equal to 0 "

What am I doing wrong ?
Last edited by markmarques on 2012-04-24T09:54:44-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: fx operator + while() option doubt

Post by fmw42 »

try replacing null: with xc:
markmarques
Posts: 88
Joined: 2010-06-29T14:36:09-07:00
Authentication code: 8675308

Re: [Solved] fx operator + while() option doubt

Post by markmarques »

It worked with the xc: option ...
and something like this :

Code: Select all

for /f "tokens=*" %%a in ('convert xc: -format "%%[fx:  mgama= %gamma2: =% ; while ( mgama > 3.5, mgama = mgama- (mgama / 10)  )  ]" info: ') DO set gamma2=%%a
Thanks ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [Solved] fx operator + while() option doubt

Post by fmw42 »

Correct.

null: means no image.

xc: by itself means an image of 1x1 that is transparent, I think, but am not positive, or perhaps just a placeholder image?

Convert needs some image to process fx expressions no matter what size or kind.

see
http://www.imagemagick.org/Usage/transf ... fx_escapes
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [Solved] fx operator + while() option doubt

Post by anthony »

Never saw the 'while' expression in FX. I wonder when it was added! It isn't in change log
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [Solved] fx operator + while() option doubt

Post by fmw42 »

Magick wrote me on 11/2/2011

I added robust support for scientific notation to -fx as well as new funcs
such as not(), guass(), squish(), while(), and the Phi constant. In all
likelyhood I broke more than I fixed. Send me any expressions that used
to work but fail now and I'll use the expression to debug -fx.

Note, wait an hour before you download 6.7.3-4 Beta.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [Solved] fx operator + while() option doubt

Post by anthony »

What is the squish function for? From the web docs...
squish(x): squish function; squish(x)=1.0/(1.0+exp(4.0*x))

Note for IMv7 development...
I am trying to decide if I need to remove the % operator from FX, so I can do percent substitutions into the operator before it is processed (perhaps hundreds of times).
The % is the modulus function and mod() function has been in place for some time.

If I allow only multi-character percent escapes, EG: %[...] then their is no conflict as that is a syntax error normally in FX. That is it will not occur naturally! But if you want to be able to do other single letter escapes like %x (X resolution or density) then I will need to remove '%' from normal use.

Note the most useful single letter escapes (width, height, depth, index) are already included as FX varables so that is not a big loss.

I also plan to include some IF type percent escapes, as well as access to things not available at this time like background, and fill colors, and other option settings not currently available. I am surverying the what is available right now, and making improvments before the more serious work.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [Solved] fx operator + while() option doubt

Post by fmw42 »

squish(x): squish function; squish(x)=1.0/(1.0+exp(4.0*x))
Not sure what it is for, but it is just an exponentially decreasing function as shown by

im_graph "-fx 2*squish(u)" squish.gif
Post Reply