/* move_av.c */ #include #include #include "mypgm.h" void move_av_filtering() /* Spatial filtering of image data */ /* Moving average filter */ /* input: image1[y][x] -------- output: image2[y][x] */ { int x, y, i, j; /* loop variable */ int mean; /* mean value in 3x3 mask */ int count; /* no. of pixels in 3x3 mask */ x_size2 = x_size1; y_size2 = y_size1; /* filtering operation */ 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++; } } } mean /= count; image2[y][x] = (unsigned char)mean; } } } main() { load_image_data(); /* Input of image1 */ move_av_filtering(); /* Moving average filtering is applied to image1 */ save_image_data(); /* Output of image2 */ return 0; }