07 Canny operator edge detection


foreword

I have learned several classic operators before:
06Laplican
05Priwitt
04Sobel
03Roberts
What I learned today is the Canny operator.


1. What is the Canny operator?

Canny operator is an optimal edge detection operator, which has high precision and low false detection rate, and is often used in the fields of computer vision and image processing. The Canny operator mainly consists of the following steps:

1 Gaussian filter: Gaussian filter is used in the image to smooth the image to remove noise.

2 Calculate the gradient of the image: Calculate the gradient value and direction of each pixel in the smoothed image.

3 Non-maximum suppression: In the direction of the gradient, only the pixels of the local maximum are retained to obtain the final edge.

4 Dual threshold detection: according to the high and low thresholds, the pixels in the image are divided into strong edges and weak edges.

5. Edge connection: According to the position and topological relationship of strong and weak edges, weak edges are connected to edges connected with strong edges.

The above steps are the main process of the Canny operator. Compared with other edge detection algorithms, the edge generated by the Canny operator is more delicate and accurate, which can effectively avoid the problems of noise and high false detection rate.

2. Program Verification

1. Use third-party libraries

The code is as follows (example):

import cv2
import numpy as np

def canny_edge_detection(image):
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    blurred_image = cv2.GaussianBlur(gray_image, (3, 3), 0)
    edges = cv2.Canny(blurred_image, 30, 100)
    return edges

insert image description here

Summarize

This article calls a third-party library to complete canny edge extraction. Since canny edge extraction includes a lot of knowledge points, I can only slowly realize all its functions with my current code level. This part will be updated in later articles.

Guess you like

Origin blog.csdn.net/CSDN_Yangk/article/details/129859396
Recommended