Image addition
Cv2 and NumPy provide an implementation of the image addition, you can use the function Cv2.add () to add two images, of course, you can also directly make
With Numpy,res=img1+img. The size of the two images must be the same type, or the second image can make a simple scalar value.
But the two implementations are somewhat different, as an example:
1#-*-coding:utf-8-*-2 3 # Image addition, comparing two different addition operations in NumPy and Cv24 5 Import Cv26Import NumPy asNP7 8x = Np.uint8 ([ -])9y = Np.uint8 ([Ten])TenPrint Cv2.add (x, y) # -+Ten=260=255 One#cv2结果: [[255]] APrint X+y # -+Ten=260% the=4 -#numpy结果: [4]
View Code
Therefore, it is necessary to explain.
The difference between addition in OpenCV and addition of NumPy is that the addition of OpenCV is a kind of saturation operation, and the addition of NumPy is a kind of modulo operation.
This difference is more pronounced when you add two images. The results of the OpenCV will be a little better. So we try to use the functions in OpenCV.
Image blending
This is actually an addition, but the difference is that the weights of the two images are different, which gives the person a feeling of mixing or transparency.
The calculation formula for image blending is as follows:
By modifying the value (0-->1), you can achieve a very cool mix. Now let's mix the two pictures together.
The weight of the first image is 0.7, and the weight of the second picture is 0.3. The function cv2.addweighted () can be used to mix the pictures as shown in the following formula.
The value of R here is 0.
Arithmetic operations on PYTHON_OPENCV_ images