Implementation of the Canny edge detector
Usage
function y = cannyedge(x : cube, sigma=1, low_threshold=1, high_threshold=0.1)
Parameters
x | the input image |
sigma | parameter for the Gaussian filter (used for smoothing) |
low_threshold | hysteresis lower threshold |
high_threshold | hysteresis higher threshold |
Remarks
The steps involved
- Smooth using the Gaussian with sigma above.
- Apply the horizontal and vertical Sobel operators to get the gradients within the image. The edge strength is the sum of the magnitudes of the gradients in each direction.
- Find the normal to the edge at each point using the arctangent of the ratio of the Y sobel over the X sobel. Pragmatically, we can look at the signs of X and Y and the relative magnitude of X vs Y to sort the points into 4 categories: horizontal, vertical, diagonal and antidiagonal.
- Look in the normal and reverse directions to see if the values in either of those directions are greater than the point in question. Use interpolation to get a mix of points instead of picking the one that’s the closest to the normal.
- Label all points above the high threshold as edges.
- Recursively label any point above the low threshold that is 8-connected to a labeled point as an edge.