imglearn.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  : imglearn.c
  3.  Purpose    : to train shape matrix and deformation variance
  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 "gsnake.h"
  13. #include "xwindow.h"
  14. void help();
  15. main( int argc, char **argv )
  16. {
  17. MODEL model; /* to store results of learning */
  18. GSNAKE sample(_EDGE); /* sample will use _EDGE as external energy */
  19. char *outfile; /* output contour file */
  20. char **imgsamples; /* image samples */
  21. short level = 2;        /* pyramid level */
  22. register short i;
  23. if (argc < 3) {
  24.                 help();
  25.                 exit( -1 );
  26.         }
  27. imgsamples = &argv[2] ;
  28. outfile = argv[1] ;
  29. for(i=0; *imgsamples ; i++, imgsamples++) {
  30.     printf("Using Sample %s to Learn SHAPEnn", *imgsamples);
  31.     
  32.     sample.putRawImg(*imgsamples);
  33.     if( i==0 ) {
  34. /* use manually selected feature points to 
  35.        estimate the shape matrix */
  36.        
  37. sample.CONTOUR::init( sample.rawImg );
  38. model.LearnShape( &sample );
  39.     }
  40.   /* Using the initial shape matrix and minimiax regularization, 
  41.      the total energy of gsnake is minimize and then the shape 
  42.      matrix is updated */
  43.     model.duplicate(&sample);
  44.     sample.generate(level, 1);   /* generate pyramid */
  45.     sample.localize(5, 5, 1, 0.25, 3);  /* localize the contour */
  46.     sample.minimize(5, 5, 0); /* minimize energy */
  47.     sample.deform(); /* manually adjust */
  48.     
  49.     model.LearnShape( &sample );   /* average out the shape coef */
  50.     
  51.     if(i) model.regenerate() ; /* regenerate the shape based on mtx */
  52. }
  53. /* deformation and noise variance are done only after the 
  54.    shape matrix has been properly trained */
  55. for(imgsamples = &argv[2]; *imgsamples; imgsamples++) {
  56. printf("Using Sample %s to Learn DEFORMATIONnn", *imgsamples);
  57.      sample.putRawImg(*imgsamples);
  58.      model.duplicate(&sample);
  59.      sample.generate(level, 1);
  60.      sample.localize(5, 5, 1, 0.25, 3);
  61.      sample.putGLambda(_LOCAL_MINMAX);
  62.      sample.minimize(5, 5, 0);
  63.      sample.deform();
  64. model.LearnDeform( &sample ); /* average out the deform param */
  65. }
  66. model.computeZ() ;  /* compute normalizing constant using monte_carlo
  67.        estimation */
  68. model.CONTOUR::print() ;
  69. model.CONTOUR::write( outfile ); /* write it to file */
  70. }
  71. void help()
  72. {
  73.            printf("n Image learn Utility n");
  74.            printf(" Usage : imglearn <contour> <image samples>n");
  75.            printf(" Images can be of type bin or SUN raster. nn");
  76. }