Arithmetic operations on PYTHON_OPENCV_ images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.