home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1988 by
- * Robotics Principles Research Department, ATT Bell Laboratories.
- * All rights reserved.
- * Last modified 2/8/88 Ingemar J. Cox
- * Revised 4/22/88 Ingemar J. Cox
- * Revised 11/11/88 Ingemar J. Cox
- */
- #include <stdio.h>
- #include "edge_finder.h"
-
- #define UBYTE_HD 0x4500
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- short header[5];
- int nx, ny;
- static unsigned char *pic;
- float sigma;
- int threshold;
- int hysteresis = 1;
- int thinning = 1;
- int cnt, i;
-
- unsigned char *edge_map;
- unsigned char *image_find_edges();
- unsigned char *image_hysteresis();
- unsigned char *image_thin();
- float atof();
-
- if(argc<2)
- {
- fprintf(stderr, "\n***error: wrong number of arguments***\n");
- fprintf(stderr,
- "\n%s -h -t sigma opt_thld < input > output\n", argv[0]);
- exit(1);
- }
- cnt = 1;
- while(argv[cnt][0]=='-')
- {
- switch(argv[cnt][1])
- {
- case 'h':
- hysteresis = 0;
- cnt++;
- break;
- case 't':
- thinning = 0;
- cnt++;
- break;
- default:
- fprintf(stderr, "%s: syntax error\n", argv[0]);
- fprintf(stderr,
- "%s -h -t sigma opt_thld < input > output\n", argv[0]);
- exit(1);
- }
- }
- sigma=atof(argv[cnt++]);
- if(argc>cnt)
- threshold=atoi(argv[cnt]);
- else
- threshold=0;
- /*
- * now read in image
- */
- read(0, (char*)header, 10);
- if(header[0] != UBYTE_HD)
- {
- fprintf(stderr, "%s: ERROR image not of unsigned char\n", argv[0]);
- exit(1);
- }
- nx = header[1];
- ny = header[2];
- fprintf(stderr, "\nimage size is %d x %d\n", nx, ny);
-
- if((pic = (unsigned char *)malloc(nx*ny*sizeof(unsigned char)))==0)
- {
- fprintf(stderr,
- "%s: ERROR cannot allocate image array\n", argv[0]);
- exit(1);
- }
-
- for(i=0; i<ny; i++)
- {
- read(0, (char*)pic+i*nx, nx);
- }
- image_init(pic, nx, ny);
-
- edge_map = image_find_edges(sigma, &threshold);
- if(hysteresis)
- {
- fprintf(stderr, "\napplying hysteresis\n");
- edge_map = image_hysteresis(threshold/3);
- }
- if(thinning)
- {
- fprintf(stderr, "\nthinning image\n");
- edge_map = image_thin();
- }
- write(1, (char*)header, 10);
- write(1, (char*)edge_map, nx*ny);
-
- image_cleanup();
- }
-
-