The main implementation of this paper is to display grayscale images and color images with matplotlib.
Some students in the use of matplotlib display color images, will get undesirable effects, specific reasons and solutions please see below.
1. matplotlib Display grayscale Images
Import Cv2
from matplotlib import pyplot as Plt
img = cv2.imread (' test.jpg ', 0)
plt.imshow (img, cmap = ' gray ')
#plt. Xticks ([]), Plt.yticks ([]) #去除横纵坐标
plt.show ()
2. Matplotlib Display color image
Sometimes when you display color images with matplotlib, the results are not satisfactory because:
Matplotlib is RGB, and OPNECV is BGR, all we need to first read the OPENCV into the color image into B, G, r three channels, and then in R, G, b Order merged three channels, the code is as follows
img = cv2.imread (' test.jpg ')
B, g, r = Cv2.split (img)
img2 = Cv2.merge ([R, G, b])
Plt.subplot (121); Plt.imshow (IMG)
plt.subplot (122);p lt.imshow (IMG2)
plt.show ()
Take another look at the following code:
Import Cv2 from
matplotlib import pyplot as Plt
img = cv2.imread (' test.png ')
B, g, r = Cv2.split (IMG)
Img2 = Cv2.merge ([R, G, b])
cv2.imshow (' BGR image ', img)
cv2.imshow (' RGB image ', img2)
cv2.waitkey (0) C17/>cv2.destroyallwindows ()
Know where it's different ...