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)
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Opencv Beginner Tutorial
- 1) Loading images
- 2) Loading Video and Webcam
- 3) Drawing and writing on images
- 4) Basic operations on images
- 5) Add images and Threshold
- 6) Blending images
- 7) Bitwise Operators
- 8) Trackbars
- 9) Object detection using HSV Color space
- 10) Basic Thresholding
- 11) Histograms
- 12) Basic geometric transformations
- 13) Perspective transformation
- 14) Affine transformation
- 15) Adaptive thresholding5
- 16) Smoothing images
- 17) Morphological transformation
- 18) Edge detection
- 19) Find and Draw Contours
- 20) Template matching
- 21) Lines detection with Hough Transform
- 22) Corners detection
- 23) Image Pyramids
- 24) Image Pyramids (Blending and reconstruction)
- 25) Feature detection (SIFT, SURF, ORB)
- 26) Feature Matching (Brute-Force)
- 27) Mouse Events
- 28) Histogram and Back Projection
- 29) Object tracking with Mean-shift
- 30) Object tracking with Camshift
- 31) Optical Flow with Lucas-Kanade method
- 32) Background Subtraction
- 33) k-Nearest Neighbour classification
- 34) Object tracking using Homography
- 35) Fourier Transform
- 36) Knn handwritten digits recognition
- 37) Face detection using Haar Cascades
- Train YOLO to detect a custom object (online with free GPU)
- YOLO object detection using Opencv with Python
- Detecting colors (Hsv Color Space) – Opencv with Python
- How to install Python 3 and Opencv 4 on Windows
- Check if two images are equal with Opencv and Python
- How to install Dlib for Python 3 on Windows
- Feature detection (SIFT, SURF, ORB) – OpenCV 3.4 with python 3 Tutorial 25
- Simple shape detection – Opencv with Python 3