model.tex
Upload User: shhuayu888
Upload Date: 2013-03-28
Package Size: 1788k
Code Size: 5k
Category:

Windows Develop

Development Platform:

Unix_Linux

  1. rhead{class MODEL}
  2. section{MODEL : Shape Learning Class}
  3. {tt MODEL} provides shape matrix and local regularization parameters learning routines. It has the following structure:
  4. begin{verbatim}
  5. class MODEL : public GSNAKE {
  6.     protected :
  7.         short deformSample;      /* number of deformed samples */
  8.         short shapeSample;       /* number of learned samples */
  9. };
  10. end{verbatim}
  11. {tt MODEL} inherits extra functions from {tt GSNAKE}. With sufficient training samples, we can generate a robust contour model with specific prior knowledge.
  12. %
  13. subsection{MODEL constructor}
  14. subsubsection*{Synopsis}
  15. begin{verbatim}
  16. MODEL(void)
  17. end{verbatim}
  18. subsubsection*{Description}
  19. The constructor sets {tt deformSample} and {tt shapeSample} to 0.
  20. %
  21. subsection{Learning shape matrix}
  22. subsubsection*{Synopsis}
  23. begin{verbatim}
  24. int LearnShape(GSNAKE *sample)
  25. end{verbatim}
  26. subsubsection*{Arguments}
  27. tb
  28. {tt sample} & Gsnake sample.
  29. te
  30. subsubsection*{Returns}
  31. tb
  32. {tt NOERROR} & Successfully operation. \
  33. {tt MEMORYERROR} & Memory allocation error.
  34. te 
  35. subsubsection*{Description}
  36. {tt LearnShape} performs learning of shape matrix from different samples. This is done by taking an initial estimate of shape matrix from the first sample. Using this shape matrix and {em minmax} regularization, we minimize the second samples and average the shape matrix. By repeating this for the rest samples, we can derive a learned {em model} to regenerate a new contour shape.
  37. %
  38. subsection{Learning local deformation variances}
  39. subsubsection*{Synopsis}
  40. begin{verbatim}
  41. int LearnDeform(GSNAKE *sample)
  42. end{verbatim}
  43. subsubsection*{Arguments}
  44. tb
  45. {tt *sample} & GSNAKE sample.
  46. te
  47.  
  48. subsubsection*{Returns}
  49. tb
  50. {tt NOERROR} & Successful operation. \
  51. {tt MEMORYERROR} & Memory allocation error. 
  52. te 
  53. subsubsection*{Description}
  54. {tt LearnDeform} learns the local regularization parameters $lambda_{i}$ which control the {tt GSNAKE} deformation. By computing deformation variance ($sigma_{i}^{2}$) and noise varaince ($sigma_{eta}^{2}$), we have $lambda_{i}$ as following,
  55. eq
  56.  lambda_{i}=frac{sigma_{eta}^{2}}{sigma_{eta}^{2}+sigma_{i}^{2}}
  57. en
  58. %
  59. subsection{Accessing the trained model}
  60. subsubsection*{Synopsis}
  61. begin{verbatim}
  62. GSNAKE *getModel(void) 
  63. end{verbatim}
  64. subsubsection*{Returns}
  65. Learned contour model.
  66. subsubsection*{Description}
  67. {tt getModel} facilitates the retrieval of a learned contour model.
  68. %
  69. subsection{Example : Learning of shape matrix from different samples}
  70. begin{verbatim}
  71. void testmain( char **argv,
  72.                unsigned char mag,
  73.                short level,
  74.                int magPos,
  75.                int levelPos )
  76. {
  77.         MODEL model;            /* to store results of learning */
  78.         GSNAKE sample(_EDGE);   /* sample will use _EDGE as external energy */
  79.         char **imgsamples;      /* image samples */
  80.         register short i;
  81.         imgsamples = &argv[1] ;
  82.         for( i=1; *imgsamples ; i++, imgsamples++) {
  83.             if ( ( i == magPos ) || ( i == levelPos) )
  84.                 break;
  85.             printf("Using Sample %s to Learn SHAPEnn", *imgsamples);
  86.             sample.putRawImg(*imgsamples);
  87.             if( i==1 ) {
  88.                 /* use manually selected feature points to
  89.                    estimate the shape matrix */
  90.                 sample.CONTOUR::init( sample.rawImg, mag );
  91.                 model.LearnShape( &sample );
  92.             }
  93.             /* Using the initial shape matrix and minimiax regularization,
  94.                the total energy of gsnake is minimize and then the shape
  95.                matrix is updated */
  96.             model.duplicate(&sample);
  97.             sample.generate(level, 1);          /* generate pyramid */
  98.             sample.localize(5, 5, 1, 0.25, 3);  /* localize the contour */
  99.             sample.minimize(5, 5, 0, mag);      /* minimize energy */
  100.             sample.deform( mag );               /* manually adjust */
  101.             model.LearnShape( &sample );        /* average out the shape coef*/
  102.             /* Using the shape matrix and the last two snaxels,
  103.                a contour is regenerated to show invariance of shape matrix */
  104.             if( i != 1 ) {
  105.                 printf("Regenerate the shape...n");
  106.                 model.regenerate();     /* regenerate the shape based on mtx */
  107.                 model.CONTOUR::display( mag );
  108.                 printf("Press Enter to continue...n");
  109.                 getchar();
  110.              }
  111.         }
  112.         printf("nResulting contour :n");
  113.         model.CONTOUR::print() ;
  114. }
  115. end{verbatim}
  116. This program reads in one sample at each interaction. An initial estimate of the shape matrix are computed from the first sample. {tt localize} and {tt minimize} will localize the second sample and minimize its energy, and then {tt LearnShape} updates the new shape matrix. Since the shape matrix is regenerative, {tt regenerate} will generate a new contour. By repeating this precedure for many samples, we can obtain a learned model. If we take several square images which undergo affine transformation to train the shape matrix, the program will show that the regenerative shape is still a square. This verify the invariance of a shape matrix.