python matplotlib显示无插值的逐像素图像

时间:2015-09-17 20:00:59

标签: python image matplotlib pixel

import matplotlib
from matplotlib import pyplot as plt
%matplotlib inline

arr = np.array([[130,146,133,95,71,71,62,78],
                [130,146,133,92,62,71,62,71],
                [139,146,146,120,62,55,55,55],
                [139,139,139,146,117,112,117,110],
                [139,139,139,139,139,139,139,139],
                [146,142,139,139,139,143,125,139],
                [156,159,159,159,159,146,159,159],
                [168,159,156,159,159,159,139,159]
               ])

所以我想重新构建这个图像

enter image description here

我有每个像素的灰度颜色,我使用以下python代码(python 3,jupyter)

import matplotlib.image as mpimg
import matplotlib.cm as cm

fig = plt.figure(1, figsize=(8,6), dpi=64)
ax = fig.gca()
ax.autoscale_view(True, False, False)
plt.imshow(arr, cmap = cm.gray)
plt.show()

但我得到的结果是这张图片,但我希望将它显示为原始图像!

enter image description here

0 个答案:

没有答案