home *** CD-ROM | disk | FTP | other *** search
- /*
- * linexy.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /* LINEXY: program lists x,y coordinates for TLC level 1 lines
- * usage: linexy infile [-c] [-s] [-L]
- * Note -- this differs from the PCCFEAT (x,y) coordinate
- * output, because that program just dumps the coordinates
- * in PCC coding order, whereas LINEXY lists coordinates
- * in order along each connected line (breaks features are
- * connected).
- * KNOWN BUGS: If the image result of the (x,y) coordinates
- * from LINEXY are compared against the original
- * image before PCC coding using a difference program,
- * there is an x,y shift causing a small (pixel or so)
- * difference.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <images.h>
- #include "pcc2.h" /* for PCC programs */
- extern void print_sos_lic ();
-
- unsigned char *fcCode; /* code storage */
- long nByteCode; /* no. bytes in code storage */
-
- long xytoline (struct point *, long *, long *, long *);
- long usage (short);
- long
- input (int, char **, short *);
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- long width, height; /* image size */
- short sumFlag; /* flag=1 print coords; =2 summary; =0 all */
- struct point *data; /* data curve */
- long nData; /* no. coords in data curve */
- long nSegments; /* number of segments found */
- long nStructs; /* number of line structures found */
- long i;
-
- /* user input */
- if (input (argc, argv, &sumFlag) < 0)
- return (-1);
-
- /* open input PCC file */
- if (pccread (argv[1], &fcCode, &nByteCode, &width, &height) == -1)
- exit (1);
- if (sumFlag != 1)
- printf ("image size: %dx%d, PCC length = %d\n", width, height, nByteCode);
-
- /* allocate space for data coordinate array */
- if ((data = (struct point *)
- calloc (nByteCode * MAXPERCODE, sizeof (long))) == NULL) {
- printf ("LINEXY: not enough memory -- sorry");
- return (-1);
- }
-
- /* construct tables of feature chain decodes */
- pccdecodes ();
-
- /* perform feature chain decoding */
- pcc2xy (data, &nData);
-
- data[nData++].x = -STOPCODE;
- if ((data = (struct point *)
- realloc (data, nData * sizeof (struct point))) == NULL) {
- printf ("LINEXY: not enough memory -- sorry");
- return (-2);
- }
-
- /* find x,y coordinates for each line */
- xytoline (data, &nData, &nSegments, &nStructs);
-
- /* print information */
- if (sumFlag != 1)
- printf ("Summary: %d coordinates, %d segments, %d structures\n",
- nData, nSegments, nStructs);
-
- if (sumFlag != 2) {
- printf ("\n");
- for (i = 0; i < nData; i++) {
- if (data[i].x == -1)
- printf ("\n\n");
- else
- printf ("(%d,%d)", data[i].x, data[i].y);
- }
- printf ("\n");
- }
-
- return (0);
- }
-
-
-
- /* USAGE: function gives instructions on usage of program
- * usage: usage (flag)
- * When flag is 1, the long message is given, 0 gives short.
- */
-
- long
- usage (flag)
- short flag; /* flag =1 for long message; =0 for short message */
- {
-
- /* print short usage message or long */
- printf ("USAGE: linexy infile [-c] [-s] [-L]\n");
- if (flag == 0)
- return (-1);
-
- printf ("\nlinexy lists (x,y) coordinates for each line\n");
- printf ("segment in all image line structures; a line segment is\n");
- printf ("between PCC features, including endpoints and junctions.\n\n");
- printf ("ARGUMENTS:\n");
- printf (" infile: input filename (PCC) \n\n");
- printf ("OPTIONS:\n");
- printf (" -c: display (x,y) coordinates only\n");
- printf (" -s: display summary of features only;\n");
- printf (" default is to display both coordinates and summary.\n");
- printf (" -L: print Software License for this module\n");
-
- return (-1);
- }
-
-
- /* INPUT: function reads input parameters
- * usage: input (argc, argv, &sumFlag)
- */
-
- #define USAGE_EXIT(VALUE) {usage (VALUE); return (-1);}
-
- long
- input (argc, argv, sumFlag)
- int argc;
- char *argv[];
- short *sumFlag; /* flag=1 print coords; =2 print summary; =0 all */
- {
- long n;
-
- if (argc == 1)
- USAGE_EXIT (1);
-
-
- *sumFlag = 0;
-
- for (n = 2; n < argc; n++) {
- if (strcmp (argv[n], "-c") == 0)
- *sumFlag = 1;
- else if (strcmp (argv[n], "-s") == 0)
- *sumFlag = 2;
- else if (strcmp (argv[n], "-L") == 0) {
- print_sos_lic ();
- exit (0);
- }
- else
- USAGE_EXIT (0);
- }
-
- return (0);
- }
-