Image Multiplication in Image Processing using OpenCV

In this article, you’ll see image multiplication in image processing using OpenCV. I highly recommend you get the “Computer Vision: Models, Learning, and Inference Book” to learn Computer Vision. For image multiplication in image processing just follow these steps:

Step 1: Install OpenCV

If OpenCV is not installed, then first install it using this code.

pip install opencv-python

Step 2: Import the required libraries

import cv2
import numpy as np

Step 3: Read the Image

Now read the image from the location.

image = cv2.imread("C:\\AiHints\\animal.jpg")

Step 4: Value

The value is 2 which will multiply with all the pixels of the image. For this first, we create a matrix of the same shape.

value = np.ones((image.shape), dtype=np.uint8) * 2

Step 5: Image Multiplication

In this step, multiply the image with a value using the cv2.multiply() function.

mul_img = cv2.multiply(image,value)

Step 6: Display the Output

cv2.imshow("Image", image)
cv2.imshow("Image Multiplication", mul_img)



Original Image
Image Multiplication
Image Multiplication

Example: Multiply two images

import cv2

img1 = cv2.imread("C:\\AiHints\\cat.jpg")
img2 = cv2.imread("C:\\AiHints\\cat.jpg")

add_img = cv2.multiply(img1,img2)

cv2.imshow("Image 1", img1)
cv2.imshow("Image 2", img2)
cv2.imshow("Image Multiplication", add_img)

Original Image
Image Multiplication
Image Multiplication

Leave a Comment

Your email address will not be published.