machinevisiontoolbox.Image.canny

Image.canny(sigma=1, th0=None, th1=None)

Canny edge detection

Parameters:
  • sigma (float, optional) – standard deviation for Gaussian kernel smoothing, defaults to 1

  • th0 (float) – lower threshold

  • th1 (float) – upper threshold

Returns:

edge image

Return type:

Image instance

Computes an edge image obtained using the Canny edge detector algorithm. Hysteresis filtering is applied to the gradient image: edge pixels > th1 are connected to adjacent pixels > th0, those below th0 are set to zero.

Example:

  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/machinevisiontoolbox/ImageSpatial.py", line 757, in convolve
    K = argcheck.getmatrix(K, shape=[None, None], dtype="float32")
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/spatialmath/base/argcheck.py", line 230, in getmatrix
    elif isvector(m):
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/spatialmath/base/argcheck.py", line 513, in isvector
    or (s[0] == 1 and s[1] > 0)
IndexError: tuple index out of range
Note:
  • Produces a zero image with single pixel wide edges having non-zero values.

  • Larger values correspond to stronger edges.

  • If th1 is zero then no hysteresis filtering is performed.

  • A color image is automatically converted to greyscale first.

References:
  • “A Computational Approach To Edge Detection”, J. Canny, IEEE Trans. Pattern Analysis and Machine Intelligence, 8(6):679–698, 1986.

  • Robotics, Vision & Control for Python, Section 11.5.1.3, P. Corke, Springer 2023.