Combine multiple images using vips (ruby-vips8)
<p>How do I apply a function to corresponding pixels of two images of the same resolution? Like Photoshop does when covering one layer with another one. What about more than two images?</p>

<p>If it was Wolfram Mathematica I would take a List of those images and transpose them to get a single "image" where each "pixel" would be an array of N pixels -- there I would apply a <code>Mean[]</code> function to them.</p>

<p>But how do I do that with vips? There are so many <a href="http://www.rubydoc.info/gems/ruby-vips8/Vips/Image" rel="nofollow">Vips::Image</a> methods and only <a href="http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/libvips-conversion.html#vips-bandmean" rel="nofollow">here</a> I could find some minimal description on what do they all mean. So for example:</p>

<pre><code>images = Dir["shots/*"].map{ |i| Vips::Image.new_from_file(i) }
ims = images.map(&amp;:bandmean)
(ims.inject(:+) / ims.size).write_to_file "temp.png"
</code></pre>

<p>I wanted it to mean "calculating an average image" but I'm not sure what I've done here.</p>