You can add two images either using OpenCV:
cv2.add() or Numpy:
result = img1 + img2
(Both images should be of same depth and type.)There is a major difference between these two.
>>> x = np.uint8()
>>> y = np.uint8()
>>> print cv2.add(x,y) # 250+10 = 260 => 255
>>> print x+y # 250+10 = 260 % 256 = 4
*OpenCV provides better results
Adding images using the previous method is very blunt. Using blending you can get cool transition between two images.
Blending is done by using the OpenCV function
cv2.addWeighted() using the formula:
f(x)=a*img1 + (1-a)img2 + z
where a is the weight.
What we basically do is provide weights to the two images such that they mix with different intensities.
The following code adds two images with weights 0.7 and 0.3.
(Both images should be of same depth and type)
img1 = cv2.imread('img1.png')
img2 = cv2.imread('img2.jpg')
result = cv2.addWeighted(img1,0.7,img2,0.3,0) # z is taken as 0