Python OpenCV: Blend Two Images Using cv2.addWeighted()

In python opencv, we can use cv2.addWeighted() method to blend two images easily, it also can allow us to blend images with different weights. In this tutorial, we will introduce you how to do.

Python OpenCV - Blend Two Images Using cv2.addWeighted()

1.Read two images

import cv2

# read two images
src1 = cv2.imread('image1.png', cv2.IMREAD_COLOR)
src2 = cv2.imread('image2.png', cv2.IMREAD_COLOR)

2.Use cv2.addWeighted() to blend two images with different weights

# add or blend the images
dst = cv2.addWeighted(src1, 0.5, src2, 0.5, 0.0)

3.Save blended image

cv2.imwrite('image.png', dst)

Run this code, you will see this image:

Python OpenCV - blend two images