/*********************************************************/ /* program 7: apply flat field correction */ /*********************************************************/ #define XSIZE 1280 #define YSIZE 960 short int *ff; long int scale,val; unsigned char *ir,*ig,*ib; unsigned char *or,*og,*ob; main() { long int x,y; /* allocate input and output memory buffers */ ff = (short int *) malloc (2*XSIZE*YSIZE); ir = (unsigned char *) malloc (XSIZE*YSIZE); ig = (unsigned char *) malloc (XSIZE*YSIZE); ib = (unsigned char *) malloc (XSIZE*YSIZE); or = (unsigned char *) malloc (XSIZE*YSIZE); og = (unsigned char *) malloc (XSIZE*YSIZE); ob = (unsigned char *) malloc (XSIZE*YSIZE); /* read the 16-bit flat field correction image */ read_image16("ffcorrect",ff); /* read the uncorrected field rgb input image */ read_image("input",ir,ig,ib); /* correct the rgb image */ for (y = 0; y < YSIZE; y++) { for (x = 0; x < XSIZE; x++) { /* correct red plane */ scale = ((long)ir[(y*XSIZE)+x] * (long)ff[(y*XSIZE)+x]) >> 12; val = (long)ir[(y*XSIZE)+x] - scale; or[(y*XSIZE)+x] = (unsigned int)val; if (val < 0) or[(y*XSIZE)+x] = 0; if (val > 255) or[(y*XSIZE)+x] = 255; /* correct green plane */ scale = ((long)ig[(y*XSIZE)+x] * (long)ff[(y*XSIZE)+x]) >> 12; val = (long)ig[(y*XSIZE)+x] - scale; og[(y*XSIZE)+x] = (unsigned int)val; if (val < 0) og[(y*XSIZE)+x] = 0; if (val > 255) og[(y*XSIZE)+x] = 255; /* correct blue plane */ scale = ((long)ib[(y*XSIZE)+x] * (long)ff[(y*XSIZE)+x]) >> 12; val = (long)ib[(y*XSIZE)+x] - scale; ob[(y*XSIZE)+x] = (unsigned int)val; if (val < 0) ob[(y*XSIZE)+x] = 0; if (val > 255) ob[(y*XSIZE)+x] = 255; } } /* write the corrected field rgb output image */ write_image("output",or,or,or); /* free memory buffers */ free (ff); free (ir); free (ig); free (ib); free (or); free (og); free (ob); }