Digital Image Processing Real-Life Applications and getting started in Python

prateekmaj21 Last Updated : 03 Aug, 2022
6 min read

This article was published as a part of the Data Science Blogathon

Introduction

Digital Image Processing consists of the various techniques and methods involving in the manipulation of images on a computer. Various types of operations are performed on images, which constitute Digital Image Processing.

Understanding what an Image actually is?

Image is basically a two-dimensional signal. The signal function is f(x,y), where the value of x and y at a point generates the pixel at the point. Image is basically a two-dimensional array consisting of numbers between 0 and 255.

Various factors are involved in Image Processing. Image processing has a few main motives.

Image Processing help in :

1. Improvement in digital information stored by us.

2. Making working with images automated.

3. Better image optimization leading to efficient storage and transmission.

Over the years, image processing has improved a lot, and there are a lot of modern commercial applications of image processing.

Image Processing Uses :

1. Image Correction, Sharpening, and Resolution Correction

Often, we wish we could make old images better. And that is possible nowadays. Zooming, sharpening, edge detection, high dynamic range edits all fall under this category. All these steps help in enhancing the image. Most editing software and Image correction code can do these things easily.

2. Filters on Editing Apps and Social Media

Most editing apps and social media apps provide filters these days.

Digital Image Processing filter

Above is an example of the original Image and filtered Image. Filters make the image look more visually appealing. Filters are usually a set of functions that change the colors and other aspects in an image that make the image look different. Filters are an interesting application of Image processing.

3. Medical Technology :

In the medical field, Image Processing is used for various tasks like PET scan, X-Ray Imaging, Medical CT, UV imaging, Cancer Cell Image processing, and much more. The introduction of Image Processing to the medical technology field has greatly improved the diagnostics process.

Digital Image Processing medical tech

( Image Source – https://axisimagingnews.com/radiology-products/imaging-equipment/x-ray/image-processing-software-mimics-grid-use-improve-image-quality )

The image on the left is the original image. The image on the right is the processed image. We can see that the processed image is far better and can be used for better diagnostics.

4. Computer / Machine Vision :

One of the most interesting and useful applications of Image Processing is in  Computer Vision. Computer Vision is used to make the computer see, identify things, and process the whole environment as a whole. An important use of Computer Vision is Self Driving cars, Drones etc. CV helps in obstacle detection, path recognition, and understanding the environment.

CV

( Source: Paris streets in the eyes of Tesla Autopilot  https://youtu.be/_1MHGUC_BzQ)

This is how typical Computer Vision works for Car Autopilots. The computer takes in live footage and analyses other cars, the road, and other obstacles.

5. Pattern recognition:

Pattern recognition is a part of Image Processing that involves AI and Machine Learning. Image processing is used to find out various patterns and aspects in images. Pattern Recognition is used for Handwriting analysis, Image recognition, Computer-aided medical diagnosis, and much more.

6. Video Processing:

Video is basically a fast movement of images. Various image processing techniques are used in Video Processing. Some methods of Video Processing are noise removal, image stabilization, frame rate conversion, detail enhancement, and much more.

Getting started with Image Processing in Python:

Let us get started with some basic Image related tasks in Python. We will make use of PIL.

PIL

Python Imaging Library is used for various image processing tasks.

Installation:

pip install pillow

With PIL installed, we can now move to the code.

First, we work with some matplotlib functions.

import matplotlib.image as img
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

The following image will be read. It is named image1.jpg.

Digital Image Processing 3

Python Code:

 Digital Image Processing show

The image is read.

# modifying the shape of the image
lum1 = img[:, :, 0] 
plt.imshow(lum1)

Now the image shape is modified.

Digital Image Processing image shape modified

Now we will change it into the “hot” colourmap. To read more about colourmap, visit this link.

plt.imshow(lum1, cmap ='hot') 
plt.colorbar()

Image output looks:

color

Now we try a different colormap.

imgplot = plt.imshow(lum1)
imgplot.set_cmap('nipy_spectral')

Image output:

imgplot = plt.imshow(lum1)

The reason for using colormaps is that, often in various applications and uses, having a uniform colormap helps. Read more about Colourmaps: Choosing Colormaps in Matplotlib.

Now let us have a look at why we called an image a 2D array.

#data type of lum1

print(type(lum1))

Output: <class ‘numpy.ndarray’>

print(lum1)
[[ 92 91 89 … 169 168 169] [110 110 110 … 168 166 167] [100 103 108 … 164 163 164]

[ 97 96 95 … 144 147 147] [ 99 99 98 … 145 139 138] [102 102 103 … 149 137 137]]

The dots are just there to show that there are many more data points in between. But one thing is sure, is that it is all numeric data.

Let us find the size of the array.

len(lum1)

Output: 320

len(lum1[300])

Output: 658

This gives us the number of pixels, and dimensions of the image: 320*658.

 We will also verify this later.

Now, we work with PIL.

from PIL import Image

We will use this image file, named as: people.jpg.

image
img2 = Image.open('people.jpg')
plt.imshow(img2)
digital image processing 4

The image is read.

Now, we resize the image.

img2.thumbnail((50, 50), Image.ANTIALIAS)  # resizes image in-place
imgplot = plt.imshow(img2)
blur 1
imgplot1 = plt.imshow(img2, interpolation="nearest")
imgplot2 = plt.imshow(img2, interpolation="bicubic")
blur 2

But, why do we purposefully blur images in Image Processing? Well, often for Pattern Recognition and Computer Vision algorithms, it becomes difficult to process the images if they are very sharp. Thus blurring is done to make the images smooth. Blurring also makes the colour transition in an image, from one side to the other, a lot more smooth.

Now, let us verify the dimensions of the car image, we worked on earlier.

#some more interesting stuff
file='image1.jpg'
with Image.open(file) as image: 
    width, height = image.size 
#Image width, height is be obtained
size

These are the dimensions we got earlier as well. So we can conclude that the image is 320*658.

Let us also try rotating and transposing the image.

#Relative Path 
img3 = Image.open("image1.jpg")  
#Angle given 
img_rot= img3.rotate(180)  
#Saved in the same relative location 
img_rot.save("rotated_picture.jpg")
inverse

This is the rotated image.

#transposing image  
transposed_img = img3.transpose(Image.FLIP_LEFT_RIGHT)
#Saved in the same relative location 
transposed_img.save("transposed_img.jpg")
transposed image

This is the transposed image.

Final Words:

Image Processing has various important applications and with time the methods and processes will also improve.

About me:

Prateek Majumder

Data Science and Analytics | Digital Marketing Specialist | SEO | Content Creation

Connect with me on Linkedin.

Thank You.

The media shown in this article on Digital Image Processing are not owned by Analytics Vidhya and is used at the Author’s discretion.

Prateek is a dynamic professional with a strong foundation in Artificial Intelligence and Data Science, currently pursuing his PGP at Jio Institute. He holds a Bachelor's degree in Electrical Engineering and has hands-on experience as a System Engineer at TCS Digital, where he excelled in API management and data integration. Prateek also has a background in product marketing and analytics from his time with start-ups like AppleX and Milkie Way, Inc., where he was involved in growth campaigns and technical blog management. Recognized for his structured thinking and problem-solving abilities, he has received accolades like the Dr. Sudarshan Chakraborty Award for Best Student Performance. Fluent in multiple languages and passionate about technology, Prateek continues to expand his expertise in the rapidly evolving AI and tech landscape.

Responses From Readers

Clear

Isabella Watson
Isabella Watson

Thank you for sharing this valuable information with us. Really appreciate your work.

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details