/**********************************************************************/ /* OUTLINE OF A PROGRAM FOR EDGE DETECTION ON GREY LEVEL IMAGES */ /* EXAMPLE FOR READING AND WRITING A PICTURE FILE */ /* */ /* compiling: cc edge2.c rasio.c -o edge2 -lm */ /* running: edge2 threshold inpic_file outpic_file */ /* Murali Subbarao, ESE 558 Digital Image Processing */ /**********************************************************************/ #include #include #include #include #include "rasio.h" float thresh; /* global variable used for parameter passing */ void main(int argc, char *argv[]) { Raster_file *raster_file_in; /* input file */ Raster_header *raster_header_in; /* header of input file */ unsigned char **inpic, **outpic; int width, height; int i=0, j=0; char infilename[100], outfilename[100]; void process_image(unsigned char ** , unsigned char ** , int , int ); if(argc != 4){ fprintf(stderr, "Usage : edge2 threshold infilename outfilename\n"); exit(1); } strcpy(infilename, argv[2]); strcpy(outfilename, argv[3]); thresh = (float)atof(argv[1]); /* read threshold */ if(thresh>255.0) { fprintf(stderr,"threshold should be <= 255\n"); exit(1); } if(thresh<0.0) { fprintf(stderr,"threshold should be >= 0.0\n"); exit(1); } /* read in input file */ raster_file_in = read_raster_file( infilename); raster_header_in = raster_file_in->header; height = raster_header_in->height; width = raster_header_in->width; /* allocate 2-d image array */ inpic = raster_file_in->image; outpic = pic_alloc(height, width); process_image(inpic, outpic, height, width); /* change the value of height and width here if needed */ /* write out image to a file */ write_raster_file( outfilename, outpic, height, width); free_pic(inpic,height); free_pic(outpic,height); } /* end main */ void process_image( unsigned char **inpic , unsigned char **outpic, int height, int width) { int i,j; float gradmag; extern float thresh; /* Manipulate the contents of inpic[i][j] and compute outpic[i][j] */ /* Print the top left corner of input picture for examination on the terminal. This assumes that the image is larger than 16x16. Comment out this part after initial testing. */ for(i=0; ((i< 16) && (ithresh) outpic[i][j]=200; else outpic[i][j]=5; } } for(i=0;i