mser.h File Reference


Detailed Description

Maximally Stable Extremal Regions Overview

Running the MSER filter usually involves the following steps:

MSER definition

An extremal region $R_l$ of an image is a connected component of the level set $S_l = \{ x : I(x) \leq l \}$.

mser-er.png

For each intensity $l$, one has multiple disjoint extremal regions in the level set $S_l$. Let $l$ span a finite number of values $\mathcal{L}=\{0,\dots,M-1\}$ (a sampling of the image range). One obtains a family of regions $R_l$; by connecting two regions $R_l$and $R_{l+1}$ if, and only if, $R_l\subset R_{l+1}$, regions form a tree:

mser-tree.png

The maximally stable extremal regions are extremal regions which satisfy a stability criterion. Here we use a criterion which is similar but not identical to the original paper. This definition is somewhat simpler both to understand and code (it also runs faster).

Let $B(R_l)=(R_l,R_{l+1},\dots,R_{l+\Delta})$ be the branch of the tree rooted at $R_l$. We associate to the branch the (in)stability score

\[ v(R_l) = \frac{|R_{l+\Delta} - R_l|}{|R_l|}. \]

The score is low if the regions along the branch have similar area (and thus similar shape). We aim to select maximally stable branches; then a maximally stable region is just a representative region selected from a maximally stable branch (for simplicity we select $R_l$, but one could choose for example $R_{l+\Delta/2}$).

Roughly speaking, a branch is maximally stable if it is a local minimum of the (in)stability score. More accurately, we start by assuming that all branches are maximally stable. Then we consider each branch $B(R_{l})$ and its parent branch $B(R_{l+1}):R_{l+1}\supset R_l$ (notice that, due to the discrete nature of the calculations, they might be geometrically identical) and we mark as unstable the less stable one, i.e.:

  • if $v(R_l)<v(R_{l+1})$, mark $R_{l+1}$ as unstable;
  • if $v(R_l)>v(R_{l+1})$, mark $R_{l}$ as unstable;
  • otherwise, do nothing.

This criterion selects among nearby regions the ones that are more stable. We optionally refine the selection by running (starting from the bigger and going to the smaller regions) the following tests:

  • $a_- \leq |R_{l}|/|R_{\infty}| \leq a_+$: exclude MSERs too small or too big ($|R_{\infty}|$ is the area of the image).

  • $v(R_{l}) < v_+$: exclude MSERs too unstable.

  • For any MSER $R_l$, find the parent MSER $R_{l'}$ and check if $|R_{l'} - R_l|/|R_l'| < d_+$: remove duplicated MSERs.

parameter alt. name standard value set by
$\Delta$ delta 5 vl_mser_set_delta()
$a_+$ max_area 0.75 vl_mser_set_max_area()
$a_-$ min_area 3.0/$|R_\infty|$ vl_mser_set_min_area()
$v_+$ max_var 0.25 vl_mser_set_max_variation()
$d_+$ min_diversity 0.2 vl_mser_set_min_diversity()

Volumetric images

The code supports images of arbitrary dimension. For instance, it is possible to find the MSER regions of volumetric images or time sequences. See vl_mser_new() for further details.s

Ellipsoids

Usually extremal regions are returned as a set of ellipsoids fitted to the actual regions (which have arbitrary shape). The fit is done by calculating the mean and variance of the pixels composing the region:

\[ \mu_l = \frac{1}{|R_l|}\sum_{x\in R_l}x, \qquad \Sigma_l = \frac{1}{|R_l|}\sum_{x\in R_l} (x-\mu_l)^\top(x-\mu_l) \]

Ellipsoids are fitted by vl_mser_ell_fit(). Notice that for a n dimensional image, the mean has n components and the variance has n(n+1)/2 independent components. The total number of components is obtained by vl_mser_get_ell_dof() and the total number of fitted ellipsoids by vl_mser_get_ell_num(). A matrix with an ellipsoid per column is returned by vl_mser_get_ell(). The column is the stacking of the mean and of the independent components of the variance, in the order (1,1),(1,2),..,(1,n), (2,2),(2,3).... In the calculations, the pixel coordinate $x=(x_1,...,x_n)$ use the standard index order and ranges.

Algorithm

The algorithm is quite efficient. While some details may be tricky, the overall idea is easy to grasp.

  • Pixels are sorted by increasing intensity.
  • Pixels are added to a forest by increasing intensity. The forest has the following properties:
    • All the descendent of a certain pixels are subset of an extremal region.
    • All the extremal regions are the descendants of some pixels.
  • Extremal regions are extracted from the region tree and the extremal regions tree is calculated.
  • Stable regions are marked.
  • Duplicates and other bad regions are removed.

