How to save Numpy array as image in python?

0 votes

I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works (png, jpeg, bmp...). One important constraint is that PIL is not present.

Nov 16, 2018 in Python by Anirudh
• 2,080 points
5,635 views

1 answer to this question.

0 votes

If you have matplotlib, you can do:

import matplotlib.pyplot as plt
plt.imshow(matrix) #Needs to be in row,col order
plt.savefig(filename)

This will save the plot (not the images itself).

answered Nov 16, 2018 by Nymeria
• 3,540 points

Related Questions In Python

0 votes
1 answer

How to save an image locally using Python in which we already know the URL address?

Hi, @Roshni, The following code is used to ...READ MORE

answered Jun 26 in Python by Gitika
• 31,430 points
38 views
+4 votes
7 answers
+2 votes
11 answers
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,076 views
0 votes
0 answers
0 votes
1 answer

How to use Pandas HDF5 as a Database in Python?

HDF5 works fine for concurrent read only ...READ MORE

answered Nov 30, 2018 in Python by Nymeria
• 3,540 points

edited Dec 10, 2018 by Nymeria 215 views
0 votes
1 answer