Home Edge detecting
Post
Cancel

Edge detecting

What is Edge Detecting?

As you can see in the word “Edge detecting”, it can detect edge by
cv2.Canny(image, threshold1, threshold2)
where:

  • image = 8-bit input image.
  • threshold1 = any value below threshold1 is considered not to be an edge.
  • threshold2 = any gradient value larger than threshold2 is considered to be an edge. Then how about the values between threshold1 and threshold2? they are considered as edges or non-edges based on how their intensities are connected.




Modifing Edges

We can modify the thickness of edges by four ways:

  • Erosion = Removes pixels at the boundaries of objects in an image. It can used as
    cv2.erode(src, kernel, anchor, iterations) where

    • src = input image; the number of channels can be arbitrary.
    • kernel = structuring element used for erosion; if element=Mat(), a 3 x 3 rectangular structuring element is used.
    • anchor = position of the anchor within the element; default value (-1, -1) means that the anchor is at the element center.
    • iterations = number of times erosion is applied.

  • Dilation = Adds pixels to the boundaries of objects in an image. It can used as
    cv2.dilate(src, kernel, anchor, iterations) where

    • src = input image; the number of channels can be arbitrary.
    • kernel = structuring element used for erosion; if element=Mat(), a 3 x 3 rectangular structuring element is used.
    • anchor = position of the anchor within the element; default value (-1, -1) means that the anchor is at the element center.
    • iterations = number of times erosion is applied.

  • Morphology = It is a morphological operation used for removing noise, filling holes, and splicing broken lines. Morphological operations can be applied to binary images consisting only of black and white. It can used as
    cv2.morphologyEx(src, op, kernel, anchor, iterations) where

    • src = input image; the number of channels can be arbitrary.
    • op = Type of a morphological operation.
    • kernel = structuring element used for erosion; if element=Mat(), a 3 x 3 rectangular structuring element is used.
    • anchor = position of the anchor within the element; default value (-1, -1) means that the anchor is at the element center.
    • iterations = number of times erosion is applied.




Types of morphological operations.



  • MORPH_ERODE = Same as eroding
  • MORPH_DILATE = Same as dliting
  • MORPH_OPEN = Erosion followed by dilation
  • MORPH_CLOSE = Dilation followed by erosion
  • MORPH_GRADIENT = Boundary pixels obtained by subtracting the dilated image from the eroded image.
  • MORPH_TOPHAT = Original image - morph_open image.
  • MORPH_BLACKHAT = Morph_close - original image.
  • MORPH_HITMISS = It applies one or more structuring elements to an input image to obtain the output image. Because of that, MORPH_HITMISS is often used to detect corner of image.





Implementation

Dilation, Erosion and Edge Detection

This post is licensed under CC BY 4.0 by the author.