gsfit.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  : gsfit.c
  3.  Purpose    : extract arbitrary contour
  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. asschan@ntu.ac.sg
  10. kflai@iti.gov.sg
  11. ***************************************************************************/
  12. #include "xwindow.h"
  13. #include "gsnake.h"
  14. void getparam(int ac, char** av);
  15. void printHelp();
  16. int verbose = 0; /* verbose mode */
  17. int spacing = 5; /* snaxel spacing */
  18. int spac = 2; /* search segment spacing */
  19. int nhood = 2; /* number of search segment */
  20. double lambda = _LOCAL_MINMAX; /* regularization parameter */
  21. EEXTTYPE Etype = _EDGE; /* external energy type */
  22. int level = 2; /* Gaussian pyramid level */
  23. int mag = 1; /* image magnification factor */
  24. float low_p = 0.9; /* low percentage range */
  25. float high_p = 0.95; /* high percentage range */
  26. float low_v = 0.2; /* low intensity range */
  27. float high_v = 0.9; /* high intensity range */
  28. float e_pow = 1; /* exponential power */
  29. main( int argc, char **argv )
  30. {
  31. IMAGE myimage; /* image object */
  32. GSNAKE mysnake; /* gsnake object */
  33. short register i, j;
  34. if (argc==1) printHelp();
  35. else {
  36.    getparam(argc,argv);
  37.    /* perform gaussian pyramid */
  38.    if ( !(myimage.read(argv[1]))) { 
  39. printf("nHistogram Specification parameters :");
  40. printf("ntLow Percent:%f tHigh Percent:%f",low_p,high_p);
  41. printf("ntLow Value  :%f tHigh Value :%f",low_v,high_v);
  42. printf("ntExponent   :%f tMagnification:%d",e_pow,mag);
  43. mysnake.putRawImg( &myimage );
  44. printf("nnGenerating Gaussian pyramid images ... wait");
  45.                 mysnake.generate( level, verbose,
  46. low_p, high_p,low_v, high_v, e_pow);
  47.     }
  48.     else
  49. exit( -1 );
  50.     /* generate gsnake */
  51.     short row = myimage.getRow();
  52.     short col = myimage.getCol();
  53.     if ( !mysnake.read( argv[2] ) ) {
  54.         printf("nnGSNAKE performance parameters :");
  55.         printf("ntExternal Energyt: ");
  56.         switch  (Etype) {
  57.    case _EDGE : printf("Edge"); break;
  58.    case _EDGEMAG : printf("Edge magnitude"); break;
  59.      case _INTENSITY : printf("Intensity");break;
  60.    default : break;
  61.     } 
  62.      printf("ntSearch spacingt: %d",spac);
  63.      printf("ntInsertion spacingt: %d",spacing);
  64.      printf("ntSearch neighbourhoodt: %d",nhood);
  65.      printf("ntRegularization lambdat: %f", lambda );
  66.      printf("nnGeneralized Hough transform ... wait");
  67.      mysnake.localize();
  68.      printf("nEnergy minimization ... waitn");
  69.      mysnake.minimize( spac, nhood, spacing, mag, verbose, lambda );
  70.  
  71.      mysnake.show( (unsigned char)mag );
  72.      printf("nnEnter to continue ...");
  73.      getchar();
  74.   }
  75. }
  76. xwin_close();
  77. }
  78. void getparam( int ac, char** av )
  79. {   
  80. register int i;
  81. char *inputstr;
  82. for (i=2; i<ac; i++) {
  83. if (*av[i] == '/') verbose = 1;
  84. if( *av[i] != '-' )
  85. continue; /* illegal input */
  86. inputstr = av[i]+2;
  87. switch( *(av[i]+1) ) {
  88.    case 'L' :
  89. level = atoi(inputstr);
  90. break;
  91.    case 'M' :
  92. mag = atoi(inputstr);
  93. break;
  94.    case 'P' :
  95. inputstr=av[i]+3;
  96. switch (*(av[i]+2)) {
  97.    case 'l': low_p=atof(inputstr); break;
  98.    case 'h': high_p=atof(inputstr);break;
  99. }
  100. break;
  101.    case 'V' :
  102. inputstr = av[i]+3;
  103. switch( *(av[i]+2) ) {
  104.    
  105.    case 'l' :  low_v = atof(inputstr);break;
  106.    case 'h' :  high_v = atof(inputstr);break;
  107. }
  108. break;
  109.    case 'e' :
  110.  e_pow=atof(inputstr);
  111.  break;
  112.     case 'S' :
  113.      inputstr=av[i]+3;
  114. switch (*(av[i]+2)) {
  115.    case 's': spacing = atoi(inputstr); break;
  116.    case 'd': spac = atoi(inputstr);break;
  117.    case 'n': nhood = atoi(inputstr);break;
  118. }
  119. break;
  120.     case 'R' :
  121. lambda = atof(inputstr);
  122. break;
  123.     case 'E' :
  124.         
  125.         switch (*(av[i]+2)) {
  126.    case 'i': Etype = _INTENSITY; break;
  127.    case 'e': Etype = _EDGE; break;
  128.    case 'm': Etype = _EDGEMAG;break;
  129. }
  130. break;
  131.     default : break;
  132. }
  133. }
  134. }
  135. void printHelp()
  136. {
  137. printf("nn Match of a template on an imagen");
  138. printf("n Usage: gsfit <image> <contour> -[option]<value>");
  139. printf("n [ option ]:");
  140. printf("n -L     : Level of pyramid to build to, default 2");
  141. printf("n -M     : Magnification factor, default 1");
  142. printf("n -E     : External energy input type, default e");
  143. printf("n        : i - Intensity  e - Edge Data");
  144. printf("n        : m - Edge Magnitude only");
  145. printf("n -S     : Stratified Search spacing");              
  146. printf("n        : s - snaxel spacing, default 5");
  147. printf("n        : d - search segment spacing, default 2");
  148. printf("n        : n - number of search segment, default 2");
  149. printf("n -R     : Regularization parameter, default _LOCAL_MINMAX");
  150. printf("n -Pl,Ph : Percentage range for histogram specification, default 0.9-0.95");
  151. printf("n -Vl,Vh : Intensity range for histogram specification, default 0.2-0.9");
  152. printf("n -e     : Exponential Factor, default 1");
  153. printf("n  /     : Activate verbose, default 0nn");
  154. }