You are currently viewing A Small Introduction to Digital Image Processing in Computer Vision
A Small Introduction to Digital Image Processing in Computer Vision

A Small Introduction to Digital Image Processing in Computer Vision

INTRODUCTION

This blog aims at knowing about digital images, types of images and throwing some light on computer vision and digital image processing. This blog is very useful for those who are pursuing their research in computer vision especially in image processing. In this blog, various terms related to images will be covered and things will be explained with live codes and screenshots. So author hopes that reader will gain a lot after reading this blog. Following topics will be covered in this tutorial.

  1. What is a Digital Image?
  2. Types of Images
  3. Throwing some Light on Computer Vision and Image Processing
  4. Bottom-line

What is a Digital Image?

An image is 2-D (dimensional) binary representation of any object or thing in electronic form. It can be represented as two dimensional function F(x, y) where x and y are spatial coordinates. The amplitude of F at any pair of coordinates (x, y) is the intensity of image at that point. When x, y and amplitude values of F are finite, it is called a digital image.

An image can be in raster or vector format. In raster form which is also called bitmap, each individual element of the image is in square format whereas in vector form, image is made up of individual shapes like circle, square, or triangle etc. Vector image does not depends on pixels while raster depends on pixels. This is the reason when one zooms the vector image, it remains same.

Some of the common vector extensions are Adobe Illustrator Artwork (Ai), Scalable Vector Graphics (SVG), Encapsulated PostScript (EPS), Windows Metafile (WMF), CorelDraw Image File (CDR) while some of the raster extensions are Joint Photographic Experts Group (JPEG), Portable Network Graphics (PNG), Tagged Image File Format (TIFF), Bitmap File (BMP), Graphics Interchange Format (GIF).

For a digital image there are finite number of pixels. These pixels are arranged in a column and row and each holding the information of the image. Color information contained in each pixel in an image is called bit depth.

For example bit depth 1 represents each pixel either black or white. As depth increases, color of each pixel also increases using the formula 2n where n is the bit depth. If one is considering true image or RGB image having the bit depth of 24, possible color available per pixels are 16 million.

Let us discuss some of the terms which are related with image so that readers can understand the basics in more clear form.

  1. Pixel: Pixel is the smallest unit of any image arranged in a 2-D format. It can be a square or round in shape which in collaborate forms an image. Each pixel has its own value containing the information of the image. This value is proportional to the light intensity at that specific point. Value of a pixel is also called intensity value.
  2. Image Resolution: It is a measure if pixel density which is measured in depth per inch (dpi). If dpi is 72, it means in a space of one inch square, there is a grid of 72 pixels (wide) * 72 pixels (height) i.e 5184 pixels per square inch. Higher the resolution of an image, the more detail it holds. There is relationship between width and height of an image and dpi. For example a document of 8 inch * 10 inch which is scanned at 300 dpi has pixel dimension of 2400 pixels (8 inch * 300) by 3000 pixels (10 inch * 300).
  3. Intensity: Intensity of an image is the value of the pixel. It can be in between 0-255 value which is called the intensity of that pixel. Value depends on the bit depth.
  4. Concept of Brightness: In an image each pixel has its own different value lying in between 0 to 255. More the value, brighter will be the pixel. Variation of the values of the pixels is responsible for the color of the image.

Types of Images

  • Binary Image: The pixels of a binary image have only two values or states; that can be either 0 or 1. 0 represents the black color while 1 represents the white color. Black color usually referred as background and white shows the object in the image. This type of image is used to differentiate object from the background.
  • Grayscale Image: Gray scale is also known as gray level image. It is named so because it has all the shades of gray color in the whole image. So, it is monochromic gray image. Such images have the information of the brightness and not about the color. These images are formed when the colors from the image is removed and leaving the brightness or luminance value as it is.
    It has 8-bit color format with 256 different shades of color where 0 means black and 256 represents white and there are 127 stands for gray. In other words there are 256 (2^8) different combinations of colors that each pixel can have between black and white.
    Let us see how to read the grayscale image in python:
    For this, we have to use OpenCV library. This can be used to open all types of images whether binary, grayscale and RGB.
    Please see the below the code which will read the image. If it is grayscale then it will tell it is grayscale, if it is RGB then it will convert it into grayscale. Have a look at the code with proper comments.

