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

Windows Develop

Development Platform:

Unix_Linux

  1. /****************************************************************************
  2.  File Name  : gsinit
  3.  Purpose    : to create g-snake template
  4.  Release    : Version 1.0
  5.  Date     : Aug 31,1995
  6. GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
  7. University (NTU), Singapore. 
  8. 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.
  9. 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 :
  10. asschan@ntu.ac.sg
  11. kflai@iti.gov.sg
  12. ***************************************************************************/
  13. #include "xwindow.h"
  14. #include "gsnake.h"
  15. void getparam(int , char** ,int *, INITMODE *, SNAKEMODE *,int *,char **);
  16. void printHelp();
  17. main( int argc, char **argv )
  18. {
  19. IMAGE myimage; /* image object */
  20. GSNAKE mysnake; /* gsnake object */
  21. int Numpts = 16; /* number of snaxels */
  22. int level = 2; /* Gaussian pyramid level */
  23. int mag = 1; /* magnification factor */
  24. INITMODE Mode = _LOADTEMPLATE;/* contour initialization */
  25. SNAKEMODE SMode = _CLOSED; /* gsnake mode */
  26. char *filename = NULL; /* output filename */
  27. short row, col; /* image size */
  28. short register i, j;
  29. if (argc == 1)
  30.    printHelp();
  31. else {
  32.    getparam(argc, argv, &mag, &Mode, &SMode, &Numpts, &filename);
  33.    if  ( !(myimage.read(argv[1])) ) { 
  34. /* generate gsnake */
  35. row = myimage.getRow();
  36. col = myimage.getCol();
  37. printf("nCreate template ... waitnn");
  38. /* Generating line or circle based on image automatically */
  39. if (Mode == _LOADTEMPLATE) {
  40.    if ( SMode == _CLOSED )
  41.     mysnake.CONTOUR::init( row/2, col/2, 
  42. (double)MIN(row,col)/4.0,Numpts );
  43.    else
  44. mysnake.CONTOUR::init( 
  45. (short)(col/4), (short)(row/4),
  46. (short)(3*col/4), (short)(row/2),
  47.  Numpts );
  48. }
  49. /* Generating template using either click or drag */
  50. if (Mode != _LOADTEMPLATE) 
  51.     /* Initialising level 0 image */
  52.     mysnake.CONTOUR::init( &myimage, mag, Mode,SMode);
  53. if ( !filename ) 
  54.     filename = strdup("contour");
  55. if ( mysnake.write(filename) )
  56.     printf("nUnable to write to file %sn", filename);
  57.      }
  58. }
  59. xwin_close();
  60. }
  61. void getparam( int ac, char** av,
  62.        int *Mfactor, /* magnification factor */
  63.        INITMODE *mode, /* contour initialization mode */
  64.          SNAKEMODE *smode, /* gsnake mode */
  65.        int *Numpt, /* number of snaxels */
  66.        char **outfile ) /* output filename */
  67. {   
  68. register short i;
  69. char *inputstr;
  70. for (i=2; i<ac; i++) {
  71. if( *av[i] != '-' )
  72. continue; /* illegal input */
  73. inputstr = av[i]+2;
  74. switch( *(av[i]+1) ) {
  75.    case 'I' :
  76. switch (*(av[i]+2)) {
  77.    case 'c': *mode = _CLICKMOUSE; break;
  78.    case 'd': *mode = _DRAGMOUSE;break;
  79.    case 'a': *mode = _LOADTEMPLATE;break;
  80. }
  81. break;
  82.    case 'S' :
  83. switch (*(av[i]+2)) {
  84.    case 'c': *smode = _CLOSED; break;
  85.    case 'o': *smode = _OPENED;break;
  86. }
  87. break;
  88.    case 'M' :
  89. *Mfactor=atoi(inputstr);
  90. break;
  91.    case 'N' :
  92. *Numpt=atoi(inputstr);
  93. break;
  94.    case 'O' :
  95. *outfile = inputstr;
  96. break;
  97.  
  98.    default: break;
  99. }
  100. }
  101. }
  102. void printHelp()
  103. {
  104. printf("nnCreation of GSNAKE template");
  105. printf("nnUsage: gsinit <image> -[option]  ");
  106. printf("n [ option ]n ");
  107. printf("n    M     : Magnification factor, default 1");
  108. printf("n    N     : Number of points in SNAKE, default 16");
  109. printf("n    I d/c : Snake initialisation, default a");
  110. printf("n      : d - Drag  c - Click  a - Automatic ");
  111. printf("n    S o/c : Type of snake to be formed, default c");
  112. printf("n          : o - Open ended  c - Closed");
  113. printf("n    O     : Output contour filename,"); 
  114. printf("n          : default filename <contour>nn");
  115. }