Question
I am having trouble writing this loop in C. My assignment involves 8 candidate pictures and one pattern picture. Each picture is 12 x 12
I am having trouble writing this loop in C. My assignment involves 8 candidate pictures and one pattern picture. Each picture is 12 x 12 (144 pixels). My goal is to find which of the candidate pictures match the one pattern picture and assign a variable "Match" to the ith candidate that matches the pattern. Here is my code so far:
for (int i = 0; i < 8; i++) { // i represents which candidate is being compared to pattern
for (int j = 0; j < 144; j++) { // j represents which pixel of i candidate is being compared to pattern
switch (i) {
case 0:
if (Candidates[j] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 1:
if (Candidates[j+144] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 2:
if (Candidates[j+288] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 3:
if (Candidates[j+432] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 4:
if (Candidates[j+576] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 5:
if (Candidates[j+720] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 6:
if (Candidates[j+864] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
case 7:
if (Candidates[j+1008] == Pattern[j]) {
Match = i;
continue;
}
else {
break;
}
}
}
}
Candidates[i] is of size 1152 and represents all the pixels of the 8 candidates and Pattern[i] is of size 144 and represents all the pixels of the one pattern. Can you please edit this segment of code to assign the variable "Match" to the right candidate? Also, when a Match is found, I want the loop to stop iterating to cut down on time complexity.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started