/*********************************************************/ /* program 15: laplacian edge enhancement */ /*********************************************************/ #define XSIZE 640 #define YSIZE 480 #define LSIGN 1 /* treat result as signed pixels */ #define LPOS 2 /* ignore negative values */ #define LGREY 3 /* offset negative values */ main() { unsigned char *in; unsigned char *out; unsigned char *i1,*i2,*i3; unsigned char *o; long int x,y; long int val,method; /* indicate how to interpret results */ method = LSIGN; /* allocate input and output memory buffers */ in = (unsigned char *) malloc (XSIZE*YSIZE); out = (unsigned char *) malloc (XSIZE*YSIZE); /* read the input image (one plane) */ read_image("input",in); /* process all lines in the image */ for (y = 1; y < (YSIZE-1); y++) { i1 = in + ((y-1)*XSIZE); i2 = i1 + XSIZE; i3 = i2 + XSIZE; o = out + (y*XSIZE) + 1; /* process all pixels in the line */ for (x = 1; x < (XSIZE-1); x++) { val = (((long int)*(i2+1) & 0xff)<< 3) - ((long int)*(i1+0) & 0xff) - ((long int)*(i1+1) & 0xff) - ((long int)*(i1+2) & 0xff) - ((long int)*(i2+0) & 0xff) - ((long int)*(i2+2) & 0xff) - ((long int)*(i3+0) & 0xff) - ((long int)*(i3+1) & 0xff) - ((long int)*(i3+2) & 0xff); /* interpret results of output pixel */ switch (method) { case LSIGN: val = val / 24; break; case LPOS: if (val > 255) val = 255; if (val < 0) val = 0; break; case LGREY: if (val > 127) val = 127; if (val < -128) val = -128; val = val + 128; break; default: break; } /* save processed output pixel */ *o++ = (unsigned int)val; i1++; i2++; i3++; } } /* write the output image (one plane) */ write_image("output",out); /* Free memory buffers. */ free(in); free(out); }