0% found this document useful (0 votes)
17 views3 pages

THE3

This document provides instructions for a take-home exam assignment in the CENG 111 course. Students are tasked with writing a pattern_search function that searches a 2D pattern P in a 2D image I represented as lists of strings. The function returns False if P is not found in I, or a tuple (i, j, Theta) indicating the starting coordinate and orientation if P is found in I. Several sample patterns and images are provided, and restrictions on importing libraries and expected return types are outlined. The assignment will be automatically graded for compliance with specifications and multiple test cases. Programs scoring 30% or below will undergo further manual review by a TA.

Uploaded by

mcantimurcan
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)
17 views3 pages

THE3

This document provides instructions for a take-home exam assignment in the CENG 111 course. Students are tasked with writing a pattern_search function that searches a 2D pattern P in a 2D image I represented as lists of strings. The function returns False if P is not found in I, or a tuple (i, j, Theta) indicating the starting coordinate and orientation if P is found in I. Several sample patterns and images are provided, and restrictions on importing libraries and expected return types are outlined. The assignment will be automatically graded for compliance with specifications and multiple test cases. Programs scoring 30% or below will undergo further manual review by a TA.

Uploaded by

mcantimurcan
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/ 3

CENG 111

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.

Team: There is no teaming up. This is an EXAM.

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

where 1(·) is the indicator function defined as follows:



1, if x is True
1(x) = (2)
0, otherwise

PROBLEM & SPECIFICATIONS


• You should write a function called pattern_search(P, I) which computes the similarity
defined in Equation 1 and should return:

– The bool value False if the pattern P is not in the image I.


– The tuple value (i, j, Theta) if the pattern P is in the image I such that:
∗ i, j is the starting coordinate2 of the pattern in the image,
∗ Theta is the (clockwise) orientation (in degrees) of the pattern at coordinate
i, j. We will limit the task and consider Theta to be only 0, 90, 180 or 270
degrees. i, j, Theta are all integers.
1
As we will only consider 2D patterns and images, we will drop the explicit use of ‘2D’ in the rest of
the document.
2
Note that pattern/image coordinates start at 0 in Python.
Pattern Image
0 1 2 3 4 5 6 7
A X A
0 t u z < a b c d
X A Y
1 > # s A Y # a t

0o 90o 180o 270o 2 u z y X A A r .

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

Different rotations of the pattern 5 y a z y ? z y a

(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:

– Each string is a row of the pattern or the image.


– Each string has the same number of characters.
– The value at a pixel i,j can be accessed easily with P[i][j] or I[i][j].
– The strings will contain only ASCII characters.

• 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].

• A program based on randomness will be graded zero.

• The glass-box test grade is not open to discussion nor explanation.

You might also like