How to convert image into numpy.ndarray

Christian Meesters meesters at gmx.de
Wed Feb 25 11:17:28 EST 2009


On Wed, 25 Feb 2009 07:52:03 -0800, anti-suho wrote:

> In scipy module, there is a function named misc.lena which can return an
> array of numpy.ndarray type. If you use this array as parameter of
> matplotlib.pyplot.imshow and then call the matplotlib.pyplot.imshow
> function, an image will be shown. The shown image is generated by the
> numpy.ndarray array.
> 
> How to convert an arbitrary image into an array of numpy.ndarray type?
Well, arbitrary ...

But this may serve as a starting point:

from scipy.misc import fromimage
import Image #PIL
my_array = fromimage(Image.open(_file_name_))

Of course, you should perform the appropriate error checking, too. ;-)

HTH
Christian





More information about the Python-list mailing list