Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert ndarray to image and display it using python

I have converted set of images to ndarray and stored it, now i have to convert them back to images without saving it to disk. I tried with " toimage() " function, but it is displaying only 1 image.

toimage(resizedlist.values()[0]).show()

resizedlist.values contains the ndarray of 49 images. Is there any way to display images randomly??

Thanks in advance!

like image 506
varsha_holla Avatar asked Mar 24 '14 05:03

varsha_holla


People also ask

How do I turn a Ndarray into a data frame?

How do you convert an array to a DataFrame in Python? To convert an array to a dataframe with Python you need to 1) have your NumPy array (e.g., np_array), and 2) use the pd. DataFrame() constructor like this: df = pd. DataFrame(np_array, columns=['Column1', 'Column2']) .


1 Answers

To plot an ndarray as an image you can use matplotlib:

import numpy as np
import matplotlib.pyplot as plt

random = np.random.normal(0,1,size=[100,100])
plt.imshow(random,aspect="auto")
plt.show()

If your image data is stored RGBA, imshow will plot the image with the correct colours etc.

For reference, all this information can be found here:

http://matplotlib.org/1.3.1/users/image_tutorial.html

like image 130
ebarr Avatar answered Oct 15 '22 04:10

ebarr