当前位置:网站首页>Opencv learning -- arithmetic operation of image of basic operation

Opencv learning -- arithmetic operation of image of basic operation

2022-07-04 16:23:00 I won't wait for tomorrow

The addition of images

Adding two images together can use OpenCV Of cv2.add() function , Or simply pass numpy Add two images , Such as res=img1+img2.
The added two images should have Same size and type , Or the second image can be a scalar value .
OpenCV Add and Numpy Between addition Differences exist .OpenCV The addition of is a saturation operation ,Numpy The addition of is a modular operation .

Explanation of differences :

x=np.uint2([250])
y=np.uint8([10])

print(cv2.add(x, y))        #250+10=260=>255    OpenCV Add      Saturation operation 

print(x+y)                #250+10=260%256=4    Numpy Add      Modular arithmetic 
When adding two images , OpenCV The result will be better , therefore Use as much as possible OpenCV The function in .

The blending of images

Image blending is actually addition , But the difference is between the two images Different weights , It gives a sense of mixing or transparency . The calculation formula of image blending is :
g(x)=(1-a)*f0(x)+a*f1(x) 
By modifying the a Value (0-1), Different mixing effects can be achieved .
function cv2.addWeighted() You can mix pictures according to the following formula :
dst=a*img1+b*img2+c    # here c take 0
Image blending function :cv2.addWeighted()
The function prototype : cv2.addWeighted(src1,alpha,src2,beta,c)
src1,src2: Two images that need to be mixed
alpha,beta: The weight , Add to 1
c: The amount of brightness adjustment , Be sure to write , Can write 0, That is, the brightness is not adjusted .
原网站

版权声明
本文为[I won't wait for tomorrow]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141141565536.html