You are on page 1of 9

Edges Detection

Canny Edge Detection là một thuật toán phát hiện cạnh phổ biến. Nó được phát triển
bởi John F. Canny.
Bao gồm các giai đoạn
*Nó là một thuật toán nhiều giai đoạn và chúng ta sẽ đi qua từng giai đoạn.

1. Noise Reduction
2. Finding Intensity Gradient of the Image
3. Non-maximum Suppression
4. Thresholding & Hysteresis

*Trước khi Giảm Nhiễu, ta cần chuyển ảnh sang hệ thang màu độ xám

*Sau đây là đoạn code để chuyển:

* Bên dưới là Kết quả:


*Vì tính năng phát hiện cạnh dễ bị nhiễu trong ảnh (phát hiện cạnh của Canny Edge rất nhạy
cảm với nhiễu hình ảnh.), Một cách để loại bỏ nhiễu trên hình ảnh là áp dụng Gaussian Blur để
làm mịn nó. nên bước đầu tiên là loại bỏ nhiễu trong ảnh bằng bộ lọc Gaussian 5x5.
1. Noise Reduction:

-Applying image convolution technique is applied with a Gaussian


Kernel (3x3, 5x5, 7x7 etc…).

*Kết quả:
*Ở cách tính Gradient (tìm cả độ lớn, lẫn hướng của Gradient), mình sẽ đạo hàm Bức ảnh vừa
khử nhiễu theo 2 hướng x, y. Bằng cách nhân với Sobel kernels
2. Finding Intensity Gradient of the Image:

-Edges correspond to a change of pixels’ intensity. To detect it, the


easiest way is to apply filters that highlight this intensity change in
both directions: horizontal (x) and vertical (y)
The magnitude Gradient(G):

The gradient's direction:

Round angle to 4 gradient’s directions

Example: Gradient intensity matrix with the edge directions.


3. Non-maximum Suppression
- The principle is simple: the algorithm goes through all the points on
the gradient intensity matrix and finds the pixels with the maximum
value in the edge directions.
-Create a matrix initialized to 0 of the same size of the original gradient
intensity matrix

-Identify the edge direction based on the angle value from the angle
matrix

-Check if the pixel in the same direction has a higher intensity than the
pixel that is currently processed

-Return the image processed with the non-max suppression algorithm


4. Thresholding & Hysteresis
 - we need two threshold values, minVal and maxVal.
- Any edges with intensity gradient more than maxVal are sure to be edges and those
below minVal are sure to be non-edges, so discarded

- Those edges which lie between these two thresholds are classified edges
or non-edges based on their connectivity.
- If they are connected to "sure-edge" pixels, they are considered to be part
of edges. Otherwise, they are also discarded

You might also like