When we talk about images, we know its all about the matrix either binary image(0, 1), gray scale image(0-255) or RGB image(255 255 255). So additions of the image is adding the numbers of two matrices. In OpenCV, we have a command cv2.add() to add the images.
Below is code for Addition of two images using OpenCV :
But sometimes we do not want to perform simple addition in image, so in this case we have blending. This is also image addition, but different weights are given to images so that it gives a feeling of blending or transparency. Images are added as per the equation below :
g(x) = (1 - a)f(x) + af1(x)
By varying a from 0 -> 1, you can perform a cool transition between one image to another. Here two images are taken to blend together. First image is given a weight of 0.3 and second image is given 0.7, cv2.addWeighted() applies following equation on the image :
img = a . img1 + b . img 2 + y
Here y is taken as zero.
Below is code for Blending of images using OpenCV :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
- Python | Create video using multiple images using OpenCV
- Erosion and Dilation of images using OpenCV in python
- Python | Denoising of colored images using opencv
- Python | Grayscaling of Images using OpenCV
- Python - Process images of a video using OpenCV
- Drawing with Mouse on Images using Python-OpenCV
- Measure similarity between images using Python-OpenCV
- Concatenate images using OpenCV in Python
- Stitching input images (panorama) using OpenCV with C++
- Draw geometric shapes on images using OpenCV
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Python OpenCV - Depth map from Stereo Images
- Transition from OpenCV 2 to OpenCV 3.x
- Addition and Subtraction on TimeDelta objects using Pandas - Python
- Python | Copy and Paste Images onto other Image using Pillow
- How to compress images using Python and PIL?
- Get emotions of images using Microsoft emotion API in Python
- How to download Google Images using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.