如何在python中查看图像的整个矩阵? [英] How to see the whole matrix of an image in python?

查看:1760
本文介绍了如何在python中查看图像的整个矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想想象一下图像如何表示为矩阵。我已经使用了这个答案视角,第二个答案并使用了matplotlib。图像模块。

I want to visualize how an image is represented as a matrix. I have used this answers perspective, the 2nd answer and used matplotlib.image module.

现在,当我尝试打印矩阵时,由于图像由大量像素组成,因此矩阵未完全显示。如何查看完整矩阵?

Now when I try to print the matrix, since the image consists of a large number of pixels, the matrix is not fully shown. How to see the full matrix?

我使用Anaconda编译器和Spyder作为IDE,所有最新版本。

I am using Anaconda compiler with Spyder as the IDE, all latest versions.

推荐答案

您可以使用matplotlib读取图像,然后将其另存为文件

You can use matplotlib to read the image and then save it as a file

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()

这篇关于如何在python中查看图像的整个矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