-fx in Magick++

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

-fx in Magick++

Post by smajler »

Hi would anybody explain me how in Magick++ do multiply and division like this line:

Code: Select all

-fx 'u*v / p{64,64} '
u,v are Images and p{64,64} is a number.
In my code i have:

Code: Select all

Magick::Image u;//somewhere filled with data
Magick::Image v;//filled with data
double p=1;//this is p{64,64};
Magick::Image result;
How can do fx? I found there is a function Image.fx but it gets std::string as parameter which is a mathematical function what to do. Can anybody help me ?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: -fx in Magick++

Post by dlemstra »

How would you do this on the command line?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

Re: -fx in Magick++

Post by smajler »

Code: Select all

convert finalImage -fx 'firstImage * secondImage /1.00 ' .
I think something like that
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -fx in Magick++

Post by magick »

Try image->quantumOperator() with DivideEvaluateOperator or MultiplyEvaluateOperator. You'll need a HDRI-enabled version of ImageMagick to avoid clamping @ [ 0 .. 65535 ].
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

Re: -fx in Magick++

Post by smajler »

I have compiled with HDRI and quantum 8bit. I'll try it at home, thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx in Magick++

Post by fmw42 »

These three should be the same, provided image1 is the grayscale filter image.

Code: Select all

convert image1 image2 -fx 'u*v / p{64,64} ' result

Code: Select all

val=`convert image1 -format "%[pixel:u.p{64,64}]" info:`
convert image1 image2 \
\( -clone 0 -clone 1 -compose multiply -composite \) \
\( +clone -fill "$val" -colorize 100 \) \
-delete 0, 1 \
+swap -compose divide -composite result

Code: Select all

val=`convert image1 -format "%[fx:u.p{64,64}]" info:`
convert image1 image2 \
-compose multiply -composite \
-evaluate divide $val result
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

Re: -fx in Magick++

Post by smajler »

QuantumOperator doesnt work, it looks i need to use image.fx bu how to set std::string as parameter. I need this to rewrite FFT multiply command line script to c++ Magick++ app.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx in Magick++

Post by fmw42 »

Use my alternate commands to avoid -fx
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

Re: -fx in Magick++

Post by smajler »

still stuck on this images multiply. Don't know how to change command expression to c++ code
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx in Magick++

Post by fmw42 »

I do not code Magick++, but my best guess is sea composite at http://www.imagemagick.org/Magick++/Image.html, with compose_ = multiply
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: -fx in Magick++

Post by el_supremo »

I found there is a function Image.fx but it gets std::string as parameter which is a mathematical function what to do.
The string parameter is just the formula that was specified in the command line version "u*v / p{64,64}"
fx also takes a second parameter which is the channels which are affected. This might default to all channels if it isn't specified
- I'm not familiar with C++.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

Re: -fx in Magick++

Post by smajler »

Code: Select all

convert image1 image2 -fx 'u*v ' result.png
in command to the same as:

Code: Select all

Magick::Image  test("test.png");
	Magick::Image kernel("kernel.png");
test.composite(kernel,0,0,MultiplyCompositeOp);
	test.write("result.png");
But i found that there is no division composite operator for division.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: -fx in Magick++

Post by el_supremo »

In MagickCore/composite.h there are these two composite operations:

Code: Select all

  DivideDstCompositeOp,
  DivideSrcCompositeOp,
Would either of those help? Again, I'm not familiar with C++/Magick++ so I don't know how to apply these to a Magick++ program.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
smajler
Posts: 28
Joined: 2013-05-17T09:26:53-07:00
Authentication code: 6789

Re: -fx in Magick++

Post by smajler »

Next problems, now i need to divide by center pixel like:
/ p{64,64} ' \) \
but composite gets whole image not a value of pixel, and also what is the function for mod:
to do something like this:
mod(u + v + 0.5, 1.0), u, v are my images
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx in Magick++

Post by fmw42 »

Skip all the fx stuff and do it with composite math as per http://www.imagemagick.org/Usage/fourie ... ultiply_mp


Code: Select all

convert convolve_kernel.png -roll -64-64 -fft \
          \( -clone 0 -crop 1x1+64+64 +repage -scale 128x128 \
             -clone 0 -compose divide -composite \) -swap 0 +delete \
          \( cameraman_sm.png -fft \) \
          \
          \( -clone 0,2 -compose multiply -composite \) \
          \( -clone 1,3 -compose add -background gray50 -flatten \) \
           -delete 0-3 -ift  cameraman_convolve_2.png
Post Reply