7
convert -average darky1.jpg darky2.jpg lighty1.jpg lighty2.jpg l.ppm
convert -average lighty1.jpg lighty2.jpg lighty1.jpg lighty2.jpg d.ppm

l.ppm is much lighter than d.ppm. The order of images matters (but should not).

The same for using evaluate-sequence mean.

How to do it properly?

Vi.
  • 17,175

3 Answers3

4

Just use GraphicsMagick: gm convert -average *.JPG q.ppm

Vi.
  • 17,175
  • 7
    Big disadvantage: it tries to load all input images into memory. /* Alt+SysRq+F */ – Vi. Mar 12 '11 at 23:39
3

8 years on, this still seems to be a problem, with no satisfactory answers in the StackExchange family.

From this blog post:

ImageMagick's -average operator averages two images at once: the currently considered image, and the result of the previous averaging. It then moves on to the next image.

So rather than every image in the sequence having the same weight, the later images have a higher weight. This doesn't give the result pretty much everybody using this option would intuitively expect. There is also the problem that all the images need to be loaded into memory.

The solution to both problems is a script to call convert recursively, on pairs of images, like this:

#!/bin/bash

i=0
for file in img*jpg; do
    echo -n "$file.. "
    if [ $i -eq 0 ]; then
        cp $file avg.jpg
    else
        convert $file avg.jpg -fx "(u+$i*v)/$[$i+1]" avg.jpg
    fi
    i=$[$i+1]
done
  • This works great - I presume the part of the command in the quotes weights the image by 1/i as it goes through the list of images, but it would be nice to understand what the parts mean. – Phil Rosenberg Dec 16 '20 at 23:44
  • 3
    This blog post is outdated, and the script is no longer needed. Using the "wrong" example of convert img*jpg -average avg.jpg works correctly nowadays. Tested with ImageMagick 7.1.0-4. – makeworld Aug 22 '21 at 23:34
  • The advantage of the script now is that it doesn't require loading all the images into memory. – makeworld Aug 23 '21 at 00:05
3

From the ImageMagick forum:

convert darky1.jpg darky2.jpg lighty1.jpg lighty2.jpg -evaluate-sequence Mean avg.ppm

Beware: this loads all images into memory at once.

Chortos-2
  • 129