OpenCV:图像的按位运算


首先导包:

import numpy as np
import cv2
import matplotlib.pyplot as plt
def show(image):
    plt.imshow(image)
    plt.axis('off')
    plt.show()
def imread(image):
    image=cv2.imread(image)
    image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
    return image
rectangle=np.zeros((300,300,3),dtype='uint8')
#我们来画一个矩形
white=(255,255,255)
cv2.rectangle(rectangle,(25,25),(275,275),white,-1)
show(rectangle)
circle=np.zeros((300,300,3),dtype='uint8')
cv2.circle(circle,(150,150),150,white,-1)
show(circle)
#AND操作,有黑就变黑
image=cv2.bitwise_and(circle,rectangle)
show(image)
#or操作,有白就变白
image=cv2.bitwise_or(circle,rectangle)
show(image)#貌似按位操作就只有0和1这两种图像的状态,奇怪了
#XOR操作,同种颜色变黑,不同颜色变白
image=cv2.bitwise_xor(circle,rectangle)
show(image)#貌似按位操作就只有0和1这两种图像的状态,奇怪了

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM