付博研+盧振洋+白立來+陳雨+劉嘉
摘 要: 為了提升Canny邊緣檢測的效果,并使之適用于FPGA平臺,提出一種改進的Canny算法,并用C語言實現(xiàn)了該算法;將改進的Canny算法定點化處理并使用Verilog HDL語言進行描述,采用一種Matlab與Modelsim聯(lián)合的仿真方法,進行了FPGA仿真實驗,以對改進算法在FPGA上的性能進行評估。實驗結(jié)果表明改進的算法檢得邊緣清晰且更細,所采用仿真方法是基于Modelsim平臺使用Verilog HDL語言進行的,是一種驗證FPGA上圖像算法性能的新方法。
關(guān)鍵詞: Canny算法; FPGA仿真; Modelsim; 邊界細化
中圖分類號: TN919?34; TP391 文獻標識碼: A 文章編號: 1004?373X(2014)18?0011?04
An improved Canny algorithm and its simulation verification
FU Bo?yan, LU Zhen?yang, BAI Li?lai, CHEN Yu, LIU Jia
(College of Mechanical Engineering and Applied Electronics Technology, Beijing University of Technology, Beijing 100124, China)
Abstract: In order to improve an image edge detection effect of Canny algorithm and be applied to FPGA platform, a improved Canny algorithm is proposed in this paper. The algorithm was realized with C language on computer. The fixed?point processing for the improved Canny algorithm was performed. It is described with Verilog HDL. The simulation experiment was conducted by a co?simulating method which associates Matlab with Modelsim to assess the performance of the algorithm on FPGA. The result shows that the edges detected by the improved algorithm are more clear and thin. The co?simulating method is based on Modelsim, and Verilog HDL. Its a new method for verifying image processing algorithm on FPGA.
Keywords: Canny algorithm; FPGA simulation; Modelsim; edge thinning
邊緣檢測技術(shù)在特征提取、目標識別等領域有廣泛的應用。常用的邊緣檢測算法有Sobel算法、Robert算法、Prewitt算法、Canny算法等。其中Canny算法是由John F. Canny于1986年提出,是一種經(jīng)典的邊緣檢測算法[1],具有信噪比大,檢測精度高等優(yōu)點,應用非常廣泛。Canny算法也存在一些缺點,研究人員提出多種改進方法[2?5],包括修改平滑方法,優(yōu)化閾值選取等。本文提出一種改進的Canny算法并編程實現(xiàn);提出一種方法用于對FPGA平臺下的圖像算法進行仿真驗證,通過對改進的Canny算法進行仿真,結(jié)果證明了改進Canny算法的有效性。
1 算法設計
1.1 經(jīng)典Canny算法
經(jīng)典Canny算法可以分為4步:
(1) 平滑圖像。利用二維高斯函數(shù)的對稱性和可分解性,很容易求出高斯函數(shù)在任意方向的方向倒數(shù)與圖像的卷積。因此對于二維情況,容易求出適用于各類型邊界的邊界檢測算子,Canny算法實際上是用高斯函數(shù)與圖像卷積,然后求梯度[6],根據(jù)梯度的幅值和相位進一步判斷邊緣。所選二維高斯函數(shù)為:
[G(x,y)=e(-x2+y22σ2)2πσ2] (1)
式中:σ為高斯函數(shù)的標準差,決定高斯函數(shù)的平滑程度,高斯函數(shù)的平滑程度與其成正比。
(2) 計算梯度的幅值和方向。設原圖像為f(x,y),采用2×2領域內(nèi)一階偏導數(shù)的有限差分計算經(jīng)平滑后圖像P(x,y)的幅值D(x,y):
[D(x,y)=?[G(x,y)*f(x,y)]=[(?G?x*f)2+(?G?y*f)2]12] (2)
方向V(x,y)為:
[V(x,y)=arctan(Py(x,y)Px(x,y))=?G?y*f?G?x*f] (3)
(3) 對梯度幅值進行非極大值抑制。當某點的幅值大于該點梯度方向上的兩個相鄰像素的幅值,則認定該點為邊界點[6]。
(4) 雙閾值方法檢測并連接邊緣。根據(jù)高低閾值,認定所有灰度大于高閾值的點為邊緣點;灰度在高低閾值之間的點,如果周圍有大于高閾值的像素則認定該點也是邊緣點;灰度小于低閾值的點不是邊緣點[7]。
1.2 Canny算法的缺點
Canny算法在2×2鄰域內(nèi)計算梯度和幅值,容易檢測出孤立邊緣點和偽邊緣[4]。Canny算法對閾值選取比較敏感,如果Canny算子的高閾值選取過大,則會丟失灰度值變化較小的邊緣,閾值選取過小則會造成細節(jié)過多,增加偽邊緣數(shù)目[5]。