關于此算法的代碼可以再http://blog.csdn.net/caiye917015406/article/details/7863825找到 This tutorial assumes the reader: This tutorial will teach you how to:這個教程將教你: INTRODUCTIONEdges characterize boundaries and are therefore a problem of fundamental importance in image processing. Edges in images are areas with strong intensity contrasts ? a jump in intensity from one pixel to the next. Edge detecting an imagesignificantly reduces the amount of data and filters out useless information, while preserving the important structural properties in an image. This was also stated in my Sobel and Laplace edge detection tutorial, but I just wanted reemphasize the point of why you would want to detect edges. 邊緣描述邊界在圖像的預處理中是一個重要的問題。邊緣是像素點之間越跳比較明顯的區(qū)域。邊緣提取可以明顯的減少數據量和濾去一些沒用的信息,同時,它保留了圖像的重要的結構性質。這些在前一篇的文章已經介紹了,但是,我還是想再次強調一下你為什么要做邊緣提取。 The Canny edge detection algorithm is known to many as the optimal edge detector. Canny's intentions were to enhance the many edge detectors already out at the time he started his work. He was very successful in achieving his goal and his ideas and methods can be found in his paper, "A Computational Approach to Edge Detection". In his paper, he followed a list of criteria to improve current methods of edge detection. The first and most obvious is low error rate. It is important that edges occuring in images should not be missed and that there be NO responses to non-edges. The second criterion is that the edge points be well localized. In other words, the distance between the edge pixels as found by the detector and the actual edge is to be at a minimum. A third criterion is to have only one response to a single edge. This was implemented because the first 2 were not substantial enough to completely eliminate the possibility of multiple responses to an edge. Canny邊緣檢測算法是被人熟知的最佳邊緣檢測算法,在Canny開始工作的時候,他就想提高邊緣提取算法。他已經很成功的實現(xiàn)了他的目標和想法,他的思路可以參考“Computational Approach to Edge Detection”。在這篇論文中,他通過一系列標準來提高目前的邊緣檢測算法。第一個是高精度,在圖像邊緣檢測既不忽略邊界也不對非邊界標記是非常重要的。第二個標準是邊緣點能本地化,換句話說,就是實際邊緣點與測的邊緣點的距離是一個很小的值。第三個準則是單個邊緣對應一個處理。對于第三個標準的提出時因為前兩個標準不能使好幾個計算值反映一個邊緣。
Based on these criteria, the canny edge detector first smoothes the image to eliminate and noise. It then finds the image gradient to highlight regions with high spatial derivatives. The algorithm then tracks along these regions and suppresses any pixel that is not at the maximum (nonmaximum suppression). The gradient array is now further reduced by hysteresis. Hysteresis is used to track along the remaining pixels that have not been suppressed. Hysteresis uses two thresholds and if the magnitude is below the first threshold, it is set to zero (made a nonedge). If the magnitude is above the high threshold, it is made an edge. And if the magnitude is between the 2 thresholds, then it is set to zero unless there is a path from this pixel to a pixel with a gradient above T2. 基于這些標準,Canny邊緣提取算法首先對圖像進行平滑處理來消除噪聲。接下來,通過空間的導數值來求的突出區(qū)域的梯度。然后,該算法找到這些區(qū)域,抑制 不是最大的值(非最大值抑制)。這些梯度級通過滯后閥值來削弱。滯后閥值方法來追蹤那些沒被抑制的像素點。滯后閥值使用兩個閥值來處理像素點,若像素點值低于最小閥值就被設為0,若大于最大的閥值就被標記為邊緣。處于兩者之間的梯度級的像素點,若果這個像素點連接一個大于最大閥值的像素點,那么就是邊界,否則就設為0。 Step 1 為了進行邊緣提取,需要做一些預處理。第一步要進行濾波來濾去噪聲。因為高斯濾波采用一個簡單的掩碼,所以它通常應用于Canny算法。一旦一個合適的掩碼被確定,高斯濾波就可以進行標準的卷積計算。一個卷積往往要小于原始圖像。因此,掩碼要在原始圖像上滑動,每一次計算一個區(qū)域的值。高斯掩碼越大,對噪聲越敏感。隨著高斯掩碼的增大,對應的邊界檢測的誤差越大。以下是我們所用的高斯掩碼:
Step 2 進行完平滑處理和濾波處理,下一步是通過圖像的梯度求的邊緣強度。用Sobel運算來求的二維圖像的梯度。(具體見上一篇)
The magnitude, or EDGE STRENGTH, of the gradient is then approximated using the formula: Step 3 一旦求的x和y方向的梯度,就可以很容易的求的邊界方向。然而,當強度為0時,會差生錯誤,因此,在代碼中進行了處理。當x方向的梯度等于0時,邊界的方向將被設置未0或者90.進一步確定,若y方向的梯度也等于0,那么邊界方向被設置未0,否則被設置為90.以下是尋找邊緣方向的公式: Step 4 一旦求的邊緣方向,下一步就是將邊界方向與圖像聯(lián)系起來。因此,若5*5的圖像如下圖: x x x x x x x a x x x x x x x x x x x x Then, it can be seen by looking at pixel "a", there are only four possible directions when describing the surrounding pixels -0 degrees (in the horizontal direction), 45 degrees (along the positive diagonal),90 degrees (in the vertical direction), or135 degrees (along the negative diagonal). So now the edge orientation has to be resolved into one of these four directions depending on which direction it is closest to (e.g. if the orientation angle is found to be 3 degrees, make it zero degrees). Think of this as taking a semicircle and dividing it into 5 regions.
Therefore, any edge direction falling within the yellow range (0 to 22.5 & 157.5 to 180 degrees) is set to 0 degrees. Any edge direction falling in thegreen range (22.5 to 67.5 degrees) is set to 45 degrees. Any edge direction falling in theblue range (67.5 to 112.5 degrees) is set to 90 degrees. And finally, any edge direction falling within thered range (112.5 to 157.5 degrees) is set to 135 degrees. Step 5 確定邊界的方向后,下一步就是應用非最大抑制算法。非最大抑制算法在邊緣沿著邊緣方向來抑制任何不被認為為邊緣的點。這將使得輸出圖像的邊緣線變細。
Step 6
這是從網上摘抄http://blog.csdn.net/carson2005/article/details/7516434 Canny算子是John.F.Canny于20世紀80年代提出的一種多級邊緣檢測算法。該算子最初的提出是為了能夠得到一個最優(yōu)的邊緣檢測,即:檢測到的邊緣要盡可能跟實際的邊緣接近,并盡可能的多,同時,要盡量降低噪聲對邊緣檢測的干擾。 Canny算子邊緣檢測算法的計算步驟:
|
|