Deriche¶
| Fact | Value |
|---|---|
| Also called | Deriche edge detector, Deriche gradient, Recursive optimal edge detector |
| Status | Implemented and tested |
| Family | Edge detection and boundary analysis |
| Engine | Science engine |
| Type | Linear, spatial, recursive derivative filter |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/deriche.py, deriche |
| Operator code | engine/src/pixelnexus_engine/filters/deriche.py, deriche_representation |
| Packages | OpenCV |
Overview¶
The Deriche operator finds the gradient of the image with the derivative filter that Deriche derived from Canny's criteria, for a filter of infinite length. It runs as a recursive filter, a pass forward and a pass backward along each row and column. So its cost stays the same however much it smooths. The filter runs in the PixelNexus engine, with OpenCV.
How it works¶
- Take the luma, rounded to 8 bits.
- Filter along x with the derivative and along y with the smoothing filter, both recursive.
- Do the same with the roles swapped.
- Combine the two into the magnitude, or show one of them.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(f\): The derivative filter
- \(\alpha\): How fast the filter decays
- \(\omega\): The frequency of the sine
- \(c\): A scale factor
Canny asked for an edge filter with good detection, good localization and one response per edge. Deriche solved these criteria for a filter of infinite length and found f, a sine under an exponential envelope. Because it is a sum of exponentials, it runs as a recursive filter, two passes along each row or column, in time that does not depend on alpha. The derivative along x is paired with Deriche's smoothing filter along y, and the other way around. At alpha 1 and above, OpenCV's scaling makes a step of h levels peak at h.
Canny's optimal edge filter has no closed form, and his practical choice was the derivative of a Gaussian. Deriche dropped the limit on the filter's length and found an exact optimum, a sine under an exponential envelope. As omega goes to 0, it tends to x times the exponential. A sum of exponentials can be computed by a recursion with a few terms, which is what makes it fast.
Kernel or operator¶
There is no finite kernel. The filter is recursive. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Magnitude | Magnitude, Horizontal change (Gx), Vertical change (Gy) | The gradient magnitude in levels, or one signed component, shown as 128 plus half its value. |
Sharpness alpha alpha |
1 | 0.1 to 5 | The alpha of the filter, how fast it decays. Our choice of 1. |
Omega omega |
0.1 | 0.01 to 1 | The omega of the filter, the frequency of its sine. Our choice of 0.1, a small value, which brings the filter close to Deriche's limit x e^(-alpha |
Implementation¶
deriche in engine/src/pixelnexus_engine/filters/deriche.py rounds the luma to 8 bits and calls cv2.ximgproc.GradientDericheX and GradientDericheY. The magnitude is shown in levels, clipped at 255, without a stretch, so the brightness of an edge tells its height.
Worked example¶
| Alpha | Peak on a step of 150 | Mean magnitude on noise |
|---|---|---|
| 0.25 | 184 | 1.12 |
| 0.5 | 168 | 1.91 |
| 1 | 150 | 3.80 |
| 2 | 150 | 7.88 |
| 4 | 150 | 14.46 |
With omega 0.1. The step goes from 50 to 200. The noise is a flat gray of 128 with Gaussian noise of sigma 10, measured in the middle 100 x 100 pixels.
Halving alpha roughly halves the response to noise, from 14.46 at alpha 4 to 1.12 at alpha 0.25, at the same cost. At alpha 1 and above, the step of 150 levels peaks at exactly 150. At smaller alpha it peaks higher, 184 at alpha 0.25. The filter is then wider than the 20 pixels on each side of the step. We did not trace how OpenCV's scaling and its start at the image edge add up there.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels, at any alpha.
Artifacts and limitations¶
Limitations
- Recursive filters can ring slightly on strong steps.
- Only the gradient. Thinning and thresholds are left to other filters.
Artifacts
- Wide edges at small alpha.
Tests¶
The gradients must equal OpenCV's own calls on the luma. A step of 150 must peak at 150 at the default alpha, and the signed output must show 128 plus half the gradient. On a large noisy flat image, a smaller alpha must give a smaller response. The representation must have its three stages.
References¶
- Deriche, R. Using Canny's criteria to derive a recursively implemented optimal edge detector. International Journal of Computer Vision 1(2), 167 to 187, 1987. DOI 10.1007/BF00123164.
- OpenCV documentation, cv::ximgproc::GradientDericheX.