Page 1 of 1

[SOLVED]Windows script driving IM: basic arithmetic on param

Posted: 2014-07-29T23:59:40-07:00
by NicolasRobidoux
Bart van der Wolf, with some assistance from Fred Weinhaus, Alan Gibson and myself, has been polishing a Windows script that combines several ImageMagick commands to produce excellent quality when resizing. (Right now, it only works "perfectly" with sRGB input and output, but this may be extended to other input color spaces later.)
This script: http://www.luminous-landscape.com/forum ... #msg748602.
Now, we would like to be able have the script take an input value (let's call it sharpAmount, for sharpening amount), between 0 and 100, and perform some arithmetic on it in order to pass a derived value, named deblurValue, to -define filter:blur=deblurValue.
Specifically, we would like the relationship between the input and derived value to be as follows:

Code: Select all

deblurValue = 0.88549061701764 + (1 - .01*SharpAmount)*(1-0.88549061701764)
(Of course the expression on the right can be simplified a bit. This is besides the point.)
Does anybody know how to do this (in Windows)?
Link to original question: http://www.luminous-landscape.com/forum ... #msg748960

Re: Windows script driving IM: basic arithmetic on a paramet

Posted: 2014-07-30T01:08:25-07:00
by snibgo
In a Windows BAT script, I would do it like this:

Code: Select all

set SharpAmount=34.56

for /f "usebackq" %%L in (`identify ^
  -format "deblurValue=%%[fx:0.88549061701764 + (1 - .01*%SharpAmount%)*(1-0.88549061701764)]" ^
  xc:`) do set %%L

echo %deblurValue%
Note there are two back-quote characters.

We can do multiple calculations in one go:

Code: Select all

for /f "usebackq" %%L in (`%IM%identify ^
  -format "X=%%[fx:1/2]\nY=%%[fx:2/3]" ^
  xc:`) do set %%L
See my pages for many similar examples.

Re: Windows script driving IM: basic arithmetic on a paramet

Posted: 2014-07-30T01:21:32-07:00
by NicolasRobidoux
Alan: \o/

Re: Windows script driving IM: basic arithmetic on a paramet

Posted: 2014-07-30T01:35:10-07:00
by snibgo
Bart's sample...

Code: Select all

>SET Deblur=100

>SET Deblur=convert xc: -format '%[fx:1-3290*%Deblur%/2873127]' info:

>%deblur%
'0.885491'
...assigns a long string, starting with "convert" to Deblur. That string is a command. So when he executes it as a command, the command runs, and convert runs, returning the value between the required single-quote characters. But it is useless in other contexts.

Re: Windows script driving IM: basic arithmetic on a paramet

Posted: 2014-07-30T04:05:33-07:00
by NicolasRobidoux

Re: [SOLVED]Windows script driving IM: basic arithmetic on p

Posted: 2014-07-30T04:13:46-07:00
by snibgo
Sorry, I'm not a member of that forum.
BartvanderWolf wrote:The only concern I have is that the precision is limited to only a few significant digits.
For greater precision from IM, insert "-precision 9" or whatever before "-format".