Canny Edge Detection
Edge detection is an image processing technique in computer vision that involves identifying the outline of objects in an image.
Canny edge detection is one of the best techniques for edge detection. It’s designed to detect clean, well-defined edges while reducing noise and avoiding false edges. It uses a double thresholding method to detect edges in an image: a high and a low threshold.
img = cv2.Canny('photo.jpg') img_edges = cv2.Canny(img, 100, 200) // 100 is the low threshold // 200 is the high threshold
The thresholds decide what becomes an edge and what doesn't. To make this decision, we use gradient values:
- If a gradient value is above the high threshold, it’s considered a strong edge and added to the edge map. (strong edge)
- If it’s below the low threshold, it’s ignored. (non edge)
- If it is between the high and low threshold, it is only kept if it is connected to a strong edge. (potential edge)
What are gradient values?
Gradient values are not the raw image values. They are computed numbers derived from the raw image by checking how much the pixel intensity changes in an image. We use gradient values because the raw image values don’t directly tell us where the edges are.
A simple example to illustrate changes in pixel intensity: if two neighboring pixels have very different values (e.g. 50 and 200 and the gradient value is 150), there’s a big change — it might be an edge. But if two neighboring pixels have similar values (e.g. 50 and 52 and the gradient value is 2), there’s little change & very little possibility of being an edge.
After the gradient values are computed, they are then compared against the thresholds to decide what qualifies as a strong edge, a potential edge or a non edge.
How do we know values in between thresholds are connected to a strong edge?
By using a method called edge tracking by hysteresis which decides edges that are connected and should be kept VS discarded. This algorithm works by looking at the 8 neighbors (directly adjacent pixels - top, bottom, left, right, and diagonals) of each potential edge pixel. Any pixel directly or indirectly connected to a strong edge is included in the final result.
How edge tracking works:
50 80 110 90 70 250 190 120 60 180 150 70 40 60 80 50
Imagine this gradient map above:
After applying thresholds (low = 100, high = 200), the strong edge pixels ( > 200) are immediately kept as edges. Here, only the pixel 250 is marked as a strong edge.
The potential edge pixels (100–200) are 110, 190, 120, 180 and 150. Now that we have a pool of potential edges, we perform edge tracking to decide what gets to stay & what is discarded. The algorithm checks if any of the potential edges are directly or indirectly connected to the strong edge (250).
For example:
- 190 is a neighbor of 250, it is directly connected to a strong edge so it's kept.
- 150 is a neighbor of 190, it is indirectly connected to a strong edge so it’s also kept.
Weak edge pixels (< 100) like 80, 90 and the rest are completely ignored, as they are considered noise.They will not be a part of the final image.
The above is the detailed content of Canny Edge Detection. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.
