DuttaA
DuttaA

Reputation: 923

How to see the whole matrix of an image in python?

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?

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

Upvotes: 1

Views: 702

Answers (1)

Arpit Solanki
Arpit Solanki

Reputation: 9931

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

Upvotes: 3

Related Questions