/*************************************************************************** * Func: color_median * * * * Desc: Median filters a color image by finding the median of RGB using * * absolute differences * * * * Params: source - pointer to color image in memory * * cols - number of columns in image * * rows - number of rows in image * * kwidth - width of window * * filename - name of output file * ***************************************************************************/ void color_median(pixel_ptr source, int cols, int rows, int kwidth, char *filename) { int x, y, i; /* image loop variables */ int kernx, kerny; /* kernel loop variables */ int index; /* image index */ int xextra, yextra; /* size of boundary */ int conv_line; /* size of output line */ unsigned long destadd; /* destination image address */ unsigned long sourceadd, sourcebase; /* source addressing */ pixel dest[1024]; /* destination image line */ FILE *fp; /* output file pointer */ unsigned char left[25];/* left buffer */ unsigned char right[25];/* right buffer */ int xpad, ypad; /* number of rows and columns that must be copied*/ int last_line; /* last line that can be processed, others copied*/ int color_line; /* size of color line */ pixel_ptr window; /* window of pixel group being processed */ int wsize; /* number of elements in the window */ xextra = (kwidth/2)*2; xpad = xextra/2; yextra = xextra; ypad = xpad; conv_line = cols - xextra; color_line = conv_line * 3; wsize = kwidth * kwidth; window = malloc(wsize * sizeof(pixel)); if((fp=fopen(filename, "wb")) == NULL) { printf("Unable to open %s for output\n",filename); exit(1); } fprintf(fp, "P6\n%d %d\n255\n", cols, rows); /* print out header */ last_line = rows - yextra; for(y=0; y