Images are JUST NumPy Arrays

Sivaram Rasathurai
3 min readApr 2, 2020
Photo by Aw Creative on Unsplash & This article is published here.

When I began learning computer vision, I had questions like: How do computers read images? How does Python handle images? I started my journey with Python, which offers numerous libraries for image processing, such as Matplotlib, OpenCV, SciPy, and scikit-image. When you read an image using any of these libraries, it is actually loaded as a NumPy ndarray. Consequently, whenever you perform operations on these images, you are essentially manipulating the numerical data that represents them.

When we read a colour image by OpenCV as follow

import opencv
img = cv2.imread("ImagePath")
print(img)

If we execute the above code, we will get a huge NumPy array. Colour image is a collection of three parallel planes, and every plane represent the colour intensity of a single channel. Most of the colour images are stored in RGB format and here R for red, G for green and B for blue. If you take one single element of an array that represents the intensity of red, green and blue of that pixel.

For a grayscale image, It is different from the colour images since it has only one channel rather than three channels. This single-channel represents the intensity of black or white from 0 to 255.

We can get the shape of the image using the shape method which gives the dimensions of the image

--

--

No responses yet