/* move_av_times.c */ #include #include #include "mypgm.h" void move_av_times() /* spatial filtering of image data */ /* multiple moving average filter */ /* input: image1[y][x] -------- output: image2[y][x] */ { /* definition of moving average filtering */ int x, y, i, j; /* loop variable */ int mean, count; int times; x_size2 = x_size1; y_size2 = y_size1; printf("Multiple moving average filtering is applied.\n"); do { printf("Enter no. of iterations (>0) = "); scanf("%d", ×); } while (times <= 0); /* multiple filtering operation */ while (times--) { for (y = 0; y < y_size1; y++) { for (x = 0; x < x_size1; x++) { mean = 0; count = 0; for (j = -1; j <= 1; j++) { for (i = -1; i <= 1; i++) { if (y+j >= 0 && y+j < y_size1 && x+i >= 0 && x+i < x_size1) { mean += image1[y+j][x+i]; count++; } } } image2[y][x] = (unsigned char)(mean/count); } } /* copy of image2 into image1 */ for (y = 0; y < y_size2; y++) { for (x = 0; x < x_size2; x++) { image1[y][x] = image2[y][x]; } } } } main( ) { load_image_data(); /* Input of image1 */ move_av_times(); /* Multiple moving average filtering */ save_image_data(); /* Output of image2 */ return 0; }