-6- If you consider that in a small group of people,there will be variation in hair color,skin color,clothes color,etc.,then it is likely that each person's histogram will be quite different from the others.If we compare the histogram of an unknown image with each of the known images,then we can probably identify the unknown person. What we will compute is a difference score between the unknown histogram and each known histogram.This score is simply the sum of the absolute values of the differences of the elements.For example: known histogram 0 2 52 0 0 unknown histogram 0 abs (known [i]unknown [i]) 1020410210 difference score 11 If we compare the unknown histogram to each of the known ones,then we will identify it as the one with the lowest difference score.(Note:abs in the integer absolute value function from stdlib.h.) Now we can write some code. Part(a)Making a histogram In this part,your job is to write a function that computes the histogram for an image.The prototype is as follows: void MakeHistogram(int pict[SIZE][SIZE],int hist[N COLORS]); pict is the image being analyzed,and the function places the histogram in the uninitialized array passed to it as hist.(As you know,we aren't required in C to write in the size of the first dimension of pict or the size of hist,but we will do so in this problem to make it absolutely clear to you what the arguments are.) Write your code for this part at the top of the next page
– 6 – If you consider that in a small group of people, there will be variation in hair color, skin color, clothes color, etc., then it is likely that each person's histogram will be quite different from the others. If we compare the histogram of an unknown image with each of the known images, then we can probably identify the unknown person. What we will compute is a difference score between the unknown histogram and each known histogram. This score is simply the sum of the absolute values of the differences of the elements. For example: known histogram 0 3 1 2 5 2 1 2 0 0 unknown histogram 1 3 3 2 1 3 1 4 1 0 abs(known[i] – unknown[i]) 1 0 2 0 4 1 0 2 1 0 difference score 11 If we compare the unknown histogram to each of the known ones, then we will identify it as the one with the lowest difference score. (Note: abs in the integer absolute value function from stdlib.h.) Now we can write some code. Part (a) Making a histogram In this part, your job is to write a function that computes the histogram for an image. The prototype is as follows: void MakeHistogram(int pict[SIZE][SIZE], int hist[N_COLORS]); pict is the image being analyzed, and the function places the histogram in the uninitialized array passed to it as hist. (As you know, we aren’t required in C to write in the size of the first dimension of pict or the size of hist, but we will do so in this problem to make it absolutely clear to you what the arguments are.) Write your code for this part at the top of the next page
-7- void MakeHistogram(int pict[SIZE][SIZE],int hist[N_COLORS]) Part(b)Making histograms for the known data set Now you need to use your function to create histograms for the known data.Assume that main has the following declarations: main() int knownData[N PICTS][SIZE][SIZE]; int histograms [N PICTS][N COLORS]; int i; You can assume that the image data has already been stored in knownData.You will no doubt use a for loop,so we will write that for you.All you need to do for this part is show how to call the function you wrote in part (a)from inside the loop to create the histograms for the known data. for (i=0;i N PICTS;i++)
– 7 – void MakeHistogram(int pict[SIZE][SIZE], int hist[N_COLORS]) { Part (b) Making histograms for the known data set Now you need to use your function to create histograms for the known data. Assume that main has the following declarations: main() { int knownData[N_PICTS][SIZE][SIZE]; int histograms[N_PICTS][N_COLORS]; int i; You can assume that the image data has already been stored in knownData. You will no doubt use a for loop, so we will write that for you. All you need to do for this part is show how to call the function you wrote in part (a) from inside the loop to create the histograms for the known data. for (i = 0; i < N_PICTS; i++) {
-8-
– 8 – }
-9- Part(c)Identifying an unknown image Your final task is to write a function to identify an unknown image.The function has the following prototype: int BestMatch(int unknown[SIZE][SIZE],int histograms [N PICTS][N COLORS]); The arguments are the unknown image and the array of histograms of the known images.The function creates the histogram of the unknown,compares it to the known histograms using the difference score method discussed above,and returns the index of the known histogram that produces the lowest difference score.(If there is a tie,you may return the index of any of the tying histograms.) Write you answer here(additional space is available on the next page).Decomposition will simplify your code. int BestMatch(int unknown[SIZE][SIZE],int histograms [N PICTS][N COLORS])
– 9 – Part (c) Identifying an unknown image Your final task is to write a function to identify an unknown image. The function has the following prototype: int BestMatch(int unknown[SIZE][SIZE], int histograms[N_PICTS][N_COLORS]); The arguments are the unknown image and the array of histograms of the known images. The function creates the histogram of the unknown, compares it to the known histograms using the difference score method discussed above, and returns the index of the known histogram that produces the lowest difference score. (If there is a tie, you may return the index of any of the tying histograms.) Write you answer here (additional space is available on the next page). Decomposition will simplify your code. int BestMatch(int unknown[SIZE][SIZE], int histograms[N_PICTS][N_COLORS]) {