Skip to content

Frei-Chen

Fact Value
Also called Frei-Chen edge detector
Status Implemented and tested
Family Edge detection and boundary analysis
Engine Browser
Type Nonlinear, spatial, subspace projection
Output Image
Operator shown as fixed-kernel (exact)
Support radius 1
Code web/src/core/filters/edges/compass.ts, freiChenFilter
Operator code web/src/core/filters/edges/compass.ts, FREI_CHEN
Channels Brightness only, RGB

Overview

The Frei-Chen operator splits each 3x3 window into nine standard patterns: four edges, four lines and the mean. It reports how much of the window, as a share, looks like an edge or like a line. Because it is a share, a faint edge and a strong edge of the same shape give the same result.

Three panels: disks, the Frei-Chen edge subspace output with bright rings at the disk borders, and the line subspace output with bright thin dots. Three panels: disks, the Frei-Chen edge subspace output with bright rings at the disk borders, and the line subspace output with bright thin dots.
The edge subspace lights up on the disk borders, the line subspace on the thin dots.

How it works

  1. Correlate the window with the nine orthonormal masks.
  2. Add up the squared responses of the edge masks, or of the line masks.
  3. Divide by the sum of all nine and take the square root.

Mathematical foundation

\[ \cos\theta = \sqrt{\frac{\sum_{k \in S} (F_k \star I)^2}{\sum_{k=1}^{9} (F_k \star I)^2}}, \qquad S = \{1,2,3,4\} \text{ or } \{5,6,7,8\} \]

The formula shows the default parameter values.

where

  • \(F_k\): The nine orthonormal masks
  • \(S\): The edge or the line subspace

The nine Frei-Chen masks are an orthonormal basis of 3x3 windows: four span edges, four span lines and one is the mean. The squared projections add up to the energy of the window. The ratio of the edge or line energy to the total is the squared cosine of the angle between the window and that subspace. The output is 255 times the cosine, so a pure edge or line gives 255.

The nine masks are an orthonormal basis of 3x3 windows, so the squared responses add up to the energy of the window. The ratio of the edge energy to the total is the squared cosine of the angle between the window, seen as a 9-dimensional vector, and the edge subspace. The output is 255 times that cosine. In flat areas the energy is tiny, so small noise patterns can still give a large share.

Kernel or operator

The Inspector shows the nine masks, read from the code. The worked example below projects one window.

Algorithm

  1. Pad the image with the border mode.
  2. Correlate with the nine masks.
  3. Add the squared responses of the chosen subspace and of all nine.
  4. Write 255 times the square root of their ratio.

Parameters

Parameter Default Values Meaning
Output output Edge subspace Edge subspace, Line subspace Which part of the window to measure.
Output mapping outputMapping Clip to 0 to 255 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

freiChenFilter in web/src/core/filters/edges/compass.ts correlates with the nine masks and forms the ratio. A window with no energy gives 0. 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

\[ W = \begin{bmatrix} 20 & 20 & 200 \\ 20 & 20 & 200 \\ 20 & 20 & 200 \end{bmatrix} \]

The window is a vertical step. The filter gives 160.7 for the edge output, 255 times the cosine of the angle to the edge subspace, and 92.8 for the line output. The mean mask holds the rest of the energy, 47 percent, because the window is bright on average. Of the energy outside the mean, the edge subspace holds 75 percent.

Complexity

  • Time: \(O(N)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel. Nine 3x3 correlations per pixel.

Artifacts and limitations

Limitations

  • Flat areas with tiny noise can look like perfect edges, because only the shape counts.
  • The output mapping must not stretch it, or the noise grows.

Artifacts

  • Bright noise in flat areas, where the window energy is small.

Tests

The reference projects onto the same nine masks. Before it is used, the script checks that the masks are orthonormal. The test covers both outputs for all five border modes.

References

  • Frei, W. and Chen, C.-C. Fast boundary detection, a generalization and a new algorithm. IEEE Transactions on Computers C-26(10), 988 to 998, 1977. DOI 10.1109/TC.1977.1674733.