Roberts Cross¶
| Fact | Value |
|---|---|
| Also called | Roberts |
| Status | Implemented and tested |
| Family | Edge detection and boundary analysis |
| Engine | Browser |
| Type | Linear, spatial, convolution |
| Output | Image |
| Operator shown as | fixed-kernel (exact) |
| Support radius | 1 |
| Code | web/src/core/filters/edges/gradients.ts, robertsFilter |
| Operator code | web/src/core/filters/edges/gradients.ts, GRADIENT_PAIRS |
| Channels | Brightness only, RGB |
Overview¶
The Roberts cross operator, from 1963, is one of the first edge detectors. It uses the two diagonal differences of a 2x2 block of pixels. It has no smoothing, so edges stay thin, but every noisy pixel shows up as an edge.
How it works¶
- Subtract the pixel below right from the pixel.
- Subtract the pixel below from the pixel to the right.
- Combine the two differences into a magnitude.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(R_1, R_2\): The two diagonal differences
The two differences along the diagonals of the 2x2 block that starts at the pixel. Roberts used them in 1963, one of the first edge operators. Here they run as 3x3 kernels with the pixel at the center. The direction output is the angle of (R_1, R_2), which is the gradient angle turned by 45 degrees.
The two differences are the gradient along the two diagonals. Their L2 combination is the gradient strength, as for the other operators. A 2x2 block has no center pixel, so the result belongs half a pixel down and to the right. Here the differences run as 3x3 kernels with the pixel at the center. scikit-image divides the magnitude by the square root of 2.
Kernel or operator¶
The Inspector shows the kernels that run, read from the same code. The Impulse response demo in the Learn panel shows how one bright pixel spreads through them.
Algorithm¶
- Pad the image with the border mode.
- Subtract the neighbor below right from each pixel, and the neighbor below from the neighbor to the right.
- Combine R_1 and R_2 into the chosen output.
- Map the result to 8 bits with the output mapping.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Magnitude | Magnitude, Falling diagonal (R1), Rising diagonal (R2), Direction | Which part of the gradient to show. |
Magnitude norm norm |
L2 (square root of the sum of squares) | L2 (square root of the sum of squares), L1 (sum of absolute values) | How the two derivatives are combined into the magnitude. |
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¶
robertsFilter in web/src/core/filters/edges/gradients.ts correlates with the two kernels and combines the results like the Sobel filter. The direction output is the angle of the pair, the gradient angle turned by 45 degrees. 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 border mode, the channel scope, alpha and the output mapping. By default it works on luma and gives a gray result.
Worked example¶
The window lies on a vertical edge, dark on the left and bright on the right.
| Output | Value |
|---|---|
| R1 | -180 |
| R2 | 180 |
| Magnitude (L2) | 254.56 |
R1 is the center 20 minus the pixel below right, 200, which is -180. R2 is the right neighbor 200 minus the pixel below, 20, which is 180.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel.
Artifacts and limitations¶
Limitations
- No smoothing at all, so it is very sensitive to noise.
- The result is shifted half a pixel, because the 2x2 block has no center pixel.
Artifacts
- Speckled responses on noisy images.
Tests¶
The reference correlates with the two kernels. Before it is used, the script checks the magnitude against skimage.filters.roberts. The test covers all outputs for all five border modes.
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Section 10.2, Roberts cross-gradient operators.
- scikit-image documentation, skimage.filters.roberts. https://scikit-image.org/docs/stable/api/skimage.filters.html#skimage.filters.roberts