1: Digital Images as Numbers

To start off my blog posts, we will quickly look at digital images with a different perspective for image processing using Python. At the surface, images come in different filetypes such as png, jpeg, jpg, bitmap, etc. However, like all things digital or computer related, they need to have a numerical representation. The libraries used in this series of blog posts include skimage, opencv, pillow, numpy, etc.

Imported Libraries

Images need to be read by specific functions such as the imread and can be shown via the imshow function. Additional functions and libraries will be imported when needed.

A sample image and its numerical representation can be seen below.

Numerical representation of an image

Here, the image can be seen as an array. The numbers are the decimal values of the colors; 0 for black and 255 for white. The values in between our how dark or light the shade is. To represent colors however, additional layers are necessary, 3 to be specific. These are the Red, Green, and Blue (RGB) channels.

Colored Image

To show how the color channels work, I have created an array with 3 channels and an image shape of 3x3 or 9 pixels. In the array shape of (3, 3, 3), the 1st 3 stands for the number of rows (height/length), 2nd 3 stands for the number of columns (width), and the last 3 stands for the 3 color channels.

Red Channel

For example, looking at the red channel alone shows that the 1st pixel of each row is red while other pixels are lack of red and therefore white. Since the other columns in the original image are pure G and B, they have no influence on this channel.

Channel Interaction

However, when the channels interact, a variety of colors is created. The different channels now have overlapping values. The bottom right pixel as 150 R, 0 G, and 255 B, which creates the shade of purple.

Methods to show images

There are various methods to show these images but take note of how they are represented along the axes.

Image Processing Operations, henceforth, involves calculations and manipulations/functions to those numerical values.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nisarg Nigam

Nisarg Nigam

MS Data Science student at Asian Institute of Management