Farid-Simoncelli derivative filter¶
| Fact | Value |
|---|---|
| Also called | Farid filter |
| Status | Implemented and tested |
| Family | Edge detection and boundary analysis |
| Engine | Browser |
| Type | Linear, spatial, separable convolution |
| Output | Image |
| Operator shown as | fixed-kernel (exact) |
| Support radius | 2 |
| Code | web/src/core/filters/edges/gradients.ts, faridFilter |
| Operator code | web/src/core/filters/edges/gradients.ts, FARID_DERIVATIVE |
| Channels | Brightness only, RGB |
Overview¶
The Farid-Simoncelli filter estimates the gradient with a 5-tap derivative and a 5-tap prefilter that were designed together. The derivative is as close as possible to the true derivative of the prefilter, so the gradient direction is accurate for edges at any angle.
How it works¶
- Smooth along the edge with the 5-tap prefilter.
- Take the 5-tap derivative across the edge.
- Combine the two directions into the magnitude or the direction.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(d\): The 5-tap derivative, about -0.110, -0.277, 0, 0.277, 0.110
- \(p\): The 5-tap prefilter, about 0.038, 0.249, 0.426, 0.249, 0.038
d is a 5-tap derivative and p a 5-tap prefilter, a smoothing. Farid and Simoncelli optimized them together, so that d is the derivative of p as closely as possible. That makes the gradient direction accurate in every direction. The taps are those of skimage.filters.farid.
Farid and Simoncelli observe that a discrete derivative is only meaningful together with an interpolation: the derivative of a smooth function that fits the samples. They choose the prefilter p and the derivative d together, to minimize the error between d and the derivative of p in the frequency domain, weighted for rotation invariance. The taps here are those of skimage.filters.farid.
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.
- Correlate with d along x and p along y for G_x, and the reverse for G_y.
- Combine G_x and G_y into the chosen output.
- Map the result to 8 bits with the output mapping.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Magnitude | Magnitude, Horizontal change (Fx), Vertical change (Fy), 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¶
faridFilter in web/src/core/filters/edges/gradients.ts runs each kernel as two 1D passes of 5 taps and combines the results like the Sobel filter. 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 |
|---|---|
| Gx | 49.80 |
| Gy | 0 |
| Magnitude (L2) | 49.80 |
Only the 3x3 middle of the 5x5 kernels is shown here. The filter reads a 5x5 window, which repeats the edge pattern by the reflect 101 border on this small example.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. Each kernel runs as two passes of 5 taps.
Artifacts and limitations¶
Limitations
- A 5x5 support blurs fine detail more than 3x3 kernels.
- The taps are not whole numbers.
Artifacts
- Slightly wider edge responses than 3x3 kernels.
Tests¶
The reference correlates with the two kernels. Before it is used, the script checks the magnitude against skimage.filters.farid, which divides by the square root of 2. The test covers the magnitudes and both derivatives for all five border modes. The direction is left out of the test. The taps are not whole numbers, so tiny values near 0 give angles near 180 or -180 degrees that depend on rounding.
References¶
- Farid, H. and Simoncelli, E. P. Differentiation of discrete multidimensional signals. IEEE Transactions on Image Processing 13(4), 496 to 508, 2004. DOI 10.1109/TIP.2004.823819.
- scikit-image documentation, skimage.filters.farid. https://scikit-image.org/docs/stable/api/skimage.filters.html#skimage.filters.farid