zhiqingstudy

Be a young person with knowledge and content

In Opencv, two images can operate on each other, including addition, subtraction, multiplication and division. What is the effect of the two images after operation?
1. Addition operation of image
The addition operation of a graph is actually the addition operation of a matrix, so the size of two graphs must be the same to add. The specific api is add (A, B)
2. Subtraction of image
The subtraction api is subtrack (A, B). Subtraction is positional. A-B and B-A are completely different results, so the order should be determined.
3. Multiplication and division of images
The multiplication api is multiply (A, B), and the division api is divide (A, B). Image multiplication and division are similar to addition and subtraction, which can make the picture brighter or darker, and the degree of multiplication and division is greater.
import cv2
import numpy as np

# 导入一张图片
img=cv2.imread('20220627220106.jpg')
# 查看图片尺寸
print(img.shape)

# 创建另外一张图
img1=np.ones((787,1205,3),np.uint8)*100
# 显示原图
cv2.imshow('orig',img)
# 图片相加
result=cv2.add(img,img1)
# 显示相加后的图片
cv2.imshow('result',result)

# 图像相减
img3=cv2.subtract(result,img1)
cv2.imshow('orig_1',img3)

# 图像相乘
img4=cv2.multiply(img,img1)
cv2.imshow('img4',img4)

# 图像相除
img5=cv2.divide(img,img1)
cv2.imshow('img5',img5)

cv2.waitKey(0)
comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号