Skip to content

Shen-Castan

Fact Value
Also called ISEF edge detector, Infinite symmetric exponential filter, Shen-Castan edge detector
Status Implemented and tested
Family Edge detection and boundary analysis
Engine Science engine
Type Nonlinear, spatial, edge detection
Output Image
Operator shown as algorithm (simplified)
Support radius global
Code engine/src/pixelnexus_engine/filters/shen_castan.py, shen_castan
Operator code engine/src/pixelnexus_engine/filters/shen_castan.py, shen_castan_representation
Packages SciPy, scikit-image

Overview

The Shen-Castan detector smooths the image with the infinite symmetric exponential filter (ISEF). Shen and Castan showed this filter is optimal for step edges under their criteria. Edges are then found where the smoothed image crosses the original. The ISEF runs as a recursion, a pass forward and a pass backward along each row and column, so its cost stays the same at any amount of smoothing. The filter runs in the PixelNexus engine.

Four panels. A noisy bright disk and gray square on a dark ground. The binary Laplacian is white and black speckle on the flat areas, with a solid white ring just outside each shape and a mostly black inside. With b 0.6, the edges trace both outlines with many short spurs. With b 0.8, the outlines are thin and clean, with a few stray dots. Four panels. A noisy bright disk and gray square on a dark ground. The binary Laplacian is white and black speckle on the flat areas, with a solid white ring just outside each shape and a mostly black inside. With b 0.6, the edges trace both outlines with many short spurs. With b 0.8, the outlines are thin and clean, with a few stray dots.
A disk and a square with noise of sigma 10. Then the binary Laplacian with b 0.8, and the edges with b 0.6 and 0.8.

How it works

  1. Take the luma.
  2. Smooth it with the ISEF, a forward and a backward recursion along each row and each column.
  3. Subtract the luma from the smoothed image, and mark the positive pixels.
  4. Take the marked pixels that have an unmarked 4-neighbor as zero crossings.
  5. Measure the gradient of the smoothed image at the zero crossings.
  6. Keep the edges with hysteresis between the low and the high threshold.

Mathematical foundation

\[ f(x, y) = \frac{1 - b}{1 + b}\, b^{\lvert x \rvert + \lvert y \rvert}, \qquad B = [\, f * Y - Y > 0 \,] \]

The formula shows the default parameter values.

where

  • \(f\): The ISEF kernel
  • \(b\): The smoothing factor, from 0 to 1
  • \(Y\): The luma of the image
  • \(B\): The binary Laplacian

f is the discrete ISEF. It sums to 1 and is separable, so it is applied along the rows and then the columns. Along each line, a forward recursion and a backward recursion, each with the factor b, add up to the kernel. The smoothed image minus the original approximates a Laplacian, limited to a band of frequencies. B is 1 where it is positive. Edges lie on the border of the regions where B is 1. We keep the border pixels where the gradient of the smoothed image passes the hysteresis thresholds.

The ISEF in one dimension is (1 - b) / (1 + b) times b to the power |n|. A forward recursion with the factor b gives the right half of this kernel, and a backward recursion gives the left half. Their sum counts the center twice, so the center is subtracted once. Each recursion costs two operations per pixel at any b.

The smoothed image minus the original acts as a Laplacian limited to a band of frequencies. Near a step, smoothing lifts the dark side and lowers the bright side. So the sign changes right at the step, and the border of the positive region marks the edge.

Kernel or operator

The kernel has no finite size. The filter is recursive. The Inspector asks the engine for the stages with the current settings.

Parameters

Parameter Default Values Meaning
Output output Edges Edges, Smoothed, Band-limited Laplacian, Binary Laplacian The edge map, or one of the stages. The Laplacian is shown as 128 plus 4 times its value, our choice.
Smoothing factor b b 0.8 0.1 to 0.98 The factor b of the ISEF, from 0 to 1. Our choice of 0.8.
Low threshold low 2 0 to 50 The low hysteresis threshold on the gradient of the smoothed image, in levels per pixel. Our choice of 2.
High threshold high 5 0 to 100 The high hysteresis threshold, in levels per pixel. An edge must reach it somewhere. Our choice of 5.

Implementation

shen_castan in engine/src/pixelnexus_engine/filters/shen_castan.py runs both recursions with scipy.signal.lfilter. Each starts in the steady state of the first pixel, which acts as if the edge pixels went on forever. The paper's own last steps are an adaptive gradient in a window, then hysteresis and thinning. The sources we could read describe them only in outline. So our version is simpler. It takes the gradient of the smoothed image by central differences at the zero crossings, and keeps edges with skimage.filters.apply_hysteresis_threshold. The thresholds are in levels per pixel.

Worked example

b Zero crossings Edge pixels Edges within 2 px of the outline (%) Outline within 2 px of an edge (%)
0.5 12165 2375 27.2 99.4
0.7 11651 1416 37.6 99.4
0.8 11082 947 49.6 99.4
0.9 9937 147 86.4 34.1
0.95 9648 0 0.0 0.0

The disk and the square of the figure with noise of sigma 20, and the default thresholds 2 and 5. The outline is the border of the two shapes before the blur and the noise, 328 pixels long.

Smoothing trades stray edges for weaker ones. At b 0.8, edges reach 99.4 percent of the outline, and half of the edge pixels lie near it. At b 0.9, 86.4 percent lie near the outline, but they cover only 34.1 percent of it. At b 0.95, no edge passes. The gradient of the smoothed image falls as b grows, so the default thresholds are too high there. Lower them when you raise b.

Complexity

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

N is the number of pixels, at any b.

Artifacts and limitations

Limitations

  • The gradient and hysteresis steps are our simplified version, not the adaptive gradient of the paper.
  • The ISEF has a sharp peak, so it keeps more noise than a Gaussian of the same width.

Artifacts

  • Gaps at the corners of shapes with high thresholds.
  • Short spurs from noise with low thresholds.

Tests

The recursion must equal a direct convolution with the published kernel, at three values of b, with the edge pixels repeated. A flat image must stay flat. At a step, the Laplacian must be positive on the dark side and negative on the bright side, with the zero crossing on the dark side. On a noisy disk, the edges must go all the way around, with more than 85 percent within 2 pixels of the circle. More smoothing must leave fewer zero crossings on noise. Each output must show its stage, and the representation must have its three stages.

References

  • Shen, J., and Castan, S. An optimal linear operator for step edge detection. CVGIP Graphical Models and Image Processing 54(2), 112 to 133, 1992. DOI 10.1016/1049-9652(92)90060-B.
  • Castan, S., Zhao, J., and Shen, J. Optimal filter for edge detection methods and results. Computer Vision, ECCV 90, Lecture Notes in Computer Science 427, 13 to 17, 1990. DOI 10.1007/BFb0014845.
  • Orhei, C., Bogdan, V., Bonchis, C., and Vasiu, R. Dilated filters for edge-detection algorithms. Applied Sciences 11(22), 10716, 2021. The discrete kernel and the steps used here. Preprint at arXiv 2106.07395. DOI 10.3390/app112210716.