加、减、乘、除、均值、方差
与、或、非
亮度、对比度的修改
来看一下总体的代码
import cv2
import numpy as np
def add_demo(m1,m2):#加运算
dst=cv2.add(m1,m2)
cv2.imshow("add_demo",dst)
def subtract_demo(m1,m2):#减运算
dst=cv2.subtract(m1,m2)
cv2.imshow("subtract_demo",dst)
def divide_demo(m1,m2):#除运算
dst=cv2.divide(m1,m2)
cv2.imshow("divide_demo",dst)
def multiply_demo(m1,m2):#除运算
dst=cv2.multiply(m1,m2)
cv2.imshow("multiply_demo",dst)
def others(m1,m2):#求均值与方差的运算
M1 =cv2.meanStdDev(m1) #均值与方差,用来判断是否有图像上面,如果均值方差都为0则没有图像
M2 =cv2.meanStdDev(m2)
h,w=m1.shape[:2]
print(M1)
print(M2)
img=np.zeros([h,w],np.uint8)
m=cv2.meanStdDev(img)
print(m)
def bit_and(m1,m2):#与运算
dst=cv2.bitwise_and(m1,m2);
cv2.imshow("bit_and",dst)
def bit_or(m1,m2):#或运算
dst=cv2.bitwise_or(m1,m2);
cv2.imshow("bit_or",dst)
def bit_not(m1):#非运算
dst=cv2.bitwise_not(m1);
cv2.imshow("bit_not",dst)
def constrst_brightness_demo(image,c,b): #给image图像对比度设为c,亮度在之前范围内提高b
h, w, ch = image.shape
blank = np.zeros([h, w, ch], image.dtype)
dst = cv2.addWeighted(image, c, blank, 1-c, b) #修改对比度、亮度
cv2.imshow("con-bri-demo", dst)
print("------Hello Python-------")
src1 =cv2.imread("LinuxLogo.jpg")
src2 =cv2.imread("WindowsLogo.jpg")
print(src1.shape)
print(src2.shape)
cv2.imshow("image1",src1)
cv2.imshow("image2",src2)
print("------PIXEL MATH DEAL-------")
add_demo(src2,src1)
subtract_demo(src1,src2)
divide_demo(src2,src1)
multiply_demo(src1,src2)
others(src1,src2)
print("------PIXEL LOGIC DEAL-------")
bit_and(src2,src1)
bit_or(src1,src2)
bit_not(src1)
print("------PIXEL BRIGHTNESS DEAL-------")
constrst_brightness_demo(src1,1.1,-20)#在原来图片的基础上对比度增强1.1,亮度减小20
cv2.waitKey(0)
cv2.destroyAllWindows()
原图长这个样
(1)加法
(2)减法
image1-image2 image2-image1
(3)乘法
(4)除法
image1/image2 image2/image1
(5)均值与方差:为了获得图片上的一定的信息
用来判断是否有图像上面,如果均值方差都为0则没有图像
(1)逻辑与
(2)逻辑或
(3)逻辑非