Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please at least write the serial portion of the code using C programming. Be as

ID: 3756444 • Letter: P

Question

Please at least write the serial portion of the code using C programming. Be as specific as possible and comment the code please.

2. For the second part of the homework, you are asked to apply a filter on an image using the window size of 3x3 for a matrix size of 256x256 (you will be using the same approach of Problem 1 to create the matrix and use it and put the output to result.txt file). Please note that your window will be sliding similar to mean filter. More information about the mean filter can be found here: https://www.markschulze.net/iava/meanmed.html The filter function you need to apply is shown in the example below for a 3x3 window 4 5 6 7 8 9 P(5) (truncate (1 +22 +3452+6+72 +8+9)/9 1+4+9+14+25+36+49+64 +81 truncate -truncate(5.6)-5

Explanation / Answer

Below is the C-code :

The different timings can be otained while running the code on diferent processors.

*********************************************************************************************************************

#include <time.h>

void main(void)

{

int ROW=256,COL=256,r,c;

unsigned int P0,P1,P2,P3,P4,P5,P6,P7,P8,FilteredImg[ROW][COL];

unsigned int Img[ROW][COL]; //Input Image

double cpu_time_used;

/*

P8 P1 P2

....

P7 :P0: P3

....

P6 P5 P4

*/

FilteredImg = Img;

clock_t start, end;

start = clock();

for(r=1;r<ROW-1;r++) // Boundary pixels left

{

for(c=1;c<COL-1;c++) // Boundary pixels left

{

P0 = power(Img(r,c),2);

P1 = power(Img(r-1,c),2);

P2 = power(Img(r-1,c+1),2);

P3 = power(Img(r,c+1),2);

P4 = power(Img(r+1,c+1),2);

P5 = power(Img(r+1,c),2);

P6 = power(Img(r+1,c-1),2);

P7 = power(Img(r,c-1),2);

P8 = power(Img(r-1,c-1),2);

FilteredImg(r,c) = floor(sqrt((P0+P1+P2+P3+P4+P5+P6+P7+P8)/9)); //The floor command will round off the value towards zero. e.g. floor(5.6) = 5

}

}

end = clock();

cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

printf("CPU Time = %.3f",cpu_time_used );

getch();

}