In today’s blog, we will discover the beauty of image processing which will in the future lead us to understand the core of artificial intelligence.

Overview

• We will first look at the brief explanation of image processing and its focused areas
• Then, we will look at quick examples of image processing used in several programming languages

Digital Image Processing

From the scratch, digital image processing is the use of a digital computer to process digital images through an algorithm. It is a method to perform some operations on an image, in order to get an enhanced image or to extract some useful information from it. It is a type of signal processing in which input is an image and output may be image or characteristics/features associated with that image. Nowadays, image processing is among the rapidly growing technologies. It forms the core research areas within engineering and computer science disciplines too.

Image processing aims to,

There are two types of methods used for image processing namely, analogue and digital image processing. Analogue image processing can be used for hard copies like printouts and photographs. Image analysts use various fundamentals of interpretation while using these visual techniques. Digital image processing techniques help in the manipulation of the digital images by using computers. The three general phases that all types of data have to undergo while using digital techniques are a pre-processing, enhancement, and display, information extraction.

After the brief explanation, let’s move to some brief examples of image processing used in programming languages.

Examples of Image Processing

Image compression using Huffman Coding

In our first example, we will try to compress an image using Huffman coding.

Huffman coding is one of the basic compression methods, that have proven useful in image and video compression standards. When applying Huffman encoding technique on an Image, the source symbols can be either pixel intensities of the Image, or the output of an intensity mapping function.

If you’re not well understood what is Huffman coding, we have already introduced it to more advanced level. Check it out!

And then, we will build a Huffman Tree according to;

• Combine the two lowest probability leaf nodes into a new node.
• Replace the two leaf nodes by the new node and sort the nodes according to the new probability values.
• Continue the steps (a) and (b) until we get a single node with probability value 1.0. We will call this node as root
• Backtrack from the root, assigning ‘0’ or ‘1’ to each intermediate node, till we reach the leaf nodes

Say this is the data you want to compress:

`BANANA`

The ASCII codes for the alphabets in binary are:

```B : 01000010
A : 01000001
N : 01001110```

Thus the ASCII encoding of BANANA is:

`01000010 01000001 01001110 01000001 01001110 01000001`

Keep in mind that when the computer is reading ASCII text files, it always does so in chunks of 8 bits per character. That’s the standard. So the computer always knows that every 8 bits can be read from the file and matched against the ASCII table already in it’s memory to find which character was typed.

Let’s try to compress this with the aforementioned scheme of calling more frequent chunks of data with smaller nicknames. We will start with a naive interpretation.

```A : Occurs thrice. Let’s call it a 0
N : Occurs twice. Let’s call it a 1
B : Occurs once. Let’s call it a 10```

The compressed data thus turns out to be:

`1001010`

Lets see the uncompressed data again.

`01000010 01000001 01001110 01000001 01001110 01000001`

Face Detection in Python

Face detection is one of the most used image processing methods that basically detects faces from the given input image. In python, image processing can be done either using built-in function from the library called OpenCV or building your own algorithm.

Let you open your python and download OpenCV as cv2. After getting the library, you can then use your camera to detect your face running the code below.

```import cv2
import sys

cascPath = sys.argv[1]

video_capture = cv2.VideoCapture(0)

while True:
# Capture frame-by-frame

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# Display the resulting frame
cv2.imshow('Video', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
```

We will soon look forward to explaining all the codes and logic behind the codes and topics, however, I wanted to introduce what you can do with image processing basically.

Summary

Image processing is highly interested and intelligent knowledge that is used in many applications nowadays. I have tried to explain the basics of image processing and given some used examples. I will soon example each detail of image processing using Python language. Don’t worry if you don’t understand anything from the examples. Just know that you can do plenty of things with image processing and this blog is just the introduction to the wonderful world of digital image processing.