图像遮挡:
例子1:
import numpy as np
import matplotlib.pyplot as plt
import cv2
#图像遮挡
def show(image):
plt.imshow(image)
plt.axis('off')
plt.show()
def imread(image):
image=cv2.imread(image)
#把图像的BGR转换成RGB
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
return image
image=imread('1.png')
#创建遮挡
mask=np.zeros(image.shape,dtype='uint8')
white=(255,255,255)
cv2.rectangle(mask,(50,50),(250,250),white,-1)
show(mask)
#对图像进行遮挡
masked=cv2.bitwise_and(image,mask)
show(masked)
例子2:
import numpy as np
import matplotlib.pyplot as plt
import cv2
#图像遮挡
def show(image):
plt.imshow(image)
plt.axis('off')
plt.show()
def imread(image):
image=cv2.imread(image)
#把图像的BGR转换成RGB
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
return image
image=imread('1.png')
#创建遮挡
mask=np.zeros(image.shape,dtype='uint8')
white=(255,255,255)
cv2.circle(mask,(150,100),80,white,-1)
show(mask)
#对图像进行遮挡
masked=cv2.bitwise_and(image,mask)
show(masked)
图像通道的切分与合并:
import numpy as np
import matplotlib.pyplot as plt
import cv2
#图像通道切分
def show(image):
plt.imshow(image)
plt.axis('off')
plt.show()
def imread(image):
image=cv2.imread(image)
#把图像的BGR转换成RGB
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
return image
image=imread('1.png')
#图像的切分
(R,G,B)=cv2.split(image)
#图像的合并
merged=cv2.merge([R,G,B])
show(merged)
opencv的显示图像窗口:
import numpy as np
import matplotlib.pyplot as plt
import cv2
#图像通道切分
def show(image):
plt.imshow(image)
plt.axis('off')
plt.show()
def imread(image):
image=cv2.imread(image)
#把图像的BGR转换成RGB
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
return image
image=imread('1.png')
#图像的切分
(R,G,B)=cv2.split(image)
#图像的合并
merged=cv2.merge([R,G,B])
show(merged)
#opencv自带的图像显示器
cv2.imshow('R',R)
cv2.imshow('G',G)
cv2.imshow('B',B)
cv2.waitKey(0)
cv2.destroyAllWindows()
因为都是单通道,显示器默认都是黑白照片哦!