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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!