# Addition and Blending of images using OpenCv in Python

PythonProgrammingServer Side Programming

We know that when we solve any image related problem, we have to take a matrix. The matrix content will vary depending upon the image type - either it would be a binary image(0, 1), gray scale image(0-255) or RGB image(255 255 255). So if we want to add of two images then that means very simple we have to add respective two matrices.

In OpenCV library, we have a function cv2.add() to add the images. But for image addition the size of the two images should be same.

import cv2
cv2.imshow('image', my_firstpic)
cv2.waitKey(0)
cv2.distroyAllWindows()


## Blending of two images

cv2.addWeighted() function is used for blending of two images.

## Example code

import cv2
# Blending the images with 0.3 and 0.7
My_img = cv2.addWeighted(My_first, 0.3, My_second, 0.7, 0)
# Show the image
cv2.imshow('image', My_img)
# Wait for a key
cv2.waitKey(0)
# Destroy all the window open
cv2.distroyAllWindows()


## Output

Published on 23-Nov-2018 05:25:15