THE3
THE3
Fall 2022
Take-Home Exam 3
REGULATIONS
Due date: 23:59, 26 December 2022, Monday (Not subject to postpone)
Submission: Electronically. You should save your program source code as a text file named
the3.py, and submit this file via the ODTUCLASS page of the course.
Cheating: Source(s) and Receiver(s) will receive zero and be subject to disciplinary action.
INTRODUCTION
Your task in this assignment is to search for a 2-dimensional (2D) pattern P in a 2D image I.
A 2D pattern1 P with size N × M is a matrix with N rows and M columns such that P[i, j]
denotes the pixel value at ith row and j th column. Similarly, an image I is a matrix with H rows
and W columns such that I[i, j] denotes the pixel value at ith row and j th column. It is assumed
that patterns are always smaller than images; i.e., N < H and M < W .
In this task, we will consider a simplified notion of the presence of a pattern in an image. To
be specific, we will say that an image I with size (H, W ) contains a pattern P with size (N, M ) if
the following summation is equal to N ×M for some pixel coordinate i, j such that 1 ≤ i ≤ H −N
and 1 ≤ j ≤ W − M :
N XM
1 P[k, l] =? I[i + k, j + l] ,
X
(1)
k=1 l=1
A X A X A Y A X A Y 3 r , l A X x i o
X A Y A X A X A X A
4 z # a ! y a b c
Y A A X
(a) (b)
Figure 1: (a) A sample pattern and its clockwise rotations that you should consider. (b)
A sample image which contains the sample pattern in (a) at coordinate (1,3) with a
270-degree orientation (Theta).
• To simplify the task, we will provide you a pattern P and an image I as “ASCII images”,
as illustrated in Figure 1. In other words, P and I are lists of strings as follows:
[
".............." # <-- This is the first row
".............." # <-- This is the second row
...
".............." # <-- This is the last row
]
such that:
• The given pattern can be present in the given image at most once.
SAMPLE RUN
>>> P1 = ["AXA", "XAY"]
>>> P2 = ["AXA", "XAZ"]
>>> I = ["tuz<abcd", ">#sAY#at", "uzyXAAr.", "r,lAXxio", "z#a!yabc", "yazy?zya"]
>>> pattern_search(P1, I)
(1, 3, 270)
>>> pattern_search(P2, I)
False
RESTRICTIONS and GRADING
• You are not allowed to import any libraries.
• The similarity definition in Equation 1 is case sensitive; i.e., ‘A’ and ‘a’ are two different
characters.
• Comply with the specifications outlined. Do not expect any input from the user or print
anything on screen. Conform to the specifications and the expected return type. Your
program will be graded through an automated process and any violation of the specifications
will lead to errors (and reduction of points) in automated evaluation.
• Your program will be tested with multiple data (a distinct run for each data). Any program
that performs only 30% and below will enter a glass-box test (eye inspection by the grader
TA). The TA will judge an overall THE2 grade in the range of [0,30].