edge detection

本文介绍了边缘检测的基本原理及其在图像处理中的应用。讨论了理想边沿与实际图像中边沿的区别,并介绍了噪声对边缘检测的影响。重点阐述了三种常见的边缘检测器:Sobel滤波器、LoG检测器及Canny检测器的工作原理与实现过程。

The ideal case for edge will have a deep change, and the 1st derivation can be used for detecting purpose with looking for big absolute values, but in real word, ramp edges exist, well, the 2nd derivation produce a sign change, which can also be used for edge detection, shown as below.

这里写图片描述

However, it is not perfect in real world, some noise makes the trouble, the derivation operations on the contray amplify the noise.

这里写图片描述

So, usually, smothing is applied first before edge detection. Some edge detector(fileter) is designed to integrate the smothing element.
Edge detection is fundamental related to the gradient of the image. That is,

F=FxFyF=[F(x+1,y)F(x,y)F(x,y+1)F(x,y)]

The magnitude and orientation of pixel (x,y) is defined as,
M(x,y)=(Fx)2+(Fy)2

A(x,y)=atanFxFy

We can do things like,
M(x,y)>τ

|A(x,y)θ|<τ1,and,M(x,y)>τ2

The second equation can get the line of θ angle in the image.

Here briefly introduce three types edge detector(filter)s: sobel filter, LoG detector, canny detector.
1. Sobel filter

这里写图片描述

2. LoG detector(Laplacian of Gaussian)
The sobel filter has only one set of scale, by contrast, LoG can be tuned to detecting different scale of edges, LoG has the form as,

2G(x,y)=2x2G(x,y)+2y2G(x,y)=x2+y22σ2σ4ex2+y22σ2

The negative of LoG has the shape like this, and the σ parameter controls the body width of the function.

这里写图片描述

In LoG, 1) The Gaussian smooths the image down to a certain scale; 2) Laplacian finds edges at that scale; 3) LoG will look for zero-crossing of LoG operation since it is like a 2nd derivative. In matlab, function “fspecial” with “log” parameter works for it.

We can approximate the LoG with a difference of Gaussians(DoG), which is used a lot in computer vision(like SIFT)

DoG(x,y)=12πσ21ex2+y22σ2112πσ22ex2+y22σ22,σ1>σ2

3. canny detector
The basic steps of canny detector include:
1) Smooth image with a Gaussian;
2) Compute M(x,y),A(x,y);
3) Apply non-maxima suppression to M(x,y) to obtain a new gradient image gN(x,y)
the basic idea is to quantize A(x,y) into 4 bins, if M(x,y) is greater than both its neighbors in the quantized edge direction, gN(x,y)=M(x,y), otherwise gN(x,y)=0
4) Detect and link edges

gH(x,y)=gN(x,y)τH

gL(x,y)=τLgN(x,y)<τH

respectively for strong and weak edges detection.
and the final map is gH(x,y) {all pixels in gL(x,y) that are adjacent to at least one pixel of gH(x,y)}
The canny edge detector usually has the cleaner result.

All three types edge detector can be realized with function “edge” in matlab.

### POJ 平台边缘检测问题解决方案 对于POJ平台上编号为1009的题目——《Edge Detection》,暴力求解尝试对每一个像素单独计算输出值可能会因为时间和空间限制而失败[^1]。因此,更有效的算法是必要的。 核心思想在于仅针对特定的变化点及其周围的8个邻近位置进行运算,即总共九个点[vn,rn]中的变化点v0,v1,...,vn被识别并用于后续处理[^3]。这种策略显著减少了不必要的计算量,提高了效率。 为了实现上述逻辑,在具体编码过程中可以采用如下Python代码: ```python def edge_detection(image_matrix): rows = len(image_matrix) cols = len(image_matrix[0]) result = [[0]*cols for _ in range(rows)] directions = [ (-1,-1),(0,-1),(1,-1), (-1, 0), (1, 0), (-1, 1),(0, 1),(1, 1) ] def is_edge(i,j,value): nonlocal image_matrix,directions for di,dj in directions: ni,nj=i+di,j+dj if not(0<=ni<rows and 0<=nj<cols): continue neighbor_value=image_matrix[ni][nj] if abs(value-neighbor_value)>20: return True return False for i in range(rows): for j in range(cols): current_pixel=image_matrix[i][j] if is_edge(i,j,current_pixel): result[i][j]=current_pixel return result ``` 这段程序定义了一个`edge_detection()`函数接收二维列表形式表示的灰度图作为参数,并返回一个新的同样大小但只保留边缘特征的矩阵。通过遍历每个像素点与其周围八个方向相邻节点之间的差异来决定当前像素是否属于边界的一部分;当发现任何一对相差超过给定阈值(这里设定为20)时,则认为该处存在边沿特性并将相应位置设置为目标图像中相同坐标的元素值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值