图像按位计算

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(rectangle, circle)
show(image)

# OR,或操作,有白就变白
image = cv2.bitwise_or(rectangle, circle)
show(image)

# XOR,异或操作,黑白变白,黑黑和白白变黑
image = cv2.bitwise_xor(rectangle, circle)
show(image)

# NOT, 非操作,颜色取反
image = cv2.bitwise_not(circle)
show(image)

 

posted @ 2020-08-30 09:12  yunshangyue  阅读(150)  评论(0编辑  收藏  举报