This article was published as a part of the Data Science Blogathon
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.
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.
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.
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.
Most editing apps and social media apps provide filters these days.
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.
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.
( 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.
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.
( 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.
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.
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.
Let us get started with some basic Image related tasks in Python. We will make use of PIL.
Python Imaging Library is used for various image processing tasks.
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.
Python Code:
The image is read.
# modifying the shape of the image lum1 = img[:, :, 0] plt.imshow(lum1)
Now the image shape is 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:
Now we try a different colormap.
imgplot = plt.imshow(lum1) imgplot.set_cmap('nipy_spectral')
Image output:
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.
img2 = Image.open('people.jpg') plt.imshow(img2)
The image is read.
Now, we resize the image.
img2.thumbnail((50, 50), Image.ANTIALIAS) # resizes image in-place imgplot = plt.imshow(img2)
imgplot1 = plt.imshow(img2, interpolation="nearest")
imgplot2 = plt.imshow(img2, interpolation="bicubic")
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
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")
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")
This is the transposed image.
Final Words:
Image Processing has various important applications and with time the methods and processes will also improve.
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.
Thank you for sharing this valuable information with us. Really appreciate your work.