rlist.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*******************************************************
  2. Mean Shift Analysis Library
  3. =============================================
  4. The mean shift library is a collection of routines
  5. that use the mean shift algorithm. Using this algorithm,
  6. the necessary output will be generated needed
  7. to analyze a given input set of data.
  8. Region List Class:
  9. =================
  10. During segmentation, data regions are defined. The
  11. RegionList class provides a mechanism for doing so, as
  12. well as defines some basic operations, such as region
  13. growing or small region pruning, on the defined regions.
  14. The prototype for the RegionList class is provided below. It
  15. is defined in "region.cc".
  16. The theory is described in the papers:
  17. D. Comaniciu, P. Meer: Mean Shift: A robust approach toward feature
  18. space analysis.
  19. C. Christoudias, B. Georgescu, P. Meer: Synergism in low level vision.
  20. and they are is available at:
  21. http://www.caip.rutgers.edu/riul/research/papers/
  22. Implemented by Chris M. Christoudias, Bogdan Georgescu
  23. ********************************************************/
  24. #ifndef RLIST_H
  25. #define RLIST_H
  26. //include global type definitions
  27. #include "tdef.h"
  28. //define region structure
  29. struct REGION {
  30. int label;
  31. int pointCount;
  32. int region;
  33. };
  34. //region class prototype...
  35. class RegionList {
  36. public:
  37. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  38. /* Class Constructor and Destructor */
  39. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  40. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  41. //<--------------------------------------------------->|//
  42. //| |//
  43. //| Method Name: |//
  44. //| ============ |//
  45. //| * Class Constructor * |//
  46. //| |//
  47. //<--------------------------------------------------->|//
  48. //| |//
  49. //| Description: |//
  50. //| ============ |//
  51. //| |//
  52. //| Constructs a region list object. |//
  53. //| |//
  54. //| Its arguments are: |//
  55. //| |//
  56. //| <* maxRegions *> |//
  57. //| The maximum amount of regions that can be class- |//
  58. //| ified by the region list. |//
  59. //| |//
  60. //| <* L *> |//
  61. //| The length of the input data set being class- |//
  62. //| ified by the region list object. |//
  63. //| |//
  64. //| <* N *> |//
  65. //| The dimension of the input data set being class- |//
  66. //| ified by the region list object. |//
  67. //| |//
  68. //<--------------------------------------------------->|//
  69. //| |//
  70. //| Usage: |//
  71. //| ====== |//
  72. //| RegionList(maxRegions, L, N) |//
  73. //| |//
  74. //<--------------------------------------------------->|//
  75. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  76. RegionList(int, int, int);
  77. // Class Destructor
  78. ~RegionList( void );
  79. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  80. /* Region List Manipulation */
  81. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  82. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  83. //<--------------------------------------------------->|//
  84. //| |//
  85. //| Method Name: |//
  86. //| ============ |//
  87. //| * Add Region * |//
  88. //| |//
  89. //<--------------------------------------------------->|//
  90. //| |//
  91. //| Description: |//
  92. //| ============ |//
  93. //| |//
  94. //| Adds a region to the region list. |//
  95. //| |//
  96. //| Its arguments are: |//
  97. //| |//
  98. //| <* label *> |//
  99. //| |//
  100. //| A positive integer used to uniquely identify |//
  101. //| a region. |//
  102. //| |//
  103. //| <* pointCount *> |//
  104. //| A positive integer that specifies the number of |//
  105. //| N-dimensional data points that exist in the re- |//
  106. //| gion being classified. |//
  107. //| |//
  108. //| <* indeces *> |//
  109. //| An integer array that specifies the set of ind- |//
  110. //| eces of the data points that are contianed with- |//
  111. //| in this region. |//
  112. //| |//
  113. //<--------------------------------------------------->|//
  114. //| |//
  115. //| Usage: |//
  116. //| ====== |//
  117. //| AddRegion(label, pointCount, indeces) |//
  118. //| |//
  119. //<--------------------------------------------------->|//
  120. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  121. void AddRegion(int, int, int*);
  122. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  123. //<--------------------------------------------------->|//
  124. //| |//
  125. //| Method Name: |//
  126. //| ============ |//
  127. //| * Reset * |//
  128. //| |//
  129. //<--------------------------------------------------->|//
  130. //| |//
  131. //| Description: |//
  132. //| ============ |//
  133. //| |//
  134. //| Resets the region list for re-use (for new |//
  135. //| classification). |//
  136. //| |//
  137. //<--------------------------------------------------->|//
  138. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  139. void Reset( void );
  140. /*/\/\/\/\/\/\/\/\/\/\*/
  141. /* Query Region List */
  142. /*\/\/\/\/\/\/\/\/\/\/*/
  143. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  144. //<--------------------------------------------------->|//
  145. //| |//
  146. //| Method Name: |//
  147. //| ============ |//
  148. //| * Get Number of Regions * |//
  149. //| |//
  150. //<--------------------------------------------------->|//
  151. //| |//
  152. //| Description: |//
  153. //| ============ |//
  154. //| |//
  155. //| Returns the number of regions stored by the |//
  156. //| region list. |//
  157. //| |//
  158. //<--------------------------------------------------->|//
  159. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  160. int GetNumRegions ( void );
  161. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  162. //<--------------------------------------------------->|//
  163. //| |//
  164. //| Method Name: |//
  165. //| ============ |//
  166. //| * Get Label * |//
  167. //| |//
  168. //<--------------------------------------------------->|//
  169. //| |//
  170. //| Description: |//
  171. //| ============ |//
  172. //| |//
  173. //| Returns the label of a specified region. |//
  174. //| |//
  175. //| Its arguments are: |//
  176. //| |//
  177. //| <* regionNumber *> |//
  178. //| The index of the region in the region list |//
  179. //| array. |//
  180. //| |//
  181. //<--------------------------------------------------->|//
  182. //| |//
  183. //| Usage: |//
  184. //| ====== |//
  185. //| label = GetLabel(regionNumber) |//
  186. //| |//
  187. //<--------------------------------------------------->|//
  188. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  189. int GetLabel(int);
  190. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  191. //<--------------------------------------------------->|//
  192. //| |//
  193. //| Method Name: |//
  194. //| ============ |//
  195. //| * Get Region Count * |//
  196. //| |//
  197. //<--------------------------------------------------->|//
  198. //| |//
  199. //| Description: |//
  200. //| ============ |//
  201. //| |//
  202. //| Returns number of data points contained by a sp- |//
  203. //| ecified region. |//
  204. //| |//
  205. //| Its arguments are: |//
  206. //| |//
  207. //| <* regionNumber *> |//
  208. //| The index of the region in the region list |//
  209. //| array. |//
  210. //| |//
  211. //<--------------------------------------------------->|//
  212. //| |//
  213. //| Usage: |//
  214. //| ====== |//
  215. //| pointCount = GetRegionCount(regionNumber) |//
  216. //| |//
  217. //<--------------------------------------------------->|//
  218. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  219. int GetRegionCount(int);
  220. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  221. //<--------------------------------------------------->|//
  222. //| |//
  223. //| Method Name: |//
  224. //| ============ |//
  225. //| * Get Region Indeces * |//
  226. //| |//
  227. //<--------------------------------------------------->|//
  228. //| |//
  229. //| Description: |//
  230. //| ============ |//
  231. //| |//
  232. //| Returns a pointer to a set of grid location ind- |//
  233. //| eces specifying the data points belonging to a |//
  234. //| specified region. |//
  235. //| |//
  236. //| Its arguments are: |//
  237. //| |//
  238. //| <* regionNumber *> |//
  239. //| The index of the region in the region list |//
  240. //| array. |//
  241. //| |//
  242. //<--------------------------------------------------->|//
  243. //| |//
  244. //| Usage: |//
  245. //| ====== |//
  246. //| indeces = GetRegionIndeces(regionNumber) |//
  247. //| |//
  248. //<--------------------------------------------------->|//
  249. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  250. int*GetRegionIndeces(int);
  251. private:
  252. /*/\/\/\/\/\/\/\/\/\/\/\*/
  253. /* Class Error Handler */
  254. /*\/\/\/\/\/\/\/\/\/\/\/*/
  255. void ErrorHandler(char*, char*, ErrorType);
  256. //=============================
  257. // *** Private Data Members ***
  258. //=============================
  259. //#####################################
  260. //### REGION LIST PARTITIONED ARRAY ###
  261. //#####################################
  262. REGION *regionList; //array of maxRegions regions
  263. int minRegion;
  264. int maxRegions; //defines the number maximum number of regions
  265. //allowed (determined by user during class construction)
  266. int numRegions; //the number of regions currently stored by the
  267. //region list
  268. int freeRegion; //an index into the regionList pointing to the next
  269. //available region in the regionList
  270. //#####################################
  271. //### INDEX TABLE ###
  272. //#####################################
  273. int *indexTable; //an array of indexes that point into an external structure
  274. //specifying which points belong to a region
  275. int freeBlockLoc; //points to the next free block of memory in the indexTable
  276. //#####################################
  277. //### INPUT DATA PARAMETERS ###
  278. //#####################################
  279. //Dimension of data set
  280. int N; //dimension of data set being classified by region list
  281. //class
  282. //Length of the data set
  283. int L; //number of points contained by the data set being classified by
  284. //region list class
  285. };
  286. #endif