Moravec corner detector¶
| Fact | Value |
|---|---|
| Also called | Moravec interest operator |
| Status | Implemented and tested |
| Family | Texture, corners, blobs and features |
| Engine | Browser |
| Type | Nonlinear, spatial, minimum of shifted differences |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | window + 1, plus the minimum distance for the corners output |
| Code | web/src/core/filters/features/corners.ts, moravecFilter |
| Operator code | web/src/core/filters/features/corners.ts, moravecResponse |
| Channels | Brightness only, RGB |
Overview¶
The Moravec detector is the oldest corner detector. It moves a small window by one pixel in four directions and measures how much the window changes. The smallest change is the response, which is large only where every move changes the window, at a corner. The filter shows the response at every pixel, or the corner points.
How it works¶
- Take a small window around each pixel.
- Move it one pixel right, down right, down and down left, and sum the squared differences for each move.
- Keep the smallest sum as the response.
- For corner points, keep the local maxima at or above the threshold.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(E_s\): The change of the window for the shift s
- \(w\): The window half width
The shifts s are (1, 0), (1, 1), (0, 1) and (-1, 1), the four directions that Harris and Stephens list for Moravec's operator. Values are on a 0 to 1 scale and w is the window half width. A flat area changes for no shift, an edge for some, and a corner for all, so the smallest change marks corners. The corners output keeps pixels whose response is at least the threshold and the largest within the minimum distance. Plateaus keep every pixel. skimage.feature.corner_moravec compares only the four diagonal shifts, so it gives other values.
In a flat area no move changes the window. Along an edge, a move along the edge changes nothing, so the smallest change is 0. At a corner every move changes the window. Moravec tested only four directions, which Harris and Stephens list as (1, 0), (1, 1), (0, 1) and (-1, 1). An edge that runs between these directions changes for all four moves, so it gives false corners. Harris and Stephens replaced the four moves with the structure tensor, which covers every direction.
Kernel or operator¶
There is no kernel. The Inspector lists the window sums for the four shifts and the minimum.
Algorithm¶
- Extend the image by the support with the border mode and scale it to 0 to 1.
- For each of the four shifts, sum the squared differences over the window.
- Keep the smallest sum as the response.
- For corner points, keep the local maxima at or above the threshold, and cut the extension off.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Window half width window |
1 | 1 to 5 px | The window is 2 times this plus 1 pixels wide. 1 gives a 3 x 3 window. |
Threshold threshold |
0.1 | 0 to 25 | The smallest response that counts as a corner. Values are on a 0 to 1 scale. |
Output output |
Moravec response | Moravec response, Corner points | The response at every pixel, or the corner points as white pixels. |
Minimum distance distance |
3 | 1 to 20 px | A corner must have the largest response within this many pixels in x and in y. |
Output mapping outputMapping |
Stretch to full range | Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 | How signed results, such as gradients, become 8-bit pixel values. |
Border mode border |
Reflect 101 (default) | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
moravecResponse in web/src/core/filters/features/corners.ts squares the differences for each shift and sums them over the window with running sums. The filter extends the plane once by the support with the border mode, so strips and whole images agree. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the channel scope, alpha and the output mapping. By default it works on luma.
Worked example¶
| Pixel | x | y | Response |
|---|---|---|---|
| Flat area | 3 | 3 | 0 |
| Edge | 10 | 17 | 0 |
| Corner | 10 | 10 | 0.6920 |
The same 21 x 21 image as for Harris, with a 3 x 3 window. Values are on a 0 to 1 scale. In the flat area no shift changes the window. On the vertical edge the shift (0, 1) moves the window along the edge and changes nothing, so the smallest change is 0. At the corner every shift changes the window, so the response is positive.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. Running sums make the window size free.
Artifacts and limitations¶
Limitations
- Not rotation invariant. Edges between the four directions give a high response.
- Noisy, because each shift is tested on its own.
Artifacts
- False corners along diagonal edges that fall between the tested directions.
Tests¶
The reference computes the same sums with NumPy and scipy.ndimage.uniform_filter. The library scikit-image tests only the four diagonal shifts. Before the cases are written, the script runs the reference with those shifts and checks it against skimage.feature.corner_moravec. This confirms the window rule. The cases cover two window sizes and both outputs for all five border modes.
References¶
- Moravec, H. P. Obstacle avoidance and navigation in the real world by a seeing robot rover. PhD thesis, Stanford University, 1980.
- Harris, C. and Stephens, M. A combined corner and edge detector. Proceedings of the Alvey Vision Conference, 23.1 to 23.6, 1988. It describes Moravec's operator and its four shifts. DOI 10.5244/C.2.23.