【opencv-python 5】像素运算

算式运算:加、减、乘、除

逻辑运算:与、或、非

直接上代码

import cv2 as cv

# 加
def add_demo(m1,m2):
    dst = cv.add(m1,m2)
    cv.imshow('add_demo',dst)

# 减
def subtract_demo(m1,m2):
    dst = cv.subtract(m1,m2)
    cv.imshow('subtract_demo',dst)

# 除
def divide_demo(m1,m2):
    dst = cv.divide(m1,m2)
    cv.imshow('divide_demo',dst)

# 乘
def multiply_demo(m1,m2):
    dst = cv.multiply(m1,m2)
    cv.imshow('multiply_demo',dst)

# 逻辑
def logic_demo(m1,m2):
    # 与
    dst = cv.bitwise_and(m1,m2)
    cv.imshow('bitwise_and_demo',dst)

    # 或
    dst = cv.bitwise_or(m1,m2)
    cv.imshow('bitwise_or_demo',dst)

    # 非
    dst = cv.bitwise_not(m1)
    cv.imshow('bitwise_not_demo',dst)
        
src1 = cv.imread("D:\images\WindowsLogo.jpg")
src2 = cv.imread("D:\images\LinuxLogo.jpg")
print(src1.shape)
print(src2.shape)

cv.imshow('input WindowsLogo image',src1)
cv.imshow('input LinuxLogo image',src2)

add_demo(src1,src2)
subtract_demo(src2,src1)
divide_demo(src1,src2)
multiply_demo(src1,src2)
logic_demo(src1,src2)

cv.waitKey(0)
cv.destroyAllWindows()

下面是运行效果

【opencv-python 5】像素运算_第1张图片

 

 

你可能感兴趣的:(opencv-python)