"Python+opencv learning" first, Gui Features in Opencv (2) matplotlib display picture __python

Source: Internet
Author: User

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 ...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.