Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

What is the different between adding to images together using "+" and the add() method in Opencv in Python?

So imagine we have two images: img1 and img2. when adding these two together using + or cv2.add() we get different results. Why is that? How are they different?

img = img1 + img2
img = cv2.add(img1, img2)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

from the opencv documentation:

Image Addition You can add two images with the OpenCV function, cv.add(), or simply by the numpy operation res = img1 + img2. Both images should be of same depth and type, or the second image can just be a scalar value.

Note There is a difference between OpenCV addition and Numpy addition. OpenCV addition is a saturated operation while Numpy addition is a modulo operation. For example, consider the below sample:

x = np.uint8([250])
>>> y = np.uint8([10])
>>> print( cv.add(x,y) ) # 250+10 = 260 => 255 
[[255]]
>>> print( x+y )          # 250+10 = 260 % 256 = 4 
[4] 

This will be more visible when you add two images. Stick with OpenCV functions, because they will provide a better result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...