Main Content


Detect MSER features



regions = detectMSERFeatures(I) returns an MSERRegions object, regions, containing information about MSER features detected in the 2-D grayscale or binary input image, I. This object uses Maximally Stable Extremal Regions (MSER) algorithm to find regions.


For Simulink® support using this function, you must enable the model configuration settings. To display the dialog box, in the Simulink Editor, select the Modeling tab and then select Model Settings > Model Properties. In the Configuration Parameters dialog box, select Simulation Target > Advanced Parameters > Dynamic Memory allocation in MATLAB functions.

[regions,cc] = detectMSERFeatures(I)optionally returns MSER regions in a connected component structure.

[___] = detectMSERFeatures(I,Name,Value) sets additional options specified by one or more name-value arguments.


collapse all

Read image and detect MSER regions.

I = imread('cameraman.tif');
regions = detectMSERFeatures(I);

Visualize MSER regions which are described by pixel lists stored inside the returned 'regions' object.

figure; imshow(I); hold on;

Display ellipses and centroids fit into the regions. By default, plot displays ellipses and centroids.

figure; imshow(I); 
hold on;

Detect MSER regions.

I = imread('coins.png');
[regions,mserCC] = detectMSERFeatures(I);

Show all detected MSER Regions.

hold on

Measure the MSER region eccentricity to gauge region circularity.

stats = regionprops('table',mserCC,'Eccentricity');

Threshold eccentricity values to only keep the circular regions. (Circular regions have low eccentricity.)

eccentricityIdx = stats.Eccentricity < 0.55;
circularRegions = regions(eccentricityIdx);

Show the circular regions.

hold on

Input Arguments

collapse all

Input image, specified as an M-by-N 2-D grayscale or binary image. It must be real and nonsparse. The function internally converts input images to uint8 that are not uint8 before looking for MSER regions.

Data Types: uint8 | int16 | uint16 | single | double | logical

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'RegionAreaRange',[30 14000], specifies the size of the region in pixels.

Step size between intensity threshold levels, specified as the comma-separated pair consisting of 'ThresholdDelta' and a numeric value in the range (0,100]. This value is expressed as a percentage of the input data type range used in selecting extremal regions while testing for their stability. Decrease this value to return more regions. Typical values range from 0.8 to 4.

Size of the region in pixels, specified as the comma-separated pair consisting of 'RegionAreaRange' and a two-element vector. The vector, [minArea maxArea], allows the selection of regions containing pixels to be between minArea and maxArea, inclusive.

Maximum area variation between extremal regions at varying intensity thresholds, specified as the comma-separated pair consisting of 'MaxAreaVariation' and a positive scalar value. Increasing this value returns a greater number of regions, but they may be less stable. Stable regions are very similar in size over varying intensity thresholds. Typical values range from 0.1 to 1.0.

Rectangular region of interest, specified as a vector. The vector must be in the format [x y width height]. When you specify an ROI, the function detects corners within the area located at [x y] of size specified by [width height]. The [x y] elements specify the upper left corner of the region.

Output Arguments

collapse all

MSER regions object, returned as a MSERRegions object. The object contains information about MSER features detected in the grayscale or binary input image.

Connected component structure, returned as a structure with four fields. The connected component structure is useful for measuring region properties by using the regionprops function. You can also use the properties input of the regionprops function that provides shape measurements.

The four fields returned in cc are:


Connectivity of the MSER regions.

Default: 8


Size of I.


Number of MSER regions in I.


1-by-NumObjects cell array containing NumObjects vectors. Each vector represents the linear indices of the pixels in the element’s corresponding MSER region.


collapse all

Intensity Threshold Levels

The MSER detector incrementally steps through the intensity range of the input image to detect stable regions. The ThresholdDelta parameter determines the number of increments the detector tests for stability. You can think of the threshold delta value as the size of a cup to fill a bucket with water. The smaller the cup, the more number of increments it takes to fill up the bucket. The bucket can be thought of as the intensity profile of the region.

The MSER object checks the variation of the region area size between different intensity thresholds. The variation must be less than the value of the MaxAreaVariation parameter to be considered stable.


MSER feature detection is not suitable for use in images with extreme intensity value changes.

At a high level, MSER can be explained, by thinking of the intensity profile of an image representing a series of buckets. Imagine the tops of the buckets flush with the ground, and a hose turned on at one of the buckets. As the water fills into the bucket, it overflows and the next bucket starts filling up. Smaller regions of water join and become bigger bodies of water, and finally the whole area gets filled. As water is filling up into a bucket, it is checked against the MSER stability criterion. Regions appear, grow and merge at different intensity thresholds.


[1] Nister, D., and H. Stewenius, "Linear Time Maximally Stable Extremal Regions", Lecture Notes in Computer Science. 10th European Conference on Computer Vision, Marseille, France: 2008, no. 5303, pp. 183–196.

[2] Matas, J., O. Chum, M. Urba, and T. Pajdla. "Robust wide baseline stereo from maximally stable extremal regions." Proceedings of British Machine Vision Conference, pages 384-396, 2002.

[3] Obdrzalek D., S. Basovnik, L. Mach, and A. Mikulik. "Detecting Scene Elements Using Maximally Stable Colour Regions," Communications in Computer and Information Science, La Ferte-Bernard, France; 2009, vol. 82 CCIS (2010 12 01), pp 107–115.

[4] Mikolajczyk, K., T. Tuytelaars, C. Schmid, A. Zisserman, T. Kadir, and L. Van Gool, "A Comparison of Affine Region Detectors"; International Journal of Computer Vision, Volume 65, Numbers 1–2 / November, 2005, pp 43–72.

Extended Capabilities

Version History

Introduced in R2012a