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>You can use the normal sum operations:</p>

<pre><code>img4 = img1 + img2 + img3
</code></pre>

<p>This, however, is not exactly the same as <a href="http://fr.mathworks.com/help/images/ref/imadd.html" rel="nofollow">imadd</a> from matlab. Matplotlib works with RGB values from 0 to 1. As so the sum in some pixels will provide values superior to 1 (which for the array type is valid; the same would not be true if the data type were uint8). As so perform the following operation to guarantee that your data comes out correct:</p>

<pre><code>img1 = matplotlib.image.imread("path1")
img2 = matplotlib.image.imread("path2")
img3 = np.clip(img1 + img2, 0, 1)
</code></pre>

<p>Notice that all images must have the same size.</p>

python image matplotlib