Add images and Threshold – OpenCV 3.4 with python 3 Tutorial 5
We’re going to learn in this tutorial how to add two images using Python and Opencv.
First let’s take two images. There is one condition, the images need to have the exact same size.
There are two different functions to add the images together.
The function cv2.add (see line below) that adds rispectively the pixels of the first image with the one of the second.
sum = cv2.add(img1, img2)
This method is not the right option when we want to add two images, because it will simply add the values together and when they are 255 or over it simply gets white. See the example below.
Instead this method works fine in other type of operations. And we will see that in the next tutorials.
Add weighted images
The second method instead of adding the pixels right away takes also into account the weight we want to assign to each image.
We can assign the weight from 0 to 1.
For example if we want to highlight the car and show a soft background, we could assign 0.7 to the car and 0.3 to the background.
weighted = cv2.addWeighted(img1, 0.3, img2, 0.7, 0)
Hi there, I’m the founder of Pysource.
I’m a Computer Vision Consultant, developer and Course instructor.
I help Companies and Freelancers to easily and efficiently build Computer Vision Software.
Learn to build Computer Vision Software easily and efficiently.
This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.Sign UP for FREE
Detect and Track any Object (Full Videocourse)
You can Build Software to detect and track any Object even if you have a basic programming knowledge.