MSER region detector¶
| Fact | Value |
|---|---|
| Also called | Maximally stable extremal regions, MSER |
| Status | Implemented and tested |
| Family | Texture, corners, blobs and features |
| Engine | Science engine |
| Type | Nonlinear, spatial, maximally stable extremal regions |
| Output | Features |
| Operator shown as | algorithm (definition) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/mser.py, mser |
| Operator code | engine/src/pixelnexus_engine/filters/mser.py, mser_representation |
| Packages | OpenCV |
Overview¶
MSER finds maximally stable extremal regions. These are blobs of any shape that are brighter or darker than everything around them, and whose area hardly changes as a threshold moves through the gray levels. Text characters, signs and spots are typical examples. Each region is listed with its centroid, the radius of a disk of the same area, its long axis and its area. The regions go to the Features panel and are drawn on the canvas. The filter runs in the PixelNexus engine, with OpenCV.
How it works¶
- Take the 8-bit luma.
- Sweep the threshold and follow how the connected regions grow, in both directions.
- Keep the regions whose area changes least, within the area and variation limits.
- Report each region's centroid, equal-area radius, long axis, area and axis ratio.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(Q_t\): An extremal region at threshold t
- \(v\): The variation, the relative change of the area
- \(\Delta\): Delta, the range of gray levels
Picture the threshold t sweeping the gray levels from black to white. The pixels at or below t form connected regions, which appear, grow and merge. Each one is an extremal region, since all its pixels are darker than every pixel on its border. Matas et al. measure how fast its area changes with v. A region where v has a local minimum is maximally stable: it keeps its shape while the threshold moves. Sweeping the other way gives the bright regions, and OpenCV finds both in one run. Regions outside the area limits, or with v above the most variation, are dropped. Of nested regions that are nearly the same, only one stays. The table gives each region's centroid, the radius of a disk of the same area, and its long axis from the second moments of its pixels.
Threshold the image at a gray level t. The pixels at or below t form connected regions. As t rises, new regions appear, grow and merge, until one region covers the image. Each of these regions is extremal: every pixel inside it is darker than every pixel on its border. All of them together form a tree, the component tree of the image.
Matas and coworkers keep the regions whose area changes least as t moves by delta. A region with a local minimum of the variation v is maximally stable. Such regions have clear borders, so they come back in other views of the same scene. Sweeping t the other way gives the bright regions, and OpenCV finds both in one run. Changing the brightness in a way that keeps the order of the gray levels does not change the tree.
OpenCV adds limits on the area and the variation, and prunes nested regions that are nearly the same. On images with perfectly flat shapes, such as the Disks test image, OpenCV finds no region at all. The worked example shows that a slight blur brings them back.
Kernel or operator¶
The Inspector asks the engine for the stages with the current settings. They are the extremal regions, the stability measure with delta, the limits, and the summary of each region in the table.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Delta delta |
5 | 1 to 50 levels | The range of gray levels over which the area of a region is compared. OpenCV uses 5. |
Smallest area minArea |
60 | 1 to 100000 px | Smaller regions are dropped. OpenCV uses 60. |
Largest area maxArea |
14400 | 10 to 1e+06 px | Larger regions are dropped. OpenCV uses 14400. If it is below the smallest area, the smallest is used. |
Most variation maxVariation |
0.25 | 0.01 to 1 | The largest relative change of the area a stable region may have. OpenCV uses 0.25. |
Least diversity minDiversity |
0.2 | 0 to 1 | Of nested regions whose areas differ by less than this share, only one stays. OpenCV uses 0.2. |
Implementation¶
mser in engine/src/pixelnexus_engine/filters/mser.py calls cv2.MSER_create with the catalog values and detectRegions on the 8-bit luma. For each region, region_row finds the centroid of its pixels, the radius sqrt(area / pi), and the long axis from the second moments of the pixels. The angle counts counterclockwise from the x axis, from 0 to 180 degrees, since an axis has no direction. The axis ratio is the square root of the ratio of the two moments along the axes. The rows are sorted by area, largest first. The pixels of the regions are not kept.
Worked example¶
| Blur sigma (px) | Regions | Areas (px) |
|---|---|---|
| 0 | 0 | none |
| 1 | 1 | 300 |
| 2 | 1 | 1176 |
| 3 | 4 | 2820, 2584, 300, 172 |
| 5 | 8 | 1108, 300, 248, 232, 208, 164, 124, 124 |
The Disks test image at 512 x 512 with the defaults, after a Gaussian blur of growing sigma, rounded to 8 bits. Its disks have areas of about 113 to 16300 pixels, and the largest area allowed is 14400. On the image as it is, OpenCV finds no region. After a blur it finds some, and how many depends on the blur.
Complexity¶
- Time: \(O(N log log N)\)
- Memory: \(O(N)\)
N is the number of pixels, as Matas et al. give it for their algorithm.
Artifacts and limitations¶
Limitations
- On images whose shapes are perfectly flat, OpenCV finds no region at all. The Disks test image gives none, and after a blur of sigma 3 it gives 4.
- The table holds a summary of each region, not its pixels.
Artifacts
- Nested regions of the same object at different thresholds.
Tests¶
The detector must have the OpenCV defaults. For an ellipse with its long axis at 30 degrees, a row must give the centroid, the area, the equal-area radius, the angle of 30 degrees and the axis ratio. The table must hold what OpenCV finds on the blurred Disks image, 4 regions, sorted by area. The flat Disks image must give no region. The negated image must give the same table. The engine API tests check the JSON and the stages.
References¶
- Matas, J., Chum, O., Urban, M., and Pajdla, T. Robust wide-baseline stereo from maximally stable extremal regions. Image and Vision Computing 22(10), 761 to 767, 2004. DOI 10.1016/j.imavis.2004.02.006.
- OpenCV documentation, cv2.MSER_create and detectRegions.