You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
13 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /** @file mser.h
  2. ** @brief MSER (@ref mser)
  3. ** @author Andrea Vedaldi
  4. **/
  5. /*
  6. Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
  7. All rights reserved.
  8. This file is part of the VLFeat library and is made available under
  9. the terms of the BSD license (see the COPYING file).
  10. */
  11. #ifndef VL_MSER
  12. #define VL_MSER
  13. #include "generic.h"
  14. /** @brief MSER image data type
  15. **
  16. ** This is the data type of the image pixels. It has to be an
  17. ** integer.
  18. **/
  19. typedef vl_uint8 vl_mser_pix ;
  20. /** @brief Maximum value
  21. **
  22. ** Maximum value of the integer type ::vl_mser_pix.
  23. **/
  24. #define VL_MSER_PIX_MAXVAL 256
  25. /** @brief MSER Filter
  26. **
  27. ** The MSER filter computes the Maximally Stable Extremal Regions of
  28. ** an image.
  29. **
  30. ** @sa @ref mser
  31. **/
  32. typedef struct _VlMserFilt VlMserFilt ;
  33. /** @brief MSER filter statistics */
  34. typedef struct _VlMserStats VlMserStats ;
  35. /** @brief MSER filter statistics definition */
  36. struct _VlMserStats
  37. {
  38. int num_extremal ; /**< number of extremal regions */
  39. int num_unstable ; /**< number of unstable extremal regions */
  40. int num_abs_unstable ; /**< number of regions that failed the absolute stability test */
  41. int num_too_big ; /**< number of regions that failed the maximum size test */
  42. int num_too_small ; /**< number of regions that failed the minimum size test */
  43. int num_duplicates ; /**< number of regions that failed the duplicate test */
  44. } ;
  45. /** @name Construction and Destruction
  46. ** @{
  47. **/
  48. VL_EXPORT VlMserFilt* vl_mser_new (int ndims, int const* dims) ;
  49. VL_EXPORT void vl_mser_delete (VlMserFilt *f) ;
  50. /** @} */
  51. /** @name Processing
  52. ** @{
  53. **/
  54. VL_EXPORT void vl_mser_process (VlMserFilt *f,
  55. vl_mser_pix const *im) ;
  56. VL_EXPORT void vl_mser_ell_fit (VlMserFilt *f) ;
  57. /** @} */
  58. /** @name Retrieving data
  59. ** @{
  60. **/
  61. VL_INLINE vl_uint vl_mser_get_regions_num (VlMserFilt const *f) ;
  62. VL_INLINE vl_uint const* vl_mser_get_regions (VlMserFilt const *f) ;
  63. VL_INLINE float const* vl_mser_get_ell (VlMserFilt const *f) ;
  64. VL_INLINE vl_uint vl_mser_get_ell_num (VlMserFilt const *f) ;
  65. VL_INLINE vl_uint vl_mser_get_ell_dof (VlMserFilt const *f) ;
  66. VL_INLINE VlMserStats const* vl_mser_get_stats (VlMserFilt const *f) ;
  67. /** @} */
  68. /** @name Retrieving parameters
  69. ** @{
  70. **/
  71. VL_INLINE vl_mser_pix vl_mser_get_delta (VlMserFilt const *f) ;
  72. VL_INLINE double vl_mser_get_min_area (VlMserFilt const *f) ;
  73. VL_INLINE double vl_mser_get_max_area (VlMserFilt const *f) ;
  74. VL_INLINE double vl_mser_get_max_variation (VlMserFilt const *f) ;
  75. VL_INLINE double vl_mser_get_min_diversity (VlMserFilt const *f) ;
  76. /** @} */
  77. /** @name Setting parameters
  78. ** @{
  79. **/
  80. VL_INLINE void vl_mser_set_delta (VlMserFilt *f, vl_mser_pix x) ;
  81. VL_INLINE void vl_mser_set_min_area (VlMserFilt *f, double x) ;
  82. VL_INLINE void vl_mser_set_max_area (VlMserFilt *f, double x) ;
  83. VL_INLINE void vl_mser_set_max_variation (VlMserFilt *f, double x) ;
  84. VL_INLINE void vl_mser_set_min_diversity (VlMserFilt *f, double x) ;
  85. /** @} */
  86. /* ====================================================================
  87. * INLINE DEFINITIONS
  88. * ================================================================== */
  89. /** @internal
  90. ** @brief MSER accumulator data type
  91. **
  92. ** This is a large integer type. It should be large enough to contain
  93. ** a number equal to the area (volume) of the image by the image
  94. ** width by the image height (for instance, if the image is a square
  95. ** of side 256, the maximum value is 256 x 256 x 256).
  96. **/
  97. typedef float vl_mser_acc ;
  98. /** @internal @brief Basic region flag: null region */
  99. #ifdef VL_COMPILER_MSC
  100. #define VL_MSER_VOID_NODE ((1ui64<<32) - 1)
  101. #else
  102. #define VL_MSER_VOID_NODE ((1ULL<<32) - 1)
  103. #endif
  104. /* ----------------------------------------------------------------- */
  105. /** @internal
  106. ** @brief MSER: basic region (declaration)
  107. **
  108. ** Extremal regions and maximally stable extremal regions are
  109. ** instances of image regions.
  110. **
  111. ** There is an image region for each pixel of the image. Each region
  112. ** is represented by an instance of this structure. Regions are
  113. ** stored into an array in pixel order.
  114. **
  115. ** Regions are arranged into a forest. VlMserReg::parent points to
  116. ** the parent node, or to the node itself if the node is a root.
  117. ** VlMserReg::parent is the index of the node in the node array
  118. ** (which therefore is also the index of the corresponding
  119. ** pixel). VlMserReg::height is the distance of the fartest leaf. If
  120. ** the node itself is a leaf, then VlMserReg::height is zero.
  121. **
  122. ** VlMserReg::area is the area of the image region corresponding to
  123. ** this node.
  124. **
  125. ** VlMserReg::region is the extremal region identifier. Not all
  126. ** regions are extremal regions however; if the region is NOT
  127. ** extremal, this field is set to ....
  128. **/
  129. struct _VlMserReg
  130. {
  131. vl_uint parent ; /**< points to the parent region. */
  132. vl_uint shortcut ; /**< points to a region closer to a root. */
  133. vl_uint height ; /**< region height in the forest. */
  134. vl_uint area ; /**< area of the region. */
  135. } ;
  136. /** @internal @brief MSER: basic region */
  137. typedef struct _VlMserReg VlMserReg ;
  138. /* ----------------------------------------------------------------- */
  139. /** @internal
  140. ** @brief MSER: extremal region (declaration)
  141. **
  142. ** Extremal regions (ER) are extracted from the region forest. Each
  143. ** region is represented by an instance of this structure. The
  144. ** structures are stored into an array, in arbitrary order.
  145. **
  146. ** ER are arranged into a tree. @a parent points to the parent ER, or
  147. ** to itself if the ER is the root.
  148. **
  149. ** An instance of the structure represents the extremal region of the
  150. ** level set of intensity VlMserExtrReg::value and containing the
  151. ** pixel VlMserExtReg::index.
  152. **
  153. ** VlMserExtrReg::area is the area of the extremal region and
  154. ** VlMserExtrReg::area_top is the area of the extremal region
  155. ** containing this region in the level set of intensity
  156. ** VlMserExtrReg::area + @c delta.
  157. **
  158. ** VlMserExtrReg::variation is the relative area variation @c
  159. ** (area_top-area)/area.
  160. **
  161. ** VlMserExtrReg::max_stable is a flag signaling whether this extremal
  162. ** region is also maximally stable.
  163. **/
  164. struct _VlMserExtrReg
  165. {
  166. int parent ; /**< index of the parent region */
  167. int index ; /**< index of pivot pixel */
  168. vl_mser_pix value ; /**< value of pivot pixel */
  169. vl_uint shortcut ; /**< shortcut used when building a tree */
  170. vl_uint area ; /**< area of the region */
  171. float variation ; /**< rel. area variation */
  172. vl_uint max_stable ; /**< max stable number (=0 if not maxstable) */
  173. } ;
  174. /** @internal
  175. ** @brief MSER: extremal region */
  176. typedef struct _VlMserExtrReg VlMserExtrReg ;
  177. /* ----------------------------------------------------------------- */
  178. /** @internal
  179. ** @brief MSER filter
  180. ** @see @ref mser
  181. **/
  182. struct _VlMserFilt
  183. {
  184. /** @name Image data and meta data @internal */
  185. /*@{*/
  186. int ndims ; /**< number of dimensions */
  187. int *dims ; /**< dimensions */
  188. int nel ; /**< number of image elements (pixels) */
  189. int *subs ; /**< N-dimensional subscript */
  190. int *dsubs ; /**< another subscript */
  191. int *strides ; /**< strides to move in image data */
  192. /*@}*/
  193. vl_uint *perm ; /**< pixel ordering */
  194. vl_uint *joins ; /**< sequence of join ops */
  195. int njoins ; /**< number of join ops */
  196. /** @name Regions */
  197. /*@{*/
  198. VlMserReg *r ; /**< basic regions */
  199. VlMserExtrReg *er ; /**< extremal tree */
  200. vl_uint *mer ; /**< maximally stable extremal regions */
  201. int ner ; /**< number of extremal regions */
  202. int nmer ; /**< number of maximally stable extr. reg. */
  203. int rer ; /**< size of er buffer */
  204. int rmer ; /**< size of mer buffer */
  205. /*@}*/
  206. /** @name Ellipsoids fitting */
  207. /*@{*/
  208. float *acc ; /**< moment accumulator. */
  209. float *ell ; /**< ellipsoids list. */
  210. int rell ; /**< size of ell buffer */
  211. int nell ; /**< number of ellipsoids extracted */
  212. int dof ; /**< number of dof of ellipsoids. */
  213. /*@}*/
  214. /** @name Configuration */
  215. /*@{*/
  216. vl_bool verbose ; /**< be verbose */
  217. int delta ; /**< delta filter parameter */
  218. double max_area ; /**< badness test parameter */
  219. double min_area ; /**< badness test parameter */
  220. double max_variation ; /**< badness test parameter */
  221. double min_diversity ; /**< minimum diversity */
  222. /*@}*/
  223. VlMserStats stats ; /** run statistic */
  224. } ;
  225. /* ----------------------------------------------------------------- */
  226. /** @brief Get delta
  227. ** @param f MSER filter.
  228. ** @return value of @c delta.
  229. **/
  230. VL_INLINE vl_mser_pix
  231. vl_mser_get_delta (VlMserFilt const *f)
  232. {
  233. return f-> delta ;
  234. }
  235. /** @brief Set delta
  236. ** @param f MSER filter.
  237. ** @param x value of @c delta.
  238. **/
  239. VL_INLINE void
  240. vl_mser_set_delta (VlMserFilt *f, vl_mser_pix x)
  241. {
  242. f-> delta = x ;
  243. }
  244. /* ----------------------------------------------------------------- */
  245. /** @brief Get minimum diversity
  246. ** @param f MSER filter.
  247. ** @return value of @c minimum diversity.
  248. **/
  249. VL_INLINE double
  250. vl_mser_get_min_diversity (VlMserFilt const *f)
  251. {
  252. return f-> min_diversity ;
  253. }
  254. /** @brief Set minimum diversity
  255. ** @param f MSER filter.
  256. ** @param x value of @c minimum diversity.
  257. **/
  258. VL_INLINE void
  259. vl_mser_set_min_diversity (VlMserFilt *f, double x)
  260. {
  261. f-> min_diversity = x ;
  262. }
  263. /* ----------------------------------------------------------------- */
  264. /** @brief Get statistics
  265. ** @param f MSER filter.
  266. ** @return statistics.
  267. **/
  268. VL_INLINE VlMserStats const*
  269. vl_mser_get_stats (VlMserFilt const *f)
  270. {
  271. return & f-> stats ;
  272. }
  273. /* ----------------------------------------------------------------- */
  274. /** @brief Get maximum region area
  275. ** @param f MSER filter.
  276. ** @return maximum region area.
  277. **/
  278. VL_INLINE double
  279. vl_mser_get_max_area (VlMserFilt const *f)
  280. {
  281. return f-> max_area ;
  282. }
  283. /** @brief Set maximum region area
  284. ** @param f MSER filter.
  285. ** @param x maximum region area.
  286. **/
  287. VL_INLINE void
  288. vl_mser_set_max_area (VlMserFilt *f, double x)
  289. {
  290. f-> max_area = x ;
  291. }
  292. /* ----------------------------------------------------------------- */
  293. /** @brief Get minimum region area
  294. ** @param f MSER filter.
  295. ** @return minimum region area.
  296. **/
  297. VL_INLINE double
  298. vl_mser_get_min_area (VlMserFilt const *f)
  299. {
  300. return f-> min_area ;
  301. }
  302. /** @brief Set minimum region area
  303. ** @param f MSER filter.
  304. ** @param x minimum region area.
  305. **/
  306. VL_INLINE void
  307. vl_mser_set_min_area (VlMserFilt *f, double x)
  308. {
  309. f-> min_area = x ;
  310. }
  311. /* ----------------------------------------------------------------- */
  312. /** @brief Get maximum region variation
  313. ** @param f MSER filter.
  314. ** @return maximum region variation.
  315. **/
  316. VL_INLINE double
  317. vl_mser_get_max_variation (VlMserFilt const *f)
  318. {
  319. return f-> max_variation ;
  320. }
  321. /** @brief Set maximum region variation
  322. ** @param f MSER filter.
  323. ** @param x maximum region variation.
  324. **/
  325. VL_INLINE void
  326. vl_mser_set_max_variation (VlMserFilt *f, double x)
  327. {
  328. f-> max_variation = x ;
  329. }
  330. /* ----------------------------------------------------------------- */
  331. /** @brief Get maximally stable extremal regions
  332. ** @param f MSER filter.
  333. ** @return array of MSER pivots.
  334. **/
  335. VL_INLINE vl_uint const *
  336. vl_mser_get_regions (VlMserFilt const* f)
  337. {
  338. return f-> mer ;
  339. }
  340. /** @brief Get number of maximally stable extremal regions
  341. ** @param f MSER filter.
  342. ** @return number of MSERs.
  343. **/
  344. VL_INLINE vl_uint
  345. vl_mser_get_regions_num (VlMserFilt const* f)
  346. {
  347. return f-> nmer ;
  348. }
  349. /* ----------------------------------------------------------------- */
  350. /** @brief Get ellipsoids
  351. ** @param f MSER filter.
  352. ** @return ellipsoids.
  353. **/
  354. VL_INLINE float const *
  355. vl_mser_get_ell (VlMserFilt const* f)
  356. {
  357. return f-> ell ;
  358. }
  359. /** @brief Get number of degrees of freedom of ellipsoids
  360. ** @param f MSER filter.
  361. ** @return number of degrees of freedom.
  362. **/
  363. VL_INLINE vl_uint
  364. vl_mser_get_ell_dof (VlMserFilt const* f)
  365. {
  366. return f-> dof ;
  367. }
  368. /** @brief Get number of ellipsoids
  369. ** @param f MSER filter.
  370. ** @return number of ellipsoids
  371. **/
  372. VL_INLINE vl_uint
  373. vl_mser_get_ell_num (VlMserFilt const* f)
  374. {
  375. return f-> nell ;
  376. }
  377. /* VL_MSER */
  378. #endif