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)
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:
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.
1.2m questions
2.1m answers
5 comments
56.5k users