Let us see the code snippet as below

# importing OpenCV(cv2) module
# This is imported using pip install opencv-python
import cv2

image = 'rgb_image.jpg'
# Read RGB image
img = cv2.imread(image)

# If image is Grayscale try is implemented
try:
   if img.ndim == 2:
      print("Image is grayscale:")
      print("It has single channel")
   else:
       raise Exception
# else if image is RGB except is implemented
except:
   print("Channels are {}".format(img.ndim))
   print("It is RGB")
   print("Conversion is done")
   gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# image is converted to grayscale  
   print("Channels are reduced to {}".format(gray.ndim))

Also please have a look at the screenshot while I ran it in the virtual environment

Running the code for reading grayscale image using OpenCV
Running the code for reading grayscale image using OpenCV
  • RGB Image: RGB or true color images are those in which each individual pixel shows color value of each channel. These type of images are made of three layers i.e Red, Green, and Blue stacked on top of each other.If each channel has the bit depth of 8; overall color depth/bit depth is 24. If you print dimensions of this image, it comes out to be 3. In technical language, it has three values. Value 1 represents width of an image, Value 2 represents height of an image and Value 3 represents the depth of an image or number of channels. Let us understand the above point with the help of code.
# importing OpenCV(cv2) module
# This is imported using pip install opencv-python
import cv2

image = 'rgb_image.jpg'
# Read RGB image
img = cv2.imread(image)

print("Shape of image:")
print()
print(img.shape)

Let us see the screenshot while running the code as below:

Shape of RGB image
Shape of RGB image
  • Indexed Image: An indexed image consists of an array (x) and a colormap (map) matrix. The colormap matrix is m by 3 matrix with floating value in between 0 to 1 and is an array of class double. The row of the matrix define the RGB components of a single color. To determine the color of the pixel, the corresponding value of X is used as an index into map.

Throwing some Light on Computer Vision and Image Processing:

Digital Image Processing: In order to enhance the quality of an image, some operations are performed on it by means of a digital computer is called digital image. This is done to extract the information stored in the image.

Operations performed under digital image processing:

  1. Image Scaling: In this process, an image is resized to make specific operations on it.It is reduced or enlarged by changing the pixels of an image.
  2. Color conversion: An image has different colors made with the combination of red, green and blue. In image processing technique the color of an image is changed i.e Grayscale to RGB and vice versa with image processing tools and techniques.
  3. Image Enhancement: To extract the useful information from an image the image is so adjusted to make the display better. It include various process such as noise removal, histogram equalisation, and image sharpening etc.

Computer Vision: Computer Vision is the field which deals with the techniques to extract high level information from digital images. After acquiring, enhancing and analyzing the digital image information is extracted from it. After gaining the information from the digital images in which computer vision deals with helps in making artificial intelligent systems.

Bottom-line

In the nutshell, it can be said that this topic starts with the images which is the key topic of this blog. Then we move to types of images so that readers can be familiar with different types of images. I have made the flow in such a way, as computer vision and digital image processing deals with images, so it is important to understand images in deeper sense. Also, different terminologies associated with them. We have discussed about different types of images with some code lines and screenshot to make you understand the things in more visualized and better way. In the end, we proceeded with some conclusion on digital image processing and end the article with the definition of computer vision. AI Sangam hopes that readers gain some good and effective knowledge about images. This will be very beneficial for them while performing research in computer vision domain. If you would like to write your feedback at us please do email us at aisangamofficial@gmail.com. You can also join us at skype as aisangamofficial. You can also watch our demos and videos at AI Sangam you tube channel.

You can see next tutorial on image processing by clicking below

Image Processing in Computer vision: How to Read and Write Images in Python

Leave a Reply