matlplotlib figure imshow

来源:互联网 发布:爆破作业模拟考试软件 编辑:程序博客网 时间:2024/05/05 03:48

matplotlib

在pycharm中处理图像和显示时,使用plt.imshow()有时候能显示图像,有时候又不能,发现少了一句plt.show()——Show result on screen,还是得把文档资料看完整啦~~

import matplotlib.pyplot as pltimport matplotlib.image as mgimgimport os   #for open fileimport cv2imgpath = "./imgtest"imglist = os.listdir(imgpath)for i in xrange(len(imglist)):    """choice one----cv2"""    img = cv2.imread(imgpath + '/' + imglist[i])    cv2.imshow('img', img)    cv2.waitKey()    """choice two----mgimg"""    img = mpimg.imread(imgpath + '/' + imglist[i])    plt.imshow(img)    plt.show()

两者区别好像不大(?),官网上说Natively, matplotlib only supports PNG images. 但是测试的时候用jpg图像仍然可以正常运行显示。
http://matplotlib.org/users/image_tutorial.html
使用时有时候混淆了两种方法,如果用cv2.imread()图像,plt.imshow()显示图像,会发现原图的颜色有变化。

原图:

plt.imshow()显示(可显示坐标及对应像素值,这点比cv2方便):
plt.imshow

颜色变化:
colorwrong

解释:
cv2中的色彩排列是(b,g,r),而matplotlib库中的排列方式是(r,g,b)!
reference:http://www.cnblogs.com/pakfahome/p/3917143.html

matplotlib用法这里有总结啦
http://liam0205.me/2014/09/11/matplotlib-tutorial-zh-cn/

0 0
原创粉丝点击