- There is a sharp change in intensity a sharp change in color.

Image can be read as a matrix an array of pixels that contains the light intensity at some location.
0 : no intensity if something is completely black
255 : maximum intensity that something being completely white


a strong gradient : a steep change
a small gradient : a shallow change


- Canny Edge Detection
- A popular edge detection algorithm, it thinks noise is edges.
- It is a multi-stage algorithm and we will go through each stages.
- Noise Reduction : Since edge detection is susceptible to noise in the image, first step is to remove the noise in the image with a 5x5 Gaussian filter. We have already seen this in previous chapters.
- Finding Intensity Gradient of the Image : Smoothened image is then filtered with a Sobel kernel in both horizontal and vertical direction to get first derivative in horizontal direction and vertical direction. Gradient direction is always perpendicular to edges. It is rounded to one of four angles representing vertical, horizontal and two diagonal directions.
- Non-maximum Suppression : After getting gradient magnitude and direction, a full scan of image is done to remove any unwanted pixels which may not constitute the edge. For this, at every pixel, pixel is checked if it is a local maximum in its neighborhood in the direction of gradient. Check the image below:

Point A is on the edge ( in vertical direction).
Gradient direction is normal to the edge.
Point B and C are in gradient directions. So point A is checked with point B and C to see if it forms a local maximum. If so, it is considered for next stage, otherwise, it is suppressed ( put to zero).
In short, the result you get is a binary image with "thin edges".
- Hysteresis Thresholding
This stage decides which are all edges are really edges and which are not. For this, 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 who 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. See the image below:

The edge A is above the maxVal, so considered as "sure-edge". Although edge C is below maxVal, it is connected to edge A, so that also considered as valid edge and we get that full curve. But edge B, although it is above minVal and is in same region as that of edge C, it is not connected to any "sure-edge", so that is discarded. So it is very important that we have to select minVal and maxVal accordingly to get the correct result.
This stage also removes small pixels noises on the assumption that edges are long lines.
So what we finally get is strong edges in the image.
The process is below.
1) Compute the derivative in all directions of the image.


2) And then traces the strongest gradients as a series of white pixels.

For example,
edges=cv2.Canny(img, 100, 200)
# 100 = lower threshold, 200 = upper threshold
The result is

- Sobel
Sobel measures how fast brightness changes.
- Sobel-x: change in horizontal direction (detects vertical edges)
- Sobel-y: change in vertical direction (detects horizontal edges)
If intensity changes sharply → likely edge.
The Sobel kernel is a 3x3 convolution matrix used in image processing for edge detection by calculating the gradient approximation of image intensity. It utilizes two kernels—one for horizontal and one for vertical changes—to detect rapid intensity shifts, often acting as a smoothing filter to reduce noise.
For example,
Then, Step-by-step multiply and sum : (1)(−1)+(1)(0)+(1)(1)+(1)(−2)+(1)(0)+(1)(2)+(1)(−1)+(1)(0)+(1)(1)=0+0+0=0
→ What does this result means?
- Sobel-x measures left-to-right intensity change (x-direction gradient).
- If the right side is brighter than the left side → positive value
For example,
The patch with increasing brightness left → right \( P = \begin{bmatrix} 0 & 1 & 2 \\ 0 & 1 & 2 \\ 0 & 1 & 2 \end{bmatrix} \) means, left side is darker, right side is brighter, so Sobel-x should be positive.
- 2+4+2=8 : Positive and large → strong edge intensity change.
• If the left side is brighter than the right side → negative value
• If both sides are same brightness → near 0
If it Detects horizontal edges (changes in vertical direction), it will be as below.
\( \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ 1 & 2 & 1 \end{bmatrix} \)
'Deep Learning > Object Detection' 카테고리의 다른 글
| Thresholding, Contours, Morphology, Erosion, Dilation (0) | 2026.03.03 |
|---|---|
| Gaussian blur (0) | 2026.03.03 |
| Object Detection, mAP(The Mean Average Precision) (0) | 2024.02.16 |
| YOLO(You Only Look Once) (0) | 2024.02.12 |
| (prerequisite-YOLO) One Stage Object Detection (0) | 2024.02.11 |