An arithmetic operation on the image opencv2-- 4

1. The image adder

Use cv2.add () adding the two images, can directly use numpy, res = size img1 + img2. Two images, must be the same type, or the second image may be a simple scalar value.
It is a saturated openCV addition operation, the addition is a molded numpy operation.

np.uint8 = X ([250 ]) 
Y = np.uint8 ([10 ])
 Print (cv2.add (X, Y)) # 250 + 10 = 260.> 255 = 
# results [[255]] 
Print ( Y + X) # 250 = 10 + 255 = 260. 4% 
# results [4]

 

OpenCV results will be better, so try to use the functions in OpenCV

2. The image blending

This is addition, difference is that the right two images of different weight, it tends to give a hybrid or a feeling of transparency. Image mixing the following formula:
G (X) = ([alpha] 1-) F0 (X) + αf1 (X)
by modifying the value of [alpha] (0 -> 1) can be mixed to achieve cool.
Example: mixing two images, a weight of 0.7 to 0.3 second web weight. Function cv2.addWeighed () Images can be mixed in the following formula.
dst = α · img1 + β · img2 + γ
where the value of gamma] 0

 1 import cv2
 2 import numpy as np
 3 img1=cv2.imread('45.jpg')
 4 img2=cv2.imread('messigray.png')
 5 
 6 dst = cv2.addWeighted(img1,0.7,img2,0.3,0)
 7 
 8 cv2.imshow('dst',dst)
 9 cv2.waitKey(0)
10 cv2.destroyAllWindows()

 

 

 3. Bitwise

Here there bitwise operations including: AND, OR, NOT, XOR, etc., when we extract a portion of the image, the ROI selected non-rectangular, will be useful. Below how to change a specific region of FIG.

 

Guess you like

Origin www.cnblogs.com/weststar/p/11510901.html