How to show matrix as image?

I've got a matrix, which represents to an image. I've load the image, did some modification and wanted to show it as image. how can I do that? I'm using numpy

numpyimagematrix
4 votesJO220.00
2 Answers
JO220.00
1

You can use matplotlib to plot it as an image. It is simple

import matplotlib.pyplot as plt

plt.imshow(matrix)
plt.show()

Whatever you've got in your matrix it will show. If the shape of the image is just (w, h), like it is a gray image, the function will take the minimum and maximum values from the matrix and will plot all values in that range with the corresponding lightness. something like this 

Reply
LP190.00
3

You can use Image class from PIL package

from PIL import Image

img = Image.fromarray(matrix, 'RGB')
img.show()

Obviously, your matrix values should be from [0, 255] range

Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?