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

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
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

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

Post 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
Last edited by NicolasRobidoux on 2014-07-30T04:06:26-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

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

Post by NicolasRobidoux »

Alan: \o/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

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

Post by NicolasRobidoux »

snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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".
snibgo's IM pages: im.snibgo.com
Post Reply