How can I add two or more images using matplotlib?
<p>I read the images using imread and then I would like to compute the average image. How can I add(and divide) using matplotlib?</p>

<p>I'm searching for something like imadd in matlab.</p>

<p>Code:</p>

<pre><code>img1 = matplotlib.image.imread("path")
img2 = matplotlib.image.imread("path1")
img3 = matplotlib.image.imread("path2")
</code></pre>

<p>Thanks</p>

<p><code>matplotlib.image</code> is probably what you are looking for. You'll also need <code>numpy</code> if you want to manipulate the images otherwise, because they are basically just arrays in the size of the image (e.g. 1920 x 1080) with 3 or 4 dimensions (RGB or RGBA).</p>

<pre><code>import matplotlib.image as mpimg
import matplotlib.pyplot as plt

img1 = mpimg.imread("foo.png")
img2 = mpimg.imread("bar.png")
</code></pre>

<p>Now you are setup for image manipulation. In the case that your images are both in the same format and size (e.g. RGB. Check by using <code>img1.shape</code> and <code>img2.shape</code>) you can do:</p>

<pre><code>img3 = plt.imshow((img1 + img2) / 2)
</code></pre>

python image matplotlib