Page 1 of 1

Pixel Math

Posted: 2015-12-27T10:11:57-07:00
by Deane
I am new to Image Processing in general but familar with code writing. There are so many choices in IM that I am unsure what to use for my application.
First, is there a glossary of IM terms somewhere so I know what Mogrify and other terms mean?
Second, is there a command that allows a math operation on each pixel of two seperate .JPG images to create a third image? I know how to perform the Subtract, Add, Difference commands and that works. But I need to do the following equation:

(Image1pixel value - Image2pixelvalue) / (Image1pixel value + Image2pixelvalue)

Then I need to normalize and stretch the result so it fills the whole 8 bit range of 0 to 255 pixel brightness values. I think I can do that.
Thanks so much for any insight on this!

Re: Pixel Math

Posted: 2015-12-27T12:05:40-07:00
by fmw42
Please read viewtopic.php?f=1&t=9620. Always provide your IM version and platform, since syntax differs.

For new users, see
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/script/comma ... -tools.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/

You can solve your problem two ways.

1) Slow way

Code: Select all

convert image1 image2 -fx "(u-v)/(u+v)" -auto-level result
2) Faster way

(windows syntax)

Code: Select all

convert image1 image2 ^
( -clone 1 -clone 0 -compose minus -composite ) ^
( -clone 1 -clone 0 -compose plus -composite ) ^
( -clone 3 -clone 2 -compose divide -composite ) ^
-delete 0-3 -auto-level result
(unix syntax)

Code: Select all

convert image1 image2 \
\( -clone 1 -clone 0 -compose minus -composite \) \
\( -clone 1 -clone 0 -compose plus -composite \) \
\( -clone 3 -clone 2 -compose divide -composite \) \
-delete 0-3 -auto-level result

See
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/compose/#math
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/color_mods/#stretching

Re: Pixel Math

Posted: 2015-12-27T19:24:57-07:00
by Deane
Thanks very much! Will try this tomorrow. Too late tonight. It looks like what I want!

Sorry I forogt to say what version I have. It is ImageMagick 6.9.0 Q16 (32-bit) Windows on
a Vista op system. I am using the DOS-like command line execution method because I can't find anything
about how to run or use a Graphical User Interface or if there even is one.

Re: Pixel Math

Posted: 2015-12-27T21:02:12-07:00
by fmw42
Imagemagick is for the most part command line driven.

For some GUIs see

http://transloadit.imagemagick.org/MagickStudio/

http://jqmagick.imagemagick.org/