msImageProcessor.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. Mean Shift Image Processor Class:
  9. ================================
  10. The following class inherits from the mean shift library
  11. in order to perform the specialized tasks of image
  12. segmentation and filtering.
  13. The prototype of the Mean Shift Image Processor Class
  14. is provided below. Its definition is provided in
  15. 'msImageProcessor.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 msImageProcessor_H
  25. #define msImageProcessor_H
  26. //include mean shift library
  27. #include "ms.h"
  28. //include prototypes of additional strucuters
  29. //used for image segmentation...
  30. //include region list used to store boundary pixel
  31. //indeces for each region
  32. #include "rlist.h"
  33. //include region adjacency list class used for
  34. //region pruning and transitive closure
  35. #include "RAList.h"
  36. //define constants
  37. //image pruning
  38. #define TOTAL_ITERATIONS 14
  39. #define BIG_NUM 0xffffffff //BIG_NUM = 2^32-1
  40. #define NODE_MULTIPLE 10
  41. //data space conversion...
  42. const double Xn = 0.95050;
  43. const double Yn = 1.00000;
  44. const double Zn = 1.08870;
  45. //const double Un_prime = 0.19780;
  46. //const double Vn_prime = 0.46830;
  47. const double Un_prime = 0.19784977571475;
  48. const double Vn_prime = 0.46834507665248;
  49. const double Lt = 0.008856;
  50. //RGB to LUV conversion
  51. const double XYZ[3][3] = { { 0.4125, 0.3576, 0.1804 },
  52. { 0.2125, 0.7154, 0.0721 },
  53. { 0.0193, 0.1192, 0.9502 } };
  54. //LUV to RGB conversion
  55. const double RGB[3][3] = { { 3.2405, -1.5371, -0.4985 },
  56. { -0.9693, 1.8760, 0.0416 },
  57. { 0.0556, -0.2040, 1.0573 } };
  58. //define data types
  59. typedef unsigned char byte;
  60. //define enumerations
  61. enum imageType {GRAYSCALE, COLOR};
  62. //define prototype
  63. class msImageProcessor: public MeanShift {
  64. public:
  65. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  66. /* Class Constructor and Destructor */
  67. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  68. msImageProcessor( void ); //Default Constructor
  69. ~msImageProcessor( void ); //Class Destructor
  70. /*/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  71. /* Input Image Declaration */
  72. /*\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  73. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  74. //<--------------------------------------------------->|//
  75. //| |//
  76. //| Method Name: |//
  77. //| ============ |//
  78. //| * Define Image * |//
  79. //| |//
  80. //<--------------------------------------------------->|//
  81. //| |//
  82. //| Description: |//
  83. //| ============ |//
  84. //| |//
  85. //| Uploads an image to be segmented by the image |//
  86. //| segmenter class. |//
  87. //| |//
  88. //| An image is defined by specifying the folloing: |//
  89. //| |//
  90. //| <* data *> |//
  91. //| A one dimensional unsigned char array of RGB |//
  92. //| vectors. |//
  93. //| |//
  94. //| <* type *> |//
  95. //| Specifies the image type: COLOR or GREYSCALE. |//
  96. //| |//
  97. //| <* height *> |//
  98. //| The image height. |//
  99. //| |//
  100. //| <* width *> |//
  101. //| The image width. |//
  102. //| |//
  103. //| This method uploads the image and converts its |//
  104. //| data into the LUV space. If another conversion |//
  105. //| is desired data may be uploaded into this class |//
  106. //| via the procedure MeanShift::UploadInput(). |//
  107. //| |//
  108. //<--------------------------------------------------->|//
  109. //| |//
  110. //| Usage: |//
  111. //| ====== |//
  112. //| DefineImage(data, type, height, width) |//
  113. //| |//
  114. //<--------------------------------------------------->|//
  115. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  116. void DefineImage(byte*,imageType, int, int);
  117. void DefineBgImage(byte*, imageType , int , int );
  118. /*/\/\/\/\/\/\*/
  119. /* Weight Map */
  120. /*\/\/\/\/\/\/*/
  121. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  122. //<--------------------------------------------------->|//
  123. //| |//
  124. //| Method Name: |//
  125. //| ============ |//
  126. //| * Set Weight Map * |//
  127. //| |//
  128. //<--------------------------------------------------->|//
  129. //| |//
  130. //| Description: |//
  131. //| ============ |//
  132. //| |//
  133. //| Uploads weight map specifying for each pixel |//
  134. //| in the image a value between 0 and 1 - 1 indica- |//
  135. //| ting the presence of an edge and 0 the absense |//
  136. //| of an edge. |//
  137. //| |//
  138. //| The arguments to this method are: |//
  139. //| |//
  140. //| <* weightMap *> |//
  141. //| A floating point array of size (height x width) |//
  142. //| specifying at location (i,j) the edge strength |//
  143. //| of pixel (i,j). (e.g. pixel (i,j) has an edge |//
  144. //| strength of weightMap[j*width+i]). |//
  145. //| |//
  146. //| <* epsilon *> |//
  147. //| A floating point number specifying the threshold |//
  148. //| used to fuse regions during transitive closure. |//
  149. //| |//
  150. //| Note: DefineImage must be called prior to call- |//
  151. //| ing this method. DefineImage is used to |//
  152. //| define the dimensions of the image. |//
  153. //| |//
  154. //<--------------------------------------------------->|//
  155. //| |//
  156. //| Usage: |//
  157. //| ====== |//
  158. //| SetWeightMap(weightMap, epsilon) |//
  159. //| |//
  160. //<--------------------------------------------------->|//
  161. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  162. void SetWeightMap(float*, float);
  163. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  164. //<--------------------------------------------------->|//
  165. //| |//
  166. //| Method Name: |//
  167. //| ============ |//
  168. //| * Remove Weight Map * |//
  169. //| |//
  170. //<--------------------------------------------------->|//
  171. //| |//
  172. //| Description: |//
  173. //| ============ |//
  174. //| |//
  175. //| Removes weight map. An error is NOT flagged |//
  176. //| if a weight map was not defined prior to calling |//
  177. //| this method. |//
  178. //| |//
  179. //<--------------------------------------------------->|//
  180. //| |//
  181. //| Usage: |//
  182. //| ====== |//
  183. //| RemoveWeightMap(void) |//
  184. //| |//
  185. //<--------------------------------------------------->|//
  186. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  187. void RemoveWeightMap(void);
  188. /*/\/\/\/\/\/\/\/\/\*/
  189. /* Image Filtering */
  190. /*\/\/\/\/\/\/\/\/\/*/
  191. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  192. //<--------------------------------------------------->|//
  193. //| |//
  194. //| Method Name: |//
  195. //| ============ |//
  196. //| * Filter * |//
  197. //| |//
  198. //<--------------------------------------------------->|//
  199. //| |//
  200. //| Description: |//
  201. //| ============ |//
  202. //| |//
  203. //| Apply mean shift filter to the defined image, |//
  204. //| defined either via MeanShift::DefineLInput or |//
  205. //| msImageProcessor::DefineImage. The resulting |//
  206. //| segmented image is stored in the private data |//
  207. //| members of the image segmenter class which can |//
  208. //| be obtained by calling image msImageProcessor:: |//
  209. //| GetResults(). |//
  210. //| |//
  211. //| The arguments to this method are: |//
  212. //| |//
  213. //| <* sigmaS *> |//
  214. //| The spatial radius of the mean shift window. |//
  215. //| |//
  216. //| <* sigmaR *> |//
  217. //| The range radius of the mean shift window. |//
  218. //| |//
  219. //| <* speedUpLevel *> |//
  220. //| Determines if a speed up optimization should be |//
  221. //| used to perform image filtering. A value of |//
  222. //| NO_SPEEDUP turns this optimization off and a |//
  223. //| value of SPEEDUP turns this optimization on. |//
  224. //| |//
  225. //<--------------------------------------------------->|//
  226. //| |//
  227. //| Usage: |//
  228. //| ====== |//
  229. //| Filter(sigmaS, sigmaR, speedUpLevel) |//
  230. //| |//
  231. //<--------------------------------------------------->|//
  232. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  233. void Filter(int, float, SpeedUpLevel);
  234. /*/\/\/\/\/\/\/\/\/\/\/\*/
  235. /* Image Region Fusing */
  236. /*\/\/\/\/\/\/\/\/\/\/\/*/
  237. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  238. //<--------------------------------------------------->|//
  239. //| |//
  240. //| Method Name: |//
  241. //| ============ |//
  242. //| * Fuse Regions * |//
  243. //| |//
  244. //<--------------------------------------------------->|//
  245. //| |//
  246. //| Description: |//
  247. //| ============ |//
  248. //| |//
  249. //| Fuses the regions of a filtered image, |//
  250. //| defined either via MeanShift::DefineLInput or |//
  251. //| msImageProcessor::DefineImage. The resulting |//
  252. //| segmented image is stored in the private data |//
  253. //| members of the image segmenter class which can |//
  254. //| be obtained by calling image msImageProcessor:: |//
  255. //| GetResults(). |//
  256. //| |//
  257. //| The arguments to this method are: |//
  258. //| |//
  259. //| <* sigmaR *> |//
  260. //| The range radius that defines similar color |//
  261. //| amongst image regions. |//
  262. //| |//
  263. //| <* minRegion *> |//
  264. //| The minimum density a region may have in the |//
  265. //| resulting segmented image. All regions have |//
  266. //| point density < minRegion are pruned from the |//
  267. //| image. |//
  268. //| |//
  269. //<--------------------------------------------------->|//
  270. //| |//
  271. //| Usage: |//
  272. //| ====== |//
  273. //| FuseRegions(sigmaR, minRegion) |//
  274. //| |//
  275. //<--------------------------------------------------->|//
  276. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  277. void FuseRegions(float, int);
  278. /*/\/\/\/\/\/\/\/\/\/\*/
  279. /* Image Segmentation */
  280. /*\/\/\/\/\/\/\/\/\/\/*/
  281. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  282. //<--------------------------------------------------->|//
  283. //| |//
  284. //| Method Name: |//
  285. //| ============ |//
  286. //| * Segment * |//
  287. //| |//
  288. //<--------------------------------------------------->|//
  289. //| |//
  290. //| Description: |//
  291. //| ============ |//
  292. //| |//
  293. //| Segments the defined image, defined either via |//
  294. //| MeanShift::DefineLInput or msImageProcessor::De- |//
  295. //| fineImage. The resulting segmented image is |//
  296. //| stored in the private data members of the image |//
  297. //| processor class which can be obtained by calling |//
  298. //| ImageSegmenter::GetResults(). |//
  299. //| |//
  300. //| The arguments to this method are: |//
  301. //| |//
  302. //| <* sigmaS *> |//
  303. //| The spatial radius of the mean shift window. |//
  304. //| |//
  305. //| <* sigmaR *> |//
  306. //| The range radius of the mean shift window. |//
  307. //| |//
  308. //| <* minRegion *> |//
  309. //| The minimum density a region may have in the |//
  310. //| resulting segmented image. All regions have |//
  311. //| point density < minRegion are pruned from the |//
  312. //| image. |//
  313. //| |//
  314. //| <* speedUpLevel *> |//
  315. //| Determines if a speed up optimization should be |//
  316. //| used to perform image filtering. A value of |//
  317. //| NO_SPEEDUP turns this optimization off and a |//
  318. //| value of SPEEDUP turns this optimization on. |//
  319. //| |//
  320. //<--------------------------------------------------->|//
  321. //| |//
  322. //| Usage: |//
  323. //| ====== |//
  324. //| Segment(sigmaS, sigmaR, minRegion, |//
  325. //| speedUpLevel) |//
  326. //| |//
  327. //<--------------------------------------------------->|//
  328. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  329. void Segment(int, float, int, SpeedUpLevel);
  330. /*/\/\/\/\/\/\/\/\/\/\/\/\*/
  331. /* Data Space Conversion */
  332. /*\/\/\/\/\/\/\/\/\/\/\/\/*/
  333. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  334. //<--------------------------------------------------->|//
  335. //| |//
  336. //| Method Name: |//
  337. //| ============ |//
  338. //| * RGB To LUV * |//
  339. //| |//
  340. //<--------------------------------------------------->|//
  341. //| |//
  342. //| Description: |//
  343. //| ============ |//
  344. //| |//
  345. //| Converts an RGB vector to LUV. |//
  346. //| |//
  347. //| The arguments to this method are: |//
  348. //| |//
  349. //| <* rgbVal *> |//
  350. //| An unsigned char array containing the RGB |//
  351. //| vector. |//
  352. //| |//
  353. //| <* luvVal *> |//
  354. //| A floating point array containing the LUV |//
  355. //| vector. |//
  356. //| |//
  357. //<--------------------------------------------------->|//
  358. //| |//
  359. //| Usage: |//
  360. //| ====== |//
  361. //| RGBtoLUV(rgbVal, luvVal) |//
  362. //| |//
  363. //<--------------------------------------------------->|//
  364. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  365. void RGBtoLUV(byte*, float*);
  366. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  367. //<--------------------------------------------------->|//
  368. //| |//
  369. //| Method Name: |//
  370. //| ============ |//
  371. //| * LUV To RGB * |//
  372. //| |//
  373. //<--------------------------------------------------->|//
  374. //| |//
  375. //| Description: |//
  376. //| ============ |//
  377. //| |//
  378. //| Converts an LUV vector to RGB. |//
  379. //| |//
  380. //| The arguments to this method are: |//
  381. //| |//
  382. //| <* luvVal *> |//
  383. //| A floating point array containing the LUV |//
  384. //| vector. |//
  385. //| |//
  386. //| <* rgbVal *> |//
  387. //| An unsigned char array containing the RGB |//
  388. //| vector. |//
  389. //| |//
  390. //<--------------------------------------------------->|//
  391. //| |//
  392. //| Usage: |//
  393. //| ====== |//
  394. //| LUVtoRGB(luvVal, rgbVal) |//
  395. //| |//
  396. //<--------------------------------------------------->|//
  397. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  398. void LUVtoRGB(float*, byte*);
  399. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  400. /* Filtered and Segmented Image Output */
  401. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  402. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  403. //<--------------------------------------------------->|//
  404. //| |//
  405. //| Method Name: |//
  406. //| ============ |//
  407. //| * Get Raw Data * |//
  408. //| |//
  409. //<--------------------------------------------------->|//
  410. //| |//
  411. //| Description: |//
  412. //| ============ |//
  413. //| |//
  414. //| Returns the resulting filtered or segmented im- |//
  415. //| age data after calling Filter() or Segment(). |//
  416. //| |//
  417. //| The arguments to this method are: |//
  418. //| |//
  419. //| <* outputImageData *> |//
  420. //| A floating point array containing the vector |//
  421. //| data of the filtered or segmented image. |//
  422. //| |//
  423. //| NOTE: If DefineImage was used to specify the |//
  424. //| the input to this class, outputImageData |//
  425. //| is in the LUV data space. |//
  426. //| |//
  427. //<--------------------------------------------------->|//
  428. //| |//
  429. //| Usage: |//
  430. //| ====== |//
  431. //| GetResults(outputImageData) |//
  432. //| |//
  433. //<--------------------------------------------------->|//
  434. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  435. void GetRawData(float*);
  436. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  437. //<--------------------------------------------------->|//
  438. //| |//
  439. //| Method Name: |//
  440. //| ============ |//
  441. //| * Get Results * |//
  442. //| |//
  443. //<--------------------------------------------------->|//
  444. //| |//
  445. //| Description: |//
  446. //| ============ |//
  447. //| |//
  448. //| Returns the resulting filtered or segmented im- |//
  449. //| age after calling Filter() or Segment(). |//
  450. //| |//
  451. //| The arguments to this method are: |//
  452. //| |//
  453. //| <* outputImage *> |//
  454. //| An unsigned char array containing the RGB |//
  455. //| vector data of the output image. |//
  456. //| |//
  457. //| To obtain the un-converted (LUV) data space |//
  458. //| output one may use |//
  459. //| msImageProcessor::GetRawData(). |//
  460. //<--------------------------------------------------->|//
  461. //| |//
  462. //| Usage: |//
  463. //| ====== |//
  464. //| GetResults(outputImage) |//
  465. //| |//
  466. //<--------------------------------------------------->|//
  467. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  468. void GetResults(byte*);
  469. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  470. //<--------------------------------------------------->|//
  471. //| |//
  472. //| Method Name: |//
  473. //| ============ |//
  474. //| * Get Boundaries * |//
  475. //| |//
  476. //<--------------------------------------------------->|//
  477. //| |//
  478. //| Description: |//
  479. //| ============ |//
  480. //| |//
  481. //| Returns the boundaries of each region of the |//
  482. //| segmented image using a region list object, |//
  483. //| available after filtering or segmenting the |//
  484. //| defined image. |//
  485. //| |//
  486. //<--------------------------------------------------->|//
  487. //| |//
  488. //| Usage: |//
  489. //| ====== |//
  490. //| regionList = GetBoundaries() |//
  491. //| |//
  492. //<--------------------------------------------------->|//
  493. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  494. RegionList *GetBoundaries( void );
  495. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  496. //<--------------------------------------------------->|//
  497. //| |//
  498. //| Method Name: |//
  499. //| ============ |//
  500. //| * Get Regions * |//
  501. //| |//
  502. //<--------------------------------------------------->|//
  503. //| |//
  504. //| Description: |//
  505. //| ============ |//
  506. //| |//
  507. //| Returns the regions of the processed image. |//
  508. //| Each region in the image is uniquely character- |//
  509. //| ized by its location and color (e.g. RGB). |//
  510. //| GetRegions() therefore returns the following |//
  511. //| information about the regions of the processed |//
  512. //| image: |//
  513. //| |//
  514. //| <* regionCount *> |//
  515. //| An integer that specifies the number of regions |//
  516. //| contained in the processed image. |//
  517. //| |//
  518. //| <* modes *> |//
  519. //| A floating point array of length regionCount*N |//
  520. //| containing the feature space component of each |//
  521. //| region (e.g. LUV), and indexed by region label. |//
  522. //| |//
  523. //| <* labels *> |//
  524. //| An integer array of length (height*width) which |//
  525. //| contains at every pixel location (x,y) a label |//
  526. //| relating that pixel to a region whose mode is |//
  527. //| specified by modes and whose area is specified |//
  528. //| by modePointCounts. |//
  529. //| |//
  530. //| <* modePointCounts *> |//
  531. //| An integer array of length regionCount and ind- |//
  532. //| exed by region label, that specifies the region |//
  533. //| area (in pixels) for each segmented image reg- |//
  534. //| ion. (e.g. Area of region having label specif- |//
  535. //| ified by l, has area modePointCounts[l] (pix- |//
  536. //| els).) |//
  537. //| |//
  538. //| NOTE: Memory for the above integer and floating |//
  539. //| point arrays is allocated inside this |//
  540. //| method. |//
  541. //| |//
  542. //| Also modes stored by the modes array are |//
  543. //| not in the RGB space. Instead if the |//
  544. //| method DefineImage was used, these data |//
  545. //| points are in the LUV space, and if the |//
  546. //| method DefineLInput was used these data |//
  547. //| points are in whatever space you specified |//
  548. //| them to be in when calling DefineLInput. |//
  549. //| |//
  550. //<--------------------------------------------------->|//
  551. //| |//
  552. //| Usage: |//
  553. //| ====== |//
  554. //| regionCount = GetRegions(labels, modes |//
  555. //| modePointCounts) |//
  556. //| |//
  557. //<--------------------------------------------------->|//
  558. //--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//--\\||//
  559. int GetRegions(int**, float**, int**);
  560. void SetSpeedThreshold(float);
  561. private:
  562. //========================
  563. // *** Private Methods ***
  564. //========================
  565. /*/\/\/\/\/\/\/\/\/\*/
  566. /* Image Filtering */
  567. /*\/\/\/\/\/\/\/\/\/*/
  568. void NonOptimizedFilter(float, float); // filters the image applying mean shift to each point
  569. // Advantage : most accurate
  570. // Disadvantage : time expensive
  571. void NewNonOptimizedFilter(float, float);
  572. void OptimizedFilter1(float, float); // filters the image using previous mode information
  573. // to avoid re-applying mean shift to some data points
  574. // Advantage : maintains high level of accuracy,
  575. // large speed up compared to non-optimized
  576. // version
  577. // Disadvantage : POSSIBLY not as accurate as non-optimized
  578. // version
  579. void NewOptimizedFilter1(float, float);
  580. void OptimizedFilter2(float, float); //filter the image using previous mode information
  581. //and window traversals to avoid re-applying mean shift to
  582. //some data points
  583. // Advantage : huge speed up - maintains accuracy good enough
  584. // for segmentation
  585. // Disadvantage : not as accurate as previous filters
  586. void NewOptimizedFilter2(float, float);
  587. /*/\/\/\/\/\/\/\/\/\/\/\*/
  588. /* Image Classification */
  589. /*\/\/\/\/\/\/\/\/\/\/\/*/
  590. void Connect( void ); // classifies mean shift filtered image regions using
  591. // private classification structure of this class
  592. void Fill(int, int); // used by Connect to perform label each region in the
  593. // mean shift filtered image using an eight-connected
  594. // fill
  595. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  596. /* Transitive Closure and Image Pruning */
  597. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  598. void BuildRAM( void ); // build a region adjacency matrix using the region list
  599. // object
  600. void DestroyRAM( void ); // destroy the region adjacency matrix: de-allocate its memory
  601. // initialize it for re-use
  602. void TransitiveClosure( void ); // use the RAM to apply transitive closure to the image modes
  603. void ComputeEdgeStrengths( void ); // computes the weights of the weighted graph using the weight
  604. // map
  605. //Usage: Prune(minRegion)
  606. void Prune(int); // use the RAM to prune the image of spurious regions (regions
  607. // whose area is less than minRegion pixels, where minRegion is
  608. // an argument of this method)
  609. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  610. /* Region Boundary Detection */
  611. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  612. void DefineBoundaries( void ); // defines the boundaries of each region using the classified segmented
  613. // image storing the resulting boundary locations for each region using
  614. // a region list object
  615. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  616. /* Image Data Searching/Distance Calculation */
  617. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
  618. //Usage: InWindow(modeIndex1, modeIndex2)
  619. bool InWindow(int, int); //returns true if the range data of the specified data points
  620. //are within the defined search window (defined by kernel
  621. //bandwidth h[1])
  622. float SqDistance(int, int); // computes the normalized square distance between two modes
  623. /*/\/\/\/\/\/\/\/\/\/\*/
  624. /* Memory Management */
  625. /*\/\/\/\/\/\/\/\/\/\/*/
  626. void InitializeOutput( void ); //Allocates memory needed by this class to perform image
  627. //filtering and segmentation
  628. void DestroyOutput( void ); //De-allocates memory needed by this class to perform image
  629. //filtering and segmentation
  630. //=============================
  631. // *** Private Data Members ***
  632. //=============================
  633. //##########################################
  634. //####### IMAGE CLASSIFICATION ########
  635. //##########################################
  636. /////////Image Boundaries/////////
  637. RegionList *regionList; // stores the boundary locations for each region
  638. /////////Image Regions////////
  639. int regionCount; // stores the number of connected regions contained by the
  640. // image
  641. /////////8 Connected Neighbors/////////
  642. int neigh[8];
  643. /////////Index Table/////////////////
  644. int *indexTable; //used during fill algorithm
  645. /////////LUV_data/////////////////
  646. //int *LUV_data; //stores modes in integer format on lattice
  647. float *LUV_data; //stores modes in float format on lattice
  648. float LUV_treshold; //in float mode this determines what "close" means between modes
  649. //##########################################
  650. //####### OUTPUT DATA STORAGE ########
  651. //##########################################
  652. ////////Raw Data (1 to 1 correlation with input)////////
  653. float *msRawData; // Raw data output of mean shift algorithm
  654. // to the location of the data point on the lattice
  655. ////////Data Modes////////
  656. int *labels; // assigns a label to each data point associating it to
  657. // a mode in modes (e.g. a data point having label l has
  658. // mode modes[l])
  659. float *modes; // stores the mode data of the input data set, indexed by labels
  660. int *modePointCounts; // stores for each mode the number of point mapped to that mode,
  661. // indexed by labels
  662. //##########################################
  663. //####### REGION ADJACENCY MATRIX ########
  664. //##########################################
  665. //////////Region Adjacency List/////////
  666. RAList *raList; // an array of RAList objects containing an entry for each
  667. // region of the image
  668. //////////RAMatrix Free List///////////
  669. RAList *freeRAList; // a pointer to the head of a region adjacency list object
  670. // free list
  671. RAList *raPool; // a pool of RAList objects used in the construction of the
  672. // RAM
  673. //##############################################
  674. //####### COMPUTATION OF EDGE STRENGTHS #######
  675. //##############################################
  676. //////////Epsilon///////////
  677. float epsilon; //Epsilon used for transitive closure
  678. //////Visit Table//////
  679. unsigned char *visitTable; //Table used to keep track of which pixels have been
  680. //already visited upon computing the boundary edge strengths
  681. //##########################################
  682. //####### IMAGE PRUNING ########
  683. //##########################################
  684. ////////Transitive Closure/////////
  685. float rR2; //defines square range radius used when clustering pixels
  686. //together, thus defining image regions
  687. float speedThreshold; // the % of window radius used in new optimized filter 2.
  688. float percent_complete;
  689. };
  690. #endif