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