Remarks:
The extremal region tree which is calculated is a subset of the actual extremal region tree. In particular, it does not contain redundant entries extremal regions that coincide as sets. So, for example, in the calculated extremal region tree, the parent $R_q$ of an extremal region $R_{l}$ may or may not correspond to $R_{l+1}$, depending whether $q\leq l+1$ or not. These subtleties are important when calculating the stability tests.
Author:
Andrea Vedaldi

Definition in file mser.h.

#include "generic.h"

Go to the source code of this file.


Data Structures

struct  _VlMserStats
 MSER filter statistics definition. More...
struct  _VlMserReg
 MSER: basic region (declaration). More...
struct  _VlMserExtrReg
 MSER: extremal region (declaration). More...
struct  _VlMserFilt
 MSER filter. More...

Defines

#define VL_MSER_PIX_MAXVAL   256
 Maximum value.
#define VL_MSER_VOID_NODE   ((1ui64<<32) - 1)
 Basic region flag: null region.

Typedefs

typedef vl_uint8 vl_mser_pix
 MSER image data type.
typedef struct _VlMserFilt VlMserFilt
 MSER Filter.
typedef struct _VlMserStats VlMserStats
 MSER filter statistics.
typedef float vl_mser_acc
 MSER accumulator data type.
typedef struct _VlMserReg VlMserReg
 MSER: basic region.
typedef struct _VlMserExtrReg VlMserExtrReg
 MSER: extremal region.

Functions

Construction and Destruction
VL_EXPORT VlMserFiltvl_mser_new (int ndims, int const *dims)
 Create a new MSER filter.
VL_EXPORT void vl_mser_delete (VlMserFilt *f)
 Delete MSER filter.
Processing
VL_EXPORT void vl_mser_process (VlMserFilt *f, vl_mser_pix const *im)
 Process image.
VL_EXPORT void vl_mser_ell_fit (VlMserFilt *f)
 Fit ellipsoids.
Retrieving data
VL_INLINE vl_uint vl_mser_get_regions_num (VlMserFilt const *f)
 Get number of maximally stable extremal regions.
VL_INLINE vl_uint const * vl_mser_get_regions (VlMserFilt const *f)
 Get maximally stable extremal regions.
VL_INLINE float const * vl_mser_get_ell (VlMserFilt const *f)
 Get ellipsoids.
VL_INLINE vl_uint vl_mser_get_ell_num (VlMserFilt const *f)
 Get number of ellipsoids.
VL_INLINE vl_uint vl_mser_get_ell_dof (VlMserFilt const *f)
 Get number of degrees of freedom of ellipsoids.
VL_INLINE VlMserStats const * vl_mser_get_stats (VlMserFilt const *f)
 Get statistics.
Retrieving parameters
VL_INLINE vl_mser_pix vl_mser_get_delta (VlMserFilt const *f)
 Get delta.
VL_INLINE double vl_mser_get_min_area (VlMserFilt const *f)
 Get minimum region area.
VL_INLINE double vl_mser_get_max_area (VlMserFilt const *f)
 Get maximum region area.
VL_INLINE double vl_mser_get_max_variation (VlMserFilt const *f)
 Get maximum region variation.
VL_INLINE double vl_mser_get_min_diversity (VlMserFilt const *f)
 Get minimum diversity.
Setting parameters
VL_INLINE void vl_mser_set_delta (VlMserFilt *f, vl_mser_pix x)
 Set delta.
VL_INLINE void vl_mser_set_min_area (VlMserFilt *f, double x)
 Set minimum region area.
VL_INLINE void vl_mser_set_max_area (VlMserFilt *f, double x)
 Set maximum region area.
VL_INLINE void vl_mser_set_max_variation (VlMserFilt *f, double x)
 Set maximum region variation.
VL_INLINE void vl_mser_set_min_diversity (VlMserFilt *f, double x)
 Set minimum diversity.

Define Documentation

#define VL_MSER_PIX_MAXVAL   256

Maximum value of the integer type vl_mser_pix.

Definition at line 30 of file mser.h.

Referenced by vl_mser_process().

#define VL_MSER_VOID_NODE   ((1ui64<<32) - 1)

For internal use only.

Definition at line 119 of file mser.h.

Referenced by vl_mser_process().


Typedef Documentation

typedef float vl_mser_acc

For internal use only.

This is a large integer type. It should be large enough to contain a number equal to the area (volume) of the image by the image width by the image height (for instance, if the image is a square of side 256, the maximum value is 256 x 256 x 256).

Definition at line 115 of file mser.h.

This is the data type of the image pixels. It has to be an integer.

