import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread('./01.jpg')
# opencv 读入图片是BGR的,但是matplotlib默认是RGB的,所以需要转换
new_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 或者使用数组翻转实现通道变换
# h,w,ch=img.shape
# new_img=np.zeros_like(img)
# for i in range(ch):
# for x in range(h):
# for y in range(w):
# new_img[x,y,i]=img[x,y,2-i]
plt.figure("Image") # 图像窗口名称
plt.imshow(new_img)
plt.axis('on') # 关掉坐标轴为 offnp.like
plt.title('image') # 图像题目
plt.show()
##灰色图
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
img = np.full((50,50),fill_value=150,dtype=np.uint8)
plt.imshow(img,cmap='gray',vmin=0,vmax=255)
plt.show()
# cv.imshow('image',img)
# cv.waitKey(0)