How to load multiple images in a numpy array ?
<p>How to load pixels of multiple images in a directory in a numpy array . I have loaded a single image in a numpy array . But can not figure out how to load multiple images from a directory . Here what i have done so far </p>

<pre><code>image = Image.open('bn4.bmp')
nparray=np.array(image)
</code></pre>

<p>This loads a 32*32 matrices . I want to load 100 of the images in a numpy array . I want to make 100*32*32 size numpy array . How can i do that ? I know that the structure would look something like this </p>

<pre><code>for filename in listdir("BengaliBMPConvert"):
  if filename.endswith(".bmp"):
       -----------------
  else:
       continue
</code></pre>

<p>But can not find out how to load the images in numpy array </p>

<p>To get a list of BMP files from the directory <code>BengaliBMPConvert</code>, use:</p>

<pre><code>import glob
filelist = glob.glob('BengaliBMPConvert/*.bmp')
</code></pre>

<p>On the other hand, if you know the file names already, just put them in a sequence:</p>

<pre><code>filelist = 'file1.bmp', 'file2.bmp', 'file3.bmp'
</code></pre>

<p>To combine all the images into one array:</p>

<pre><code>x = np.array([np.array(Image.open(fname)) for fname in filelist])
</code></pre>

python image numpy image-processing