Numpy and Image Basics


In this tutorial, we shall look on to the concepts about the Numpy and image basics of storing the images in the Numpy as an N-dimensional array format. In the previous tutorial, we have learnt about the basics of the images and their properties. You can learn about the Numpy library from the previous tutorials. This tutorial covers the image processing Numpy basics for beginners

Now, let us know about the images and the basic concepts about the RGB and Grayscale images. 

You need to open your IDE, myself use Jupyter Notebook to perform the various operations and activities.

Initially, you need to import the Numpy Library and Matplotlib Library to store the image in the array and to get the plot of the image.


Then, you can import Image from the Python Image Library(PIL) to work on the images and perform various operations on the images.


You can store the image or open the image using the function by mentioning the location of the image accordingly.


You can get the image, which is stored in the pic. The type of image is of the format Jpeg.


Now, the format of the image stored can be changed to the numerical values stored in the array as NumPy N-dimensional array.

Now using the .shape function, one can get the shape of the image as (1300,1950,3) as in my case. Out of this, it shows that there are 3 arrays with 1300 rows and 1950 columns forming a 3-dimensional array that stores the values of the image pixels, of three primary colours R, G and B. 

Image Processing

Now, you can perform indexing and slicing on the Numpy arrays and can obtain the various images, with different layers. Actually, out of three colour layers:

0 denotes Red

1 denotes Blue 

2 denotes Green

Image Processing
Image Processing

One can map the colour images to the grayscale colour and then identify the images, which resembles 0 as no colour value and 255 as the full depth colour.

Image Processing

One can obtain a pure image with the red colour format by turning the array values of blue and green colour dimensions to zero. This results in the image with pixels only coloured in the band of red colour.

Image Processing

Later, you can check the shape of the image. It is still a 3-dimensional array with similar rows and columns, as observed below. We have performed the operation to turn the values to zero in another colour formats of blue and green but not deleted the blue and green dimensions.

This is all about the basic concepts to work on the images and the operations on the RGB images by varying the pixel values and several operations to understand deeply about the concept of image and the way it is stored in the array and image processing basics for beginners. For any sort of doubts or questions, you can reach through the comment box. If you like this tutorial, hit the like button located on the left top corner to show your support. 

Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *