Magick++ to average several images

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Bob-O-Rama
Posts: 31
Joined: 2007-11-23T15:34:51-07:00

Magick++ to average several images

Post by Bob-O-Rama »

I have a pile of files say 1.jpg, 2.jpg, 3.jpg,... N.jpg, all same size, depth, etc. I need to merge them together by averaging them. They would all have equal weight in the final image. Obviously I could loop through the images and perform the math on corresponding pixels. ( I may have to do this anyway to later allow for various blending methods to be implemented. ) But I'm assuming there is a way to do this is a more concise way. Any suggestions?

Ultimately I'm interested in some sort of HDR stacking method to sets of bracketed exposures.

Thanks!

-- Bob
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++ to average several images

Post by fmw42 »

Bob-O-Rama wrote:I have a pile of files say 1.jpg, 2.jpg, 3.jpg,... N.jpg, all same size, depth, etc. I need to merge them together by averaging them. They would all have equal weight in the final image. Obviously I could loop through the images and perform the math on corresponding pixels. ( I may have to do this anyway to later allow for various blending methods to be implemented. ) But I'm assuming there is a way to do this is a more concise way. Any suggestions?

Ultimately I'm interested in some sort of HDR stacking method to sets of bracketed exposures.

Thanks!

-- Bob
convert 1.jpg 2.jpg 3.jpg ... N.jpg -average result.jpg

(Too bad there are not equivalent multi-image operators such as -multiply, -minimum and -maximum that work on more than 2 or 3 images at a time).

I am not sure of your HDR and bracketing issues.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Magick++ to average several images

Post by anthony »

fmw42 wrote:(Too bad there are not equivalent multi-image operators such as -multiply, -minimum and -maximum that work on more than 2 or 3 images at a time).
There is, it is called -flatten but you need to set -background color appropriately first!

EG: here are your -multiply, -minimum and -maximum equivelents...

Code: Select all

   convert *.jpg   -background white -compose multiply -flatten result.jpg

Code: Select all

   convert *.jpg   -background white -compose darken -flatten result.jpg

Code: Select all

   convert *.jpg   -background black -compose lighten -flatten result.jpg
Note the color of the background used to so that it does play a part in the results.

I myself like to add up the channels of difference images

Code: Select all

   convert image1 image2 -compose difference -composite \
       -separate -background black -compose Plus -flatten \
difference.png
See IM Examples, Comparing Images, Difference images
http://www.imagemagick.org/Usage/compare/#difference
as well as Channels and Masks, Removing a Known Background
http://www.imagemagick.org/Usage/channels/#mask_bgnd


Of course without HDRI being enabled to handle data overflow, there is no equivalent for -average, which is why it has its own separate operation.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++ to average several images

Post by fmw42 »

anthony wrote:
fmw42 wrote:(Too bad there are not equivalent multi-image operators such as -multiply, -minimum and -maximum that work on more than 2 or 3 images at a time).
There is, it is called -flatten but you need to set -background color appropriately first!

EG: here are your -multiply, -minimum and -maximum equivelents...

Code: Select all

   convert *.jpg   -background white -compose multiply -flatten result.jpg

Code: Select all

   convert *.jpg   -background white -compose darken -flatten result.jpg

Code: Select all

   convert *.jpg   -background black -compose lighten -flatten result.jpg
Note the color of the background used to so that it does play a part in the results.

I myself like to add up the channels of difference images

Code: Select all

   convert image1 image2 -compose difference -composite \
       -separate -background black -compose Plus -flatten \
difference.png
See IM Examples, Comparing Images, Difference images
http://www.imagemagick.org/Usage/compare/#difference
as well as Channels and Masks, Removing a Known Background
http://www.imagemagick.org/Usage/channels/#mask_bgnd


Of course without HDRI being enabled to handle data overflow, there is no equivalent for -average, which is why it has its own separate operation.

Thanks for the information. I did not know you could use -compose options with -flatten.
Post Reply