Addition and Blending of images using OpenCV in Python Last Updated : 04 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 : Python # Python program for adding # images using OpenCV # import OpenCV file import cv2 # Read Image1 mountain = cv2.imread('F:\mountain.jpg', 1) # Read image2 dog = cv2.imread('F:\dog.jpg', 1) # Add the images img = cv2.add(mountain, dog) # Show the image cv2.imshow('image', img) # Wait for a key cv2.waitKey(0) # Distroy all the window open cv2.distroyAllWindows() 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 : Python # Python program for blending of # images using OpenCV # import OpenCV file import cv2 # Read Image1 mountain = cv2.imread('F:\mountain.jpg', 1) # Read image2 dog = cv2.imread('F:\dog.jpg', 1) # Blending the images with 0.3 and 0.7 img = cv2.addWeighted(mountain, 0.3, dog, 0.7, 0) # Show the image cv2.imshow('image', img) # Wait for a key cv2.waitKey(0) # Distroy all the window open cv2.distroyAllWindows() Comment More infoAdvertise with us Next Article Animate image using OpenCV in Python K Kishor Mishra Follow Improve Article Tags : Project Python Image-Processing OpenCV Python-OpenCV +1 More Practice Tags : python Similar Reads Erosion and Dilation of images using OpenCV in python Morphological operations are a set of operations that process images based on shapes. They apply a structuring element to an input image and generate an output image. The most basic morphological operations are two: Erosion and Dilation Basics of Erosion: Erodes away the boundaries of the foreground 2 min read Python | Denoising of colored images using opencv Denoising of an image refers to the process of reconstruction of a signal from noisy images. Denoising is done to remove unwanted noise from image to analyze it in better form. It refers to one of the major pre-processing steps. There are four functions in opencv which is used for denoising of diffe 1 min read Concatenate images using OpenCV in Python To concatenate images vertically and horizontally with Python, cv2 library comes with two functions as: hconcat(): It is used as cv2.hconcat() to concatenate images horizontally. Here h means horizontal.vconcat(): It is used as cv2.vconcat() to concatenate images vertically. Here v means vertical.Im 3 min read Animate image using OpenCV in Python In this article, we will discuss how to animate an image using python's OpenCV module. Let's suppose we have one image. Using that single image we will animate it in such a way it will appear continuous array of the same image. This is useful in animating the background in certain games. For example 3 min read Dividing Images Into Equal Parts Using OpenCV In Python In this article, we are going to see how to divide images into equal parts using OpenCV in Python. We are familiar with python lists and list slicing in one dimension. But here in the case of images, we will be using 2D list comprehension since images are a 2D matrix of pixel intensity. Image Used: 3 min read Color Identification in Images using Python - OpenCV An open-source library in Python, OpenCV is basically used for image and video processing. Not only supported by any system, such as Windows, Linux, Mac, etc. but also it can be run in any programming language like Python, C++, Java, etc. OpenCV also allows you to identify color in images. Donât you 3 min read Like