LAB1
LAB1
1
Course Outlines
WEEK 1 Convolution
2
Week 1
Topic: Convolution
3
Image Processing
Image processing is converting an image to a digital format and applying various
functions to it to create a better image or extract additional information from it.
4
Digital Image
y
Grayscale Image Color image in RGB space
5
Digital Image
Figure(Left to
right): Blue,
Green, Red
Channel
6
Python as Task Language
• Ease of readability and ease of learning
• Extensive libraries present, the majority are open source and free.
• Generally slower than C++ in terms of raw performance but more
user-friendly.
Libraries:
• OpenCV (Open Source Computer Vision Library)
• Pillow (PIL Fork)
• NumPy
• Matplotlib
7
OpenCV
• OpenCV is faster than PIL
• OpenCV and PIL both can do general image manipulation and
processing tasks.
• It also can perform certain computer vision-specific operations, unlike
PIL, like object detection, feature extraction, image segmentation, etc.
• Integrates well with libraries like NumPy, scikit-learn, TensorFlow, and
other computer vision and machine learning libraries.
8
Convolution
• Convolution is an operation performed on two functions to produce a
third function.
• In image processing, convolution is the process of transforming an
image by applying a kernel over each pixel and its local neighbors
across the entire image.
• The convolution operation applied on Image I(x,y) using a kernel F is
given by
9
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 0 0 0 0
0 1 0 0 1 4 5 6 0 0 0 0 0
1 0 1 0 1 7 8 9 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
10
Convolution
1X 1X8 0X7 1 0 0 0 0 0 0
9
1 2 3
0X 0X 1X 0 0 0 23 0 0 0
6 5 4
4 5 6 0 0 0 0 0
0X 1X 0X 0 1
3 2 1
7 8 9 0 0 0 0 0
1 0 1 0 1
0 0 0 0 0
0 1 1 1 0
F I(X,Y) F * I(X,Y)
11
Convolution
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
12
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 0 0 0 0
1 0 1 0 1 7 8 9 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
13
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 16 0 0 0
1 0 1 0 1 7 8 9 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
14
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 16 16 0 0
1 0 1 0 1 7 8 9 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
15
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 16 16 17 0
1 0 1 0 1 7 8 9 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
16
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 16 16 17 0
1 0 1 0 1 7 8 9 0 21 0 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
17
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 16 16 17 0
1 0 1 0 1 7 8 9 0 21 20 0 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
18
Convolution
1 1 0 1 0 0 0 0 0 0
1 2 3
0 0 1 0 0 0 23 24 15 0
0 1 0 0 1 4 5 6 0 16 16 17 0
1 0 1 0 1 7 8 9 0 21 20 22 0
0 1 1 1 0 0 0 0 0 0
F I(X,Y) F * I(X,Y)
19
Installation
20
Classwork
Input
Output
21
Assignment
1. Apply Convolution using both smoothing and sharpening kernels on
a grayscale image and output the results.
2. Repeat the process for the Color image:
1. Take an RGB image and apply convolution with each kernel, applying
convolution separately on each channel.
2. Convert the RGB image to HSV mode and apply convolution with each
kernel, applying convolution separately on each channel of HSV space.
3. Subtract the resulting image obtained from the RGB and HSV modes
to distinguish their differences.
3. Repeat (2) for both smoothing and sharpening kernels.
22
Assignment
Instructions for Filters:
1. The center of each kernel should be user-defined. Don’t fix it in the
center.
2. Use smoothing filters like the Gaussian blur filter and Mean filter.
1. For the Gaussian filter, create a filter function with parameters σx, σy (which will
be user-input) such that it satisfies:
24
Assignment(Example)
i. Applying Gaussian filter
25
Convoluted in HSV space