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

Windows Develop

Development Platform:

Unix_Linux

  1. rhead{class CLASSIFY}
  2. section{CLASSIFY : Contour Classification}
  3. {tt CLASSIFY} provides advance routines for detecting and classifying deformable contours directly from noisy image (Chapter 4 of cite{kn:thesis}). It calculates the score of each competitive templates based on marginalization of the distribution ({tt _MARGIN_PROB}), MAP probability ({tt _DEFORM_PROB}), match of deformable template ({tt _DEFORM_MATCH}) and match of rigid template ({tt _RIGID_MATCH}). It has the following structure :
  4. begin{verbatim}
  5. class CLASSIFY : public REGION {
  6.     protected :
  7.         int numClass ;                 /* number of class */
  8.         EEXTTYPE Eexttype ;             /* type of external energy */
  9.         CONTOUR **templates ;           /* reference templates */
  10.         char **labels ;                 /* label of templates */
  11.         double *Margin_Prob;            /* marginalized probability */
  12.         double *Rigid_Match ;           /* rigid match score */
  13.         double *Deform_Match ;          /* deform match score */
  14.         double *Deform_Prob ;           /* deform match probability */
  15.    
  16.    /* these localization and minimization parameters are made public so
  17.       that modifying them can be easy */
  18.    public :
  19.         int Qx, Qy ;                    /* GHT Image Cell Resolutions */
  20.         int NR, Nrxy, Nt, Ndx, Ndy ;    /* GHT ranges */
  21.         double QR, Qrxy, Qt, Qdx, Qdy;  /* GHT Resolutions */
  22.         double R, THETA ;               /* GHT Constants */
  23.         int numSearchSegment ;          /* number of search segments */
  24.         int segmentSpacing ;            /* spacing between segments */
  25.         int numLevel ;                  /* number of pyramid levels */
  26.         int verbose ;                   /* verbose mode */
  27.         int nhoodTangent, nhoodNormal;  /* neighborhood used in marginaliz-n */
  28.  end{verbatim}
  29. It stores a list of competitive templates and their corresponding score. In addition, extra parameters such as GHT range and resolution are used for localizaing and minimizing these templates.
  30. %
  31. subsection{CLASSIFY constructor}
  32. subsubsection*{Synopsis}
  33. begin{verbatim}
  34. CLASSIFY(EEXTTYPE _Eexttype = _EDGE);
  35. end{verbatim}
  36. subsubsection*{Arguments}
  37. tb
  38. {tt _Eexttype} & External energy type.
  39. te
  40. subsubsection*{Description}
  41. The constructor sets the default parameters and initializes all pointer members to NULL. 
  42. %
  43. subsection{CLASSIFY destructor}
  44. subsubsection*{Synopsis}
  45. begin{verbatim}
  46. ~CLASSIFY(void);
  47. end{verbatim}
  48. subsubsection*{Description}
  49. The destructor frees memory allocated to the pointer members.
  50. %
  51. subsection{Loading a template into CLASSIFY}
  52. subsubsection*{Synopsis}
  53. begin{verbatim}
  54. int read( CONTOUR *contour );
  55. int read( char *filename );
  56. end{verbatim}
  57. subsubsection*{Arguments}
  58. tb
  59. {tt contour} & Source {tt CONTOUR}. \
  60. {tt filename} & Contour file. 
  61. te
  62. subsubsection*{Returns}
  63. tb
  64. {tt NOERROR} & Template loaded successfully. \
  65. {tt MEMORYERROR} & Memory allocation failure or\
  66.   & template initialization error
  67. te
  68. subsubsection*{Description}
  69. These methods read in contour used for classification purpose. Once a contour is read, {tt numContour} is incremented by one, reflecting the total number of contours read.
  70. %
  71. subsection{Classifying templates}
  72. subsubsection*{Synopsis}
  73. begin{verbatim}
  74. int classify(IMAGE *testimg, CLASSTYPE ClassType = _MARGIN_PROB) ;
  75. end{verbatim}
  76. subsubsection*{Arguments}
  77. tb
  78. {tt testimg} & Testing image. \
  79. {tt ClassType} & Type of classification : \
  80. & {tt _MARGIN_PROB},
  81.  {tt _DEFORM_PROB}, {tt _DEFORM_MATCH} or {tt _RIGID_MATCH}.
  82. te
  83. subsubsection*{Returns}
  84. Classification score. 
  85. subsubsection*{Description}
  86. {tt classify} classify rigid and deformable templates directly from the testing image. For each template, it performs localization, minimization and marginalization to compute the classify score.
  87. %
  88. subsection{Selecting the best matching contour}
  89. subsubsection*{Synopsis}
  90. begin{verbatim}
  91. int selectMax( ClassTYPE ClassType = _MARGIN_PROB )
  92. end{verbatim}
  93. subsubsection*{Arguments}
  94. tb
  95. {tt ClassType} &  Type of classification : \
  96. &{tt _MARGIN_PROB},
  97.  {tt _DEFORM_PROB}, {tt _DEFORM_MATCH} or {tt _RIGID_MATCH}.
  98. te
  99. subsubsection*{Returns}
  100. Index to the template which consists of highest score.
  101. subsubsection*{Description}
  102. {tt selectMax} compares the classify score of templates of type interest and searches for the highest classify score.
  103. %
  104. subsection{Getting the number of templates read}
  105. subsubsection*{Synopsis}
  106. begin{verbatim}
  107. int getNumClass( void )
  108. end{verbatim}
  109. subsubsection*{Returns}
  110. Number of templates read.
  111. subsubsection*{Description}
  112. {tt getNumClass} retrieves the number of templates read.
  113. %
  114. subsection{Getting the matching score}
  115. subsubsection*{Synopsis}
  116. begin{verbatim}
  117. double getScore( int template_id, CLASSTYPE ClassType = _MARGIN_PROB)
  118. end{verbatim}
  119. subsubsection*{Arguments}
  120. tb
  121. {tt template_id} & Target template index. \
  122. {tt ClassType} & Type of classification : \
  123. & {tt _MARGIN_PROB},
  124.  {tt _DEFORM_PROB}, {tt _DEFORM_MATCH} or {tt _RIGID_MATCH}.
  125. te
  126. subsubsection*{Returns}
  127. Classify score of target template.
  128. subsubsection*{Description}
  129. {tt getScore} retrieves the score of template indexed by {tt template_id}.
  130. %
  131. subsection{Printing templates score}
  132. subsubsection*{Synopsis}
  133. begin{verbatim}
  134. void dump(char *imgName, FILE *stream = stdout)
  135. end{verbatim}
  136. subsubsection*{Description}
  137. {tt dump} prints onto screen or file the score of each templates.
  138. %
  139. subsection{Getting label of template}
  140. subsubsection*{Synopsis}
  141. begin{verbatim}
  142. char *getLabel(short class_id)
  143. end{verbatim}
  144. subsubsection*{Arguments}
  145. tb
  146. {tt ClassType} & Type of classification : \
  147. & {tt _MARGIN_PROB},
  148.  {tt _DEFORM_PROB}, {tt _DEFORM_MATCH} or {tt _RIGID_MATCH}.
  149. te
  150. subsubsection*{Returns}
  151. Label of template of interest.
  152. subsubsection*{Description}
  153. {getlabel} facilitates the retrieval of template label.
  154. %
  155. subsection{Example : Classifying various templates}
  156. begin{verbatim}
  157. void testmain( char **imgsamples ) /* image samples */
  158. {
  159.         register short i ;
  160.         CLASSIFY shape(_EDGE) ;
  161.  
  162.         shape.Nrxy = 3 ;    /* allow some stretching in diagonal direction */         
  163.         if( shape.read("ellip.con") != NOERROR ||
  164.             shape.read("rect.con") != NOERROR  ) {
  165.                 printf("cannot find contour filesn") ;
  166.                 exit(-1) ;
  167.         }
  168.          
  169.         for(i=0; *imgsamples; i++, imgsamples++) {
  170.         
  171.                 IMAGE myImage ;
  172.                 if( myImage.read(*imgsamples) != NOERROR )
  173.                         break ;
  174.                 int id = shape.classify(&myImage, _MARGIN_PROB) ;
  175.                 
  176.                 printf("%s : %sn", *imgsamples, shape.getLabel(id) ) ;
  177.                 
  178.                 shape.dump(*imgsamples) ;
  179.         }
  180.         exit(0) ;
  181. end{verbatim}
  182. This program read in two templates, namely {tt ellip.con} and {tt rect.con}. {tt classify} maginalizes the distribution and returns the matched template. {tt dump} will print on screen the classfy scores of the template.