You are on page 1of 2

Lab # 4 2D Convolution

Objective:
The objective of this lab is to understand the concepts of 2D Convolution in images.

Theory:
This Lab provides insight into two-dimensional convolution and zero-padding with respect to
digital image processing. Here we get idea about the design of the 2D Convolution. This design
represents the concept of convolution by directly convolving input X to the Filter H. We will
discuss the process of performing convolution. In addition, we will also see at the methodology
of implementing convolution in Python.

In the digital domain, Convolution is performed by multiplying and accumulating the


instantaneous values of overlapping samples of Input Signal (X) and Impulse Response (H).

Mathematically, Convolution is defined as:

The way it works is that we flip the kernel along or you can say one of the signal. After flipping
the kernel, we slide the kernel over the Input signal. In this way, the overlapped section of both
signals gets accumulated.

signals.

In this design, the Numpy library in Python is used to achieve this milestone. First of all, we will
zero pad the input signal with respect to our filter. Without, zero padding, a lot of our pixels will
be lost when we slide the kernel over our image. So, we add 0s to each row and column to keep
all of our pixels. In implementation, we used the concept of element-wise multiplication to
multiply the filter with the image and then summed it up for each pixel.

Steps:
 First of all, read the input image. If the image is not in grayscale then read it in grayscale
or after reading the image convert it into grayscale.
 Then we will find rows and columns of the image.
 Next, the main issue arises when we simply convolve an image with a filter, some values
still get not convolved. To avoid this, we will perform zero-padding. This will add zeros
to rows and columns of an image so the data on the edges of the image could also get
convolved and the output will be of completely convolved image.
 After performing zero-padding we will slide the filter on the image.
 Then multiply the overlapping elements and sum all the elements.

Tasks:
Convert the images to grayscale if not already in it.

You might also like