Understanding Images with skimage-Python | by Mathanraj Sharma | Towards Data Science

Computer Vision is a buzz word nowadays. Many useful applications and systems are emerging by incorporating Computer Vision techniques with AI and ML
Image Processing is an important tool that every professional in Computer Vision should have in their toolbox. Image Processing is the use of algorithms to perform various operations on digital images. Such as,
Enhancing an Image
Extract useful information
Analyzing Images
Image processing is used in various fields like Medical image analysis, AI, Image restoration, Geospatial computing, Surveillance, Robotic vision, Automative safety, and many more.
I am going to write a series of articles that will give you a practical understanding of some key Operations in Digital Image Processing using skimage in Python. In this first article let us understand how a digital image is captured and represented in a Digital Format.
It all begins with the light which passes through the lens of the camera. By the lens, it is focused on the Image plane of the camera. The image plane holds sensors(pixels) usually in a square or rectangle-shape. Sometimes they can be hexagonal or circular sensors based on the make of the camera. What is projected by the light on this plane is a two-dimensional, time-dependent, continuous distribution of light energy. A digital snapshot of this analog signal is captured in three steps,
Spatial Sampling-this is the step where the continuous analog signal is converted into its discrete representation.Temporal Sampling- this is the step that measures the amount of light incident on each sensor in a regular interval.Quantization of Pixel Values- The above two samplings is the data which will give our Digital Image. But to store and process it, we need to convert them into a range of integer values. (example 256 = 28)
Spatial Sampling-this is the step where the continuous analog signal is converted into its discrete representation.
Temporal Sampling- this is the step that measures the amount of light incident on each sensor in a regular interval.
Quantization of Pixel Values- The above two samplings is the data which will give our Digital Image. But to store and process it, we need to convert them into a range of integer values. (example 256 = 28)
The converted pixel values will later be stored in a format of a two-dimensional, ordered matrix of integers.
Let’s assume “I” is the matrix format of our image. The Size of the image is simply the width and height of the I.
from skimage import io#replace the path of imageimage = io.imread('~/Desktop/Lenna.png')print(image.shape)print(type(image))Output:(512, 512, 3)<class 'imageio.core.util.Array'>
In the above example output (512, 512,3) represents the width, height, and a number of channels in the image. And look that our image is represented in the format of Array.
On the other hand, Resolution is the spatial dimension of an image in the real world, and it is usually given as the number of image elements per measurements (example dpi, dots per inch).
In image processing, the coordinate system is flipped in the vertical direction. The origin of the axis will be at the left top corner.
Each square in the coordinate plane is known as a pixel. Each pixel will hold a quantized value acquired when capturing an image. Pixel values are normally given in binary words of k. (example 28)
from skimage import ioimage = io.imread('~/Desktop/Lenna.png')print(image[0][0])Output:[226 137 125]
The output has a list of three different integers because here I have loaded a color image. Usually, a color image is represented using three channels (RGB). Here 255, 137, 125 are the intensity values of red, green, blue color channels.
Channels are referred to as the number of colors in an image. Based on channels images are normally divided into two categories.
Grayscale Images
Grayscale images are represented using a Single color channel of black and its variations. Here each pixel will get a value between 0–255 if it is an 8-bit representation. But the range of pixel value may differ based on the k-bit representation.
from skimage import ioimage = io.imread('~/Desktop/Lenna_gray.png')print(image.shape)print(type(image))print(image[0][0])Output:(256, 256)<class 'imageio.core.util.Array'>161
As you can see in the above example the first location of our image array only holds a single value of 161.
Color Images
Usually, Color Images are represented using RGB three color channels. There will be three channels and pixels in each channel will have a value between 0–255 based on the intensity of each red, green, blue.
from skimage import ioimage = io.imread('~/Desktop/Lenna.png')print(image.shape)print(type(image))print(image[0][0])Output:(512, 512, 3)<class 'imageio.core.util.Array'>[226 137 125]
Note: You can pass any value between your 0 to width-1, 0 to height-1 in image[0][0].
Here it prints a list of three values, R = 256, G=137 and B=125 are the intensity values.
I hope you have gained some basic understanding of images and how to load and get properties of images. Let us meet again in the next topic in Image Processing.