我想形象化如何将图像表示为矩阵。我已使用此答案透视图the 2nd answer并使用了matplotlib.image模块。
现在,当我尝试打印矩阵时,由于图像包含大量像素,因此矩阵无法完全显示。如何看完整矩阵?
我正在将Anaconda编译器与Spyder用作IDE,所有最新版本。
最佳答案
您可以使用matplotlib读取图像,然后将其另存为文件
In [21]: import json
In [22]: from matplotlib import image
In [23]: f = open("out.json", "w")
In [24]: c = image.imread("02.jpg")
In [25]: f.write(json.dumps(c.tolist(), indent=4))
Out[25]: 10925444
In [26]: f.close()