Arithmetic operations using OpenCV | Python Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite: Arithmetic Operations on Images using OpenCV | Basics We can perform different Arithmetic operations on images e.g. Addition, Subtraction, etc. This is possible because images are actually stored as arrays (3 Dimensional for RGB images and 1 dimensional for the grayscale images). Importance of Arithmetic Operations on images: Image Blending: Addition of Images is used for image blending where images are multiplied with different weights and added together to give a blending effect. WaterMarking: It is also based on the principle of addition of very low weight image addition to the original image. Detecting changes in image: Image subtraction can help in identifying the changes in two images as well as to level uneven sections of the image e.g. to handle half part of image which has shadow on it. Code for Image Addition - Python3 1== import cv2 import matplotlib.pyplot as plt % matplotlib inline # matplotlib can be used to plot the images as subplot first_img = cv2.imread("C://gfg//image_processing//players.jpg") second_img = cv2.imread("C://gfg//image_processing//tomatoes.jpg") print(first_img.shape) print(second_img.shape) # we need to resize, as they differ in shape dim =(544, 363) resized_second_img = cv2.resize(second_img, dim, interpolation = cv2.INTER_AREA) print("shape after resizing", resized_second_img.shape) added_img = cv2.add(first_img, resized_second_img) cv2.imshow("first_img", first_img) cv2.waitKey(0) cv2.imshow("second_img", resized_second_img) cv2.waitKey(0) cv2.imshow("Added image", added_img) cv2.waitKey(0) cv2.destroyAllWindows() Output: (363, 544, 3) (500, 753, 3) shape after resizing (363, 544, 3) Code for image Subtraction - Python3 1== import cv2 import matplotlib.pyplot as plt % matplotlib inline first_img = cv2.imread("C://gfg//image_processing//players.jpg") second_img = cv2.imread("C://gfg//image_processing//tomatoes.jpg") print(first_img.shape) print(second_img.shape) # we need to resize, as they differ in shape dim =(544, 363) resized_second_img = cv2.resize(second_img, dim, interpolation = cv2.INTER_AREA) print("shape after resizing", resized_second_img.shape) subtracted = cv2.subtract(first_img, resized_second_img) cv2.imshow("first_img", first_img) cv2.waitKey(0) cv2.imshow("second_img", resized_second_img) cv2.waitKey(0) cv2.imshow("subtracted image", subtracted) cv2.waitKey(0) cv2.destroyAllWindows() Output: (363, 544, 3) (500, 753, 3) shape after resizing (363, 544, 3) Comment More infoAdvertise with us Next Article NumPy - Arithmetic Operations S Sourabh_Sinha Follow Improve Article Tags : Python Image-Processing OpenCV Python-OpenCV Practice Tags : python Similar Reads 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 NumPy - Arithmetic Operations Arithmetic operations are used for numerical computation and we can perform them on arrays using NumPy. With NumPy we can quickly add, subtract, multiply, divide and get power of elements in an array. NumPy performs these operations even with large amounts of data. In this article, weâll see at the 2 min read NumPy - Arithmetic Operations Arithmetic operations are used for numerical computation and we can perform them on arrays using NumPy. With NumPy we can quickly add, subtract, multiply, divide and get power of elements in an array. NumPy performs these operations even with large amounts of data. In this article, weâll see at the 2 min read Python OpenCV - Getting and Setting Pixels In this article, we will discuss Getting and Setting Pixels through OpenCV in Python. Image is made up of pixels. A pixel will be denoted as an array. The 3 integers represent the intensity of red, green, blue in the same order. Eg. [0,0,0] in RGB mode represent black color. There are other modes a 3 min read Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction) Arithmetic Operations like Addition, Subtraction, and Bitwise Operations(AND, OR, NOT, XOR) can be applied to the input images. These operations can be helpful in enhancing the properties of the input images. The Image arithmetics are important for analyzing the input image properties. The operated 3 min read Point Processing in Image Processing using Python-OpenCV OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in todayâs systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a 3 min read Like