0% found this document useful (0 votes)
24 views11 pages

Da Ip

The document provides instructions and examples for performing convolution operations. Convolution involves multiplying and adding elements of two matrices - an input matrix and a filter matrix. It discusses concepts like stride, padding and dilation which are parameters that can be adjusted in convolution. It also provides exercises for students to practice convolution with different inputs, filters, strides and padding methods.

Uploaded by

Pranav Saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views11 pages

Da Ip

The document provides instructions and examples for performing convolution operations. Convolution involves multiplying and adding elements of two matrices - an input matrix and a filter matrix. It discusses concepts like stride, padding and dilation which are parameters that can be adjusted in convolution. It also provides exercises for students to practice convolution with different inputs, filters, strides and padding methods.

Uploaded by

Pranav Saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

School of Computer Science and Engineering

Vellore Institute of Technology


ASSIGNMENT

Course Title: Image Processing


Programme: CSE
Course Credits: 3
Course Instructor: Dr. BIJICL
Release Date 10/03/2024
Due Date: 12/04/2024

Note1: Delayed submission without justification will result in zero.


Note 2: Grading will be as follows: A+: Evidence of exceptionally keen involvement and
successful completion of all tasks; A: Evidence of keen involvement and attempt to solve at least
some of the tasks; B+: Successful completion of all tasks; B: Satisfactory completion of all tasks;
C: Partial completion of all tasks; E: Unsatisfactory
[A+---10, A—8, B+--7, B—6, C—5, E—2]
Note 3: Plagiarism is defined as "the wrongful appropriation, close imitation, or purloining
and publication, of another author's language, thoughts, ideas, or expressions, and the
representation of them as one's own original work." Plagiarism is not only the mere copying of
text, but also the presentation of another's ideas as one's own, regardless of the specific words
or constructs used to express that idea. Please write the anti-plagiarism statement given in
footnote1 in your own handwriting, sign and submit.
Note 4: Grades will not be influenced by the format, handwriting or artwork ! However
you may present the work beautifully, for your own enjoyment.

1
I understand that Plagiarism is a moral offence. I state that all codes/ observations /output screenshots in this
assignment are my own, and there is no cut/copy and pasted material from undisclosed sources and manipulated
to hide the identity, and any codes/observations/output screenshots if taken from books/ websites/colleagues work
are explicitly indicated with reference.
Convolution: A local operation useful in ML
● It is the multiplication and addition of elements of 2 matrices, one of which is big and other
is small. The element by element multiplication is done each time after step-by-step sliding
(horizontally and vertically).*2
● 3 matrices in the operation – input, filter/kernel, output
● Output is normally smaller than input.
● The values of the filter matrix (filter coefficients) will produce unique effects.
● Filter size is typically 3,5,7 etc

Here is the simplest example

Exercise 1: Do convolution for each of the following input matrices and filter matrices. After all
exercises are done, try to make an observation about the effect of filter map.3

Input Filter Output

2
Note that matrix multiplication and convolution are different. To differentiate them the convolution
operation is indicated by the symbol (x).
3
Draw the 2x2 matrix on a transparent plastic sheet and place it on top of the input and do the process
for clear understanding.
(a)
1 1

1 1 1 1

1 1 1 1
1 1 1
1
1 1 1

1 1 1 1 1 1

(b)
1 1

1 1 1

1 1 1

1 1 1 1 1 1

1 1 1

1 1 1 1 1 1

(c)
1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1

1 1 1 1 1 1
(d)
1 1

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1

1 1 1 1 1 1

(e)
7 7

7 7 7 2

7 7 7 7

7 7 7 9

7 7 7

7 7 7 7 7 7

(f)
23 9 5 10 11 30

7 22 4 8 25 24 10

9 4 23 28 4 29 12

1 4 28 24 7 28 14

4 30 4 3 23 29

29 28 27 25 30 25

Questions on Convolution.
A. What is the relationship between pattern of input and pattern of filter
B. What filters can approximately represent:
Ground glass Plane glass Dark glass Glass with sun film

Parameters of Convolution: Stride, Padding and Dilation


Stride
Simple convolution is done by placing the filter matrix on the top of the input matrix and doing
element-by-element multiplication and addition. After each calculation the filter is moved
horizontally one step. When the filter reaches the rightmost portion, it reboots to the left and moves
to the next row. Thus the filter jumps in steps of 1 row/ column. This stepping value is called stride.
You could step by 2,3 …… Let us see examples of stride 2.

Input Output
Filter

1 1

1 1 1 1 0 1 3

1 1 1 1 0 1 3 2

1 1 1 1 1 3 1 1

1 1 1 1 3 2 1 3

1 1 1 1 1 1 stride-1

1 1
1
1 1 1 1 1
1
1 1 1 1 1
1 1 1 1

1 1 1
Stride-2
1 1 1 1 1 1

Exercise 2: Do the following convolutions with specified strides

Input Filter Output

1 1

1 1 1
1
1 1 1
1
1 1 1

1 1 1 1

1 1 1 1 1 1 Stride=1

1 1

1 1 1
1
1 1 1
1
1 1 1

1 1 1 1

1 1 1 1 1 1
Stride-2

Padding
You may have noticed that convolution operation mostly cannot be applied to pixels in the border
of the image. If the center of the filter is placed in a border pixel, a part of the filter will fall outside.
To address this situation there are 3 approaches:
1. Do not process the border pixels, leave them as such
2. Assume that the input image has one extra row/column which has zero value pixels.
3. Assume that the input image has one extra row/column which has the same pixels as in the
real borders.

Examples:

Input Filter Output

0 0 0 0 0 0 0 0

0 1 1 0 1 0 1 0 0 2

0 1 1 1 0 0 1 0 1 3 1
1
0 1 1 1 0 1 0 1 3 2 1

0 1 1 1 0 1 0 1 3 1 1 2

0 1 1 1 0 1 0 3 2 1 3 2

0 1 1 1 1 1 1 0 2 1 2 2 2 1

0 0 0 0 0 0 0 0

Zero padding

1 1 0 0 0 0 1 1

1 1 1 1 1 0 0 0 1 3
1
0 1 1 1 1 0 1 0 1 3 2

0 1 1 1 1 1 1 0 1 3 2 2

0 1 1 1 1 1 0 1 3 1 1 3

0 1 1 1 1 1 3 2 1 3 3

1 1 1 1 1 1 1 1 3 2 2 3 3 3
1 1 1 1 1 1 1 1

Same Padding

Exercise 3: Do the following convolution with specified padding method. (Input is 6x6 only but extra
column/row is provided to enable padding)

Input FIlter Output

1 1

1 1 1 1
1 1 1 1
1 1 1
1
1 1 1

1 1 1 1 1 1

1 1

1 1 1
1
1 1 1
1
1 1 1

1 1 1 1

1 1 1 1 1 1

Dilation
Normally the filter exactly overlaps the convolved region. This need not always be the case. If a 2x2
filter sits over a 3x3 region with one row and column of the input data skipped, it is called dilation.
Input FIlter Output

1 1 0 1 2 1

1 1 1 1 1 2

0 1 1

1 1 1 1 1 2 2

1 1 1 0 1

1 0 1 1 0 2

0 1 1 1

Exercise 4: Do the following convolution with dilation of 1.

Input FIlter Output

Downsampling an Image:
In machine learning applications, often the input image need not be considered as such, for reasons
of adequacy as well as reasons of size. We can downsample an image or a convolved output in 3
ways:
Replace adjacent pixels with one, based on:
1. Maximum of the n values
2. Sum of the n values
3. Average of the n values

Exercise 4: Given below the feature map which are results of convolving images with filters. Do
specified pooling of action (all 2x2):
A. Max Pooling
B. Sum Pooling
C. Average Pooling

Feature Map Pooling Output

1 2 3 4 5 1

6 1 8 7 1 1 1

3 4 1 1 2 1 1
7 5 1 1 6 1
1
8 1 2 3 1 1
Max Pooling
1 1 1 1 1 1

1 2 3 4 5 1

6 1 8 7 1 1 1

3 4 1 1 2 1 1
7 5 1 1 6 1
1
8 1 2 3 1 1
Same Pooling
1 1 1 1 1 1

1 2 3 4 5 1

6 1 8 7 1 1 1

3 4 1 1 2 1 1
7 5 1 1 6 1
1
8 1 2 3 1 1 Average Pooling
1 1 1 1 1 1

2. Pixel Manipulation [Python]

1 Write a function that takes a color image and


find the most frequently occurring
color from the image.

2 Write a function mergeImage which takes two


images fg and bg that extracts the
foreground object and places it in the
background and returns the resultant image.

3 Try out with different foreground and


background images of your choice and show
the results.

3. Contrast Stretching [Python]


1 Write a function linContrastStretching which takes
a grayscale image im, a and
b that enhances the contrast such that the resulting
intensity range is [a; b]

2 Display the input image and the resultant image


side-by-side along with their
colorbars (a strip containing k most frequently
occurring colors). Give suitable
explanation for the resulting colorbars.

3 Use your function on multiple images and argue


why the effect is more on some
images while it is not that apparent on the others.

You might also like