Blend (mix) refers to mixing images with a weighted sum of 1

Import Libraries


In [1]:
import cv2

In [2]:
import matplotlib.pyplot as plt

Read Images


In [3]:
img1 = cv2.imread('demo1.jpg', cv2.IMREAD_GRAYSCALE)

In [4]:
img2 = cv2.imread('nature.jpg', cv2.IMREAD_GRAYSCALE)

In [5]:
plt.figure(figsize=(10,8))


Out[5]:
<matplotlib.figure.Figure at 0x7f99679ecd68>

In [6]:
plt.subplot(1,2,1)


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f99679ecd30>

In [7]:
plt.title('Shooter')


Out[7]:
<matplotlib.text.Text at 0x7f9967709320>

In [8]:
plt.imshow(img1, cmap='gray')


Out[8]:
<matplotlib.image.AxesImage at 0x7f99676b3278>

In [9]:
plt.subplot(1,2,2)


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f99676b3320>

In [10]:
plt.title('Nature')


Out[10]:
<matplotlib.text.Text at 0x7f9967683be0>

In [11]:
plt.imshow(img2, cmap='gray')


Out[11]:
<matplotlib.image.AxesImage at 0x7f99676367b8>

In [12]:
plt.show()


Blend Images

Say we want more of nature than shooter, let alpha = 0.3 for shooter. Therefore, for nature, it will be 1 - alpha = 0.7

In [13]:
alpha = 0.3

In [14]:
img = (alpha*img1) + ((1-alpha)*img2)

In [15]:
plt.imshow(img, cmap='gray')


Out[15]:
<matplotlib.image.AxesImage at 0x7f99644b5ef0>

In [16]:
plt.show()


See, isn't it look like a camouflaged shooter in nature. Similarly, we can play with the alpha value to get the desired blend of images