Please!!!
Help to find a faster way to do the following
-fx 'sqrt(r**2 + g**2 + b**2)'
please help with fx
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: please help with fx
Try (r*r + g*g + b*b). A multiply is sometimes faster than using **.
Pete
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.
See my message in this topic for a link to a zip of all the files.
Re: please help with fx
Thank you. It can help a bit, indeed.
But fx is very slow anyway. I was hoping to find a non-fx way.
But fx is very slow anyway. I was hoping to find a non-fx way.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: please help with fx
blackswan wrote:Please!!!
Help to find a faster way to do the following
-fx 'sqrt(r**2 + g**2 + b**2)'
I presume r,g,b are the image color channels and that you really need
-fx 'sqrt((r**2 + g**2 + b**2)/3)
to avoid overflow (larger than IM quantumrange for your compile, i.e. 255 for Q8 and 65535 for Q16). If you don't divide by 3, then you get clipping of data at white as your values will be larger than white. If you really need this, then you will have to compile IM in HDRI mode.
convert zelda3.png -set colorspace RGB -separate +channel \
\( -clone 0 -clone 0 -compose multiply -composite \) \
\( -clone 1 -clone 1 -compose multiply -composite \) \
\( -clone 2 -clone 2 -compose multiply -composite \) \
-delete 0-2 -evaluate-sequence mean \
-evaluate pow 0.5 \
zelda3_result.png
see
http://www.imagemagick.org/script/comma ... p#separate
http://www.imagemagick.org/Usage/color_basics/#channels
http://www.imagemagick.org/Usage/compose/#multiply
http://www.imagemagick.org/script/comma ... p#evaluate
http://www.imagemagick.org/script/comma ... e-sequence
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/basics/#parenthesis
viewtopic.php?f=4&t=21269
http://www.imagemagick.org/script/high- ... -range.php
Last edited by fmw42 on 2012-11-06T18:12:56-07:00, edited 1 time in total.
Re: please help with fx
Thank you for your answer. It's not what I'm looking for, unfortunately.
I should explain why I need that operation.
It's a kind of a 3-axis distance function for a RGB difference of two images,
distance = sqrt(r**2 + g**2 +b**2)
it allows to turn RGB difference to a better grayscale one, than allowed by standard operators, I think
I should explain why I need that operation.
It's a kind of a 3-axis distance function for a RGB difference of two images,
distance = sqrt(r**2 + g**2 +b**2)
it allows to turn RGB difference to a better grayscale one, than allowed by standard operators, I think
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: please help with fx
blackswan wrote:Thank you for your answer. It's not what I'm looking for, unfortunately.
I should explain why I need that operation.
It's a kind of a 3-axis distance function for a RGB difference of two images,
distance = sqrt(r**2 + g**2 +b**2)
it allows to turn RGB difference to a better grayscale one, than allowed by standard operators, I think
That is exactly what I coded above, except it is the rms distance. The m means mean. You cannot add 3 values that range 0-255 (0-65535) in IM because it will produce a value larger than 255. Thus things will be clamped at white because IM is compiled as integer unless you compile in HDRI.
so the correct rms distance is
distance = sqrt((r**2 + g**2 +b**2)/3)
If you are on Windows then the syntax is slightly different. Remove the \ and replace the \ at the end of the lines with ^.
See http://www.imagemagick.org/Usage/windows/
which works fine for my images with the code above.
The difference between your result and mine will simply be a factor of sqrt(3). But than puts your result beyond 255 by sqrt(3) and it will be clipped to 255.
Do you really mean that you want:
distance = sqrt(((r1-r2)**2 + (g1-g2)**2 + (b1-b2)**2)/3)
where you have two images: image1 and image2? If so, you can do:
convert image1 image2 -compose difference -composite \
-set colorspace RGB -separate +channel \
\( -clone 0 -clone 0 -compose multiply -composite \) \
\( -clone 1 -clone 1 -compose multiply -composite \) \
\( -clone 2 -clone 2 -compose multiply -composite \) \
-delete 0-2 -evaluate-sequence mean \
-evaluate pow 0.5 \
result1.png
convert image1 image2 -compose difference -composite \
-set colorspace RGB -separate +channel \
\( -clone 0 -clone 0 -compose multiply -composite \) \
\( -clone 1 -clone 1 -compose multiply -composite \) \
\( -clone 2 -clone 2 -compose multiply -composite \) \
-delete 0-2 -evaluate-sequence add \
-evaluate pow 0.5 \
result2.png
However, the latter may overflow white and get clipped at white
see
http://www.imagemagick.org/Usage/compare/#difference
also
http://www.imagemagick.org/Usage/compare/#compare
http://www.imagemagick.org/Usage/compare/#statistics (-metric rmse)