Page 1 of 2
-fx in Magick++
Posted: 2013-11-05T02:20:03-07:00
by smajler
Hi would anybody explain me how in Magick++ do multiply and division like this line:
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 ?
Re: -fx in Magick++
Posted: 2013-11-05T03:39:48-07:00
by dlemstra
How would you do this on the command line?
Re: -fx in Magick++
Posted: 2013-11-05T05:59:59-07:00
by smajler
Code: Select all
convert finalImage -fx 'firstImage * secondImage /1.00 ' .
I think something like that
Re: -fx in Magick++
Posted: 2013-11-05T07:05:36-07:00
by magick
Try image->quantumOperator() with DivideEvaluateOperator or MultiplyEvaluateOperator. You'll need a HDRI-enabled version of ImageMagick to avoid clamping @ [ 0 .. 65535 ].
Re: -fx in Magick++
Posted: 2013-11-05T07:57:22-07:00
by smajler
I have compiled with HDRI and quantum 8bit. I'll try it at home, thanks.
Re: -fx in Magick++
Posted: 2013-11-05T10:46:48-07:00
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
Re: -fx in Magick++
Posted: 2013-11-05T14:33:01-07:00
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.
Re: -fx in Magick++
Posted: 2013-11-05T17:11:34-07:00
by fmw42
Use my alternate commands to avoid -fx
Re: -fx in Magick++
Posted: 2013-11-06T14:05:56-07:00
by smajler
still stuck on this images multiply. Don't know how to change command expression to c++ code
Re: -fx in Magick++
Posted: 2013-11-06T14:11:10-07:00
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
Re: -fx in Magick++
Posted: 2013-11-06T18:41:36-07:00
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
Re: -fx in Magick++
Posted: 2013-11-07T01:05:28-07:00
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.
Re: -fx in Magick++
Posted: 2013-11-07T09:04:07-07:00
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
Re: -fx in Magick++
Posted: 2013-11-14T08:55:07-07:00
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
Re: -fx in Magick++
Posted: 2013-11-14T10:35:12-07:00
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