gho2.c
Upload User: shhuayu888
Upload Date: 2013-03-28
Package Size: 1788k
Code Size: 6k
Category:

Windows Develop

Development Platform:

Unix_Linux

  1. /****************************************************************************
  2.  File Name  : gho2.c
  3.  Purpose    : find multiple g-snake by generalized Hough transform
  4.  Date     : Aug 31,1995
  5. GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
  6. University (NTU), Singapore. 
  7. These software programs are available to the user without any license or royalty fees. Permission is hereby granted to use, copy, modify, and distribute this software and its documentation for any purpose. ITI and NTU gives no warranty, express, implied, or statuary for the software and/or documentation provided, including, without limitation, waranty of merchantibility and warranty of fitness for a particular purpose. The software provided hereunder is on an "as is"  basis, and ITI and NTU has no obligation to provide maintenance, support, updates, enhancements, or modifications.
  8. GSNAKE API is available for any UNIX compatible system. User feedback, bugs, or software and manual suggestions should be sent via electronic mail to one of the following, who may or may not act on them as he/she desires :
  9. kflai@iti.gov.sg
  10. asschan@ntu.ac.sg
  11. ***************************************************************************/
  12. #include "gsnake.h"
  13. #include "xwindow.h"
  14. void testmain(char *, char *, short, int, short);
  15. void printhelp();
  16. void getparam(int ac, char** av, short *, int *, short *);
  17. main(int argc, char **argv)
  18. {
  19.         int Magnify = 1;
  20.         short Level = 2;
  21. short numgsnake = 1;
  22.         char *confile;
  23.         if (argc==1)
  24. printhelp();
  25.         else {
  26.                 getparam(argc,argv, &numgsnake, &Magnify, &Level );
  27.                 testmain(argv[1], argv[2], numgsnake, Magnify, Level);
  28.                 return(0);
  29.         }
  30. }
  31. void testmain( char *imgfile,  /* image file */
  32.        char *cfile,  /* contour file */
  33.        short numgsnake, /* number of desired snakes */
  34.        int mag, /* magnification factor */
  35.        short level ) /* pyramid level */
  36. {
  37.         PYRAMID mypyramid; /* PYRAMID object */
  38.         EDGE *edgemap; /* EDGE object */
  39.         CONTOUR mycontour; /* CONTOUR object */
  40. CONTOUR **localised; /* CONTOUR object */
  41.         SNAXEL *sptr; /* SNAXEL object */
  42.         GHOUGH GHT_OBJ; /* GHOUGH object */
  43.         int row, col; /* image of col x row */
  44.         int ratio;
  45.         if ( mypyramid.putRawImg(imgfile) ) 
  46. exit (-1);
  47.         if (cfile) {
  48.                 if (mycontour.read(cfile)) 
  49. exit(-1);
  50.         }
  51.         else {
  52.         /* Initialise a closed contour in the centre of the test image */
  53.         /* Radius of circle = smaller of row and col divide by 5 */
  54.         /* The values are arbitrary */
  55.                 row = mypyramid.rawImg->getRow();
  56.                 col = mypyramid.rawImg->getCol();
  57.                 mycontour.init(row/2,col/2,(double) MIN(row,col)/5,8);
  58.         }
  59.                  
  60.         /* Generate pyramid in verbose mode to level 3 */
  61.         mypyramid.generate(level, 1);
  62.         mypyramid.show(mag,level);
  63.         printf("nPress enter to continue.");
  64.         getchar();
  65.         printf("nCo-ordinates before transformn ");
  66.         mycontour.print();
  67.         mypyramid.rawImg->show(mag);
  68.         for (sptr=mycontour.getHead();sptr;sptr=sptr->getNext())
  69.                 sptr->show( mypyramid.rawImg,
  70.     ROUNDOFF(sptr->getRow())*mag,
  71.                             ROUNDOFF(sptr->getCol())*mag );
  72.         printf("nPress enter to continue.");
  73.         getchar();
  74.         /* Use external energy input Edge.The edge object used is the
  75.            highest level one because the search area  will be the
  76.            smallest */
  77.         ratio = mypyramid.getLevel()-1;
  78.         /* Reduce contour to size of highest edge */
  79.         mycontour.expand(LEVEL(-ratio));
  80.         /* Get highest level in pyramid */
  81.         edgemap = mypyramid.getEdge(ratio);
  82.         localised = GHT_OBJ.localize( &mycontour, edgemap, numgsnake );
  83. register short i;
  84. for ( i=0; i< numgsnake; i++ ) {
  85.             printf("nLocalised contour [%d] on image.n", i );
  86.             /* Get the localised gsnake. */
  87.     /* Contour will be in natural image size */
  88.             localised[i]->expand(LEVEL(ratio));
  89.             localised[i]->print();
  90.             mypyramid.rawImg->show(mag);
  91.             for ( sptr=localised[i]->getHead(); sptr; sptr=sptr->getNext() )
  92.                     sptr->show( mypyramid.rawImg, 
  93.     ROUNDOFF(sptr->getRow())*mag,
  94.                             ROUNDOFF(sptr->getCol())*mag);
  95.     printf("nnPress Enter to Continuen");
  96.             getchar();
  97. }
  98. }
  99.         
  100. void getparam( int ac, 
  101.        char** av,
  102.        short *numgsnake,
  103.        int *mag, 
  104.        short *level )
  105. {  
  106.         register int i;
  107.         char *inputstr;
  108.  
  109.         for (i=1; i<ac; i++) {
  110.  
  111.                 if( *av[i] != '-' )
  112.                         continue;       /* illegal input */
  113.  
  114.                 inputstr = av[i]+2;
  115.  
  116.                 switch( *(av[i]+1) ) {
  117.  
  118.                   case 'n' :
  119.                         *numgsnake = atoi(inputstr);   
  120.                         break;
  121.                   case 'M' :
  122.                         *mag=atoi(inputstr);   
  123.                         break;
  124.                 
  125.                    case 'L' :
  126.                         *level=atoi(inputstr);
  127.                         break;
  128.                 }
  129.         }       
  130. }
  131. void printhelp() 
  132. {
  133.         printf("nnLocalisation of contour on image");
  134.         printf("n Usage :OOgho2 <image> <contour> [ option ]");
  135. printf("n [ option ]");
  136. printf("n -n          : number of contours to be localized, default 1");
  137.         printf("n -M          : Magnification factor, default 1");
  138.         printf("n -L          : Level of pyramid, default 2nn");
  139. }