Definition at line 24 of file mser.h.

typedef struct _VlMserExtrReg VlMserExtrReg

For internal use only.

Definition at line 196 of file mser.h.

typedef struct _VlMserFilt VlMserFilt

The MSER filter computes the Maximally Stable Extremal Regions of an image.

This structure is opaque.

See also:
Maximally Stable Extremal Regions Overview

Definition at line 42 of file mser.h.

typedef struct _VlMserReg VlMserReg

For internal use only.

Definition at line 157 of file mser.h.


Function Documentation

VL_EXPORT void vl_mser_delete ( VlMserFilt f  ) 

The function releases the MSER filter f and all its resources.

Parameters:
f MSER filter to be deleted.

Definition at line 348 of file mser.c.

References vl_free().

VL_EXPORT void vl_mser_ell_fit ( VlMserFilt f  ) 

VL_INLINE vl_mser_pix vl_mser_get_delta ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
value of delta.

Definition at line 259 of file mser.h.

VL_INLINE float const * vl_mser_get_ell ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
ellipsoids.

Definition at line 396 of file mser.h.

VL_INLINE vl_uint vl_mser_get_ell_dof ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
number of degrees of freedom.

Definition at line 406 of file mser.h.

VL_INLINE vl_uint vl_mser_get_ell_num ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
number of ellipsoids

Definition at line 416 of file mser.h.

VL_INLINE double vl_mser_get_max_area ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
maximum region area.

Definition at line 312 of file mser.h.

VL_INLINE double vl_mser_get_max_variation ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
maximum region variation.

Definition at line 354 of file mser.h.

VL_INLINE double vl_mser_get_min_area ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
minimum region area.

Definition at line 333 of file mser.h.

VL_INLINE double vl_mser_get_min_diversity ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
value of minimum diversity.

Definition at line 280 of file mser.h.

VL_INLINE vl_uint const * vl_mser_get_regions ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
array of MSER pivots.

Definition at line 375 of file mser.h.

VL_INLINE vl_uint vl_mser_get_regions_num ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
number of MSERs.

Definition at line 385 of file mser.h.

VL_INLINE VlMserStats const * vl_mser_get_stats ( VlMserFilt const *  f  ) 

Parameters:
f MSER filter.
Returns:
statistics.

Definition at line 301 of file mser.h.

VL_EXPORT VlMserFilt* vl_mser_new ( int  ndims,
int const *  dims 
)

Initializes a new MSER filter for images of the specified dimensions. Images are ndims -dimensional arrays of dimensions dims.

Parameters:
ndims number of dimensions.
dims dimensions.

Definition at line 284 of file mser.c.

References vl_calloc(), and vl_malloc().

VL_EXPORT void vl_mser_process ( VlMserFilt f,
vl_mser_pix const *  im 
)

The functions calculates the Maximally Stable Extremal Regions (MSERs) of image im using the MSER filter f.

The filter f must have been initialized to be compatible with the dimensions of im.

Parameters:
f MSER filter.
im image data.

Definition at line 382 of file mser.c.

References _VlMserExtrReg::area, _VlMserReg::area, climb(), _VlMserFilt::er, _VlMserReg::height, _VlMserExtrReg::index, _VlMserExtrReg::max_stable, _VlMserFilt::mer, _VlMserExtrReg::parent, _VlMserReg::parent, _VlMserFilt::rer, _VlMserFilt::rmer, _VlMserExtrReg::shortcut, _VlMserReg::shortcut, _uMexOption::val, _VlMserExtrReg::value, _VlMserExtrReg::variation, vl_free(), vl_malloc(), VL_MAX, VL_MSER_PIX_MAXVAL, and VL_MSER_VOID_NODE.

VL_INLINE void vl_mser_set_delta ( VlMserFilt f,
vl_mser_pix  x 
)

Parameters:
f MSER filter.
x value of delta.

Definition at line 269 of file mser.h.

VL_INLINE void vl_mser_set_max_area ( VlMserFilt f,
double  x 
)

Parameters:
f MSER filter.
x maximum region area.

Definition at line 322 of file mser.h.

VL_INLINE void vl_mser_set_max_variation ( VlMserFilt f,
double  x 
)

Parameters:
f MSER filter.
x maximum region variation.

Definition at line 364 of file mser.h.

VL_INLINE void vl_mser_set_min_area ( VlMserFilt f,
double  x 
)

Parameters:
f MSER filter.
x minimum region area.

Definition at line 343 of file mser.h.

VL_INLINE void vl_mser_set_min_diversity ( VlMserFilt f,
double  x 
)

Parameters:
f MSER filter.
x value of minimum diversity.

Definition at line 290 of file mser.h.