python显示灰度图

import matplotlib 
import matplotlib.pyplot as plt
%matplotlib inline

im=plt.imread('../lena.jpg', pyplot.cm.gray)
plt.imshow(im)

imread()中,第一个参数当然是图像路径和名称,第二个参数设置的是灰度图显示.默认是彩色图,或者把灰度图通过colormap转成彩色图显示.具体可以见下面链接里的,

Colormaps选项,可以设置你选者那种colormap方式其实。

matplotlib的使用详细可以参考这里

http://www.labri.fr/perso/nrougier/teaching/matplotlib/

http://wiki.scipy.org/Cookbook/Matplotlib/Show_colormaps

转载请注明出处,谢谢。
原文地址:https://www.cnblogs.com/jianyingzhou/p/4687016.html