/*********************************************************/ /* program 11: perform arithmetic point operation */ /*********************************************************/ #define XSIZE 640 #define YSIZE 480 unsigned char *i1r,*i1g,*i1b; unsigned char *i2r,*i2g,*i2b; unsigned char *or,*og,*ob; main() { long int x,y,i; unsigned char lut[256]; /* allocate input and output memory buffers */ i1r = (unsigned char *)malloc(XSIZE*YSIZE); i1g = (unsigned char *)malloc(XSIZE*YSIZE); i1b = (unsigned char *)malloc(XSIZE*YSIZE); i2r = (unsigned char *)malloc(XSIZE*YSIZE); i2g = (unsigned char *)malloc(XSIZE*YSIZE); i2b = (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 input images. */ read_image("input1",i1r,i1g,i1b); read_image("input2",i2r,i2g,i2b); /* Perform the arithmetic operation note: this example adds to images together to reduce noise. */ for (y = 0; y < YSIZE; y++) { for (x = 0; x < XSIZE; x++) { or[(y*XSIZE)+x] = (i1r[(y*XSIZE)+x] + i2r[(y*XSIZE)+x]) / 2; og[(y*XSIZE)+x] = (i1g[(y*XSIZE)+x] + i2g[(y*XSIZE)+x]) / 2; ob[(y*XSIZE)+x] = (i1b[(y*XSIZE)+x] + i2b[(y*XSIZE)+x]) / 2; } } /* Write the output image. */ write_image("output",or,og,ob); /* Free memory buffers. */ free(i1r); free(i1g); free(i1b); free(i2r); free(i2g); free(i2b); free(or); free(og); free(ob); }