What the numpy array stores when i convert a grayscale image into a numpy array?
<p>I converted a 32 x 32 grayscale image into a numpy array using this procedure </p>

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

<p>when I print the numpy array, it prints 6 different matrix. When I printed the size of the numpy array, it showed me 3072. I suppose that the calculation is something like 3 x 32 x 32 . But I would like to know why, what is the numpy array storing? </p>

<p>Looking at the documentation on the page <a href="http://scikit-image.org/docs/dev/user_guide/numpy_images.html" rel="nofollow">A crash course on NumPy for images</a></p>

<p>If you use <code>shape</code>, </p>

<pre><code>nparray.shape
</code></pre>

<p>this will give the dimensions of the image as something like</p>

<pre><code>(32, 32, 3)
</code></pre>

<p>which gives the size you found (32 x 32 x 3 = 3072)</p>

<p>What this shows is that your image is a 32-by-32 pixel image with three channels (red, green, and blue). If it were grayscale, the size would be 32 x 32 = 1024, corresponding to a shape of:</p>

<p><code>(32, 32)</code></p>

<p>Incidentally, to convert your image to grayscale, you would need to use something like <a href="http://scikit-image.org/docs/dev/api/skimage.color.html#rgb2gray" rel="nofollow"><code>rgb2gray</code></a> (link to documentation).</p>

python numpy image-processing