小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Canny Edge Detection Tutorial(Canny 邊緣檢測教程)

 phylixal 2013-03-01

Canny Edge Detection Tutorial(Canny 邊緣檢測教程)


關于此算法的代碼可以再http://blog.csdn.net/caiye917015406/article/details/7863825找到

This tutorial assumes the reader:
(1) Knows how to develop source code to read raster data
(2) Has already read my Sobel edge detection tutorial

This tutorial will teach you how to:這個教程將教你:
(1) Implement the Canny edge detection algorithm. 實現(xiàn)Canny邊緣檢測算法

                                              

INTRODUCTION

Edges 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
In order to implement the canny edge detector algorithm, a series of steps must be followed. The first step is to filter out any noise in the original image before trying to locate and detect any edges. And because the Gaussian filter can be computed using a simple mask, it is used exclusively in the Canny algorithm. Once a suitable mask has been calculated, the Gaussian smoothing can be performed using standard convolution methods. A convolution mask is usually much smaller than the actual image. As a result, the mask is slid over the image, manipulating a square of pixels at a time. The larger the width of the Gaussian mask, the lower is the detector's sensitivity to noise. The localization error in the detected edges also increases slightly as the Gaussian width is increased. The Gaussian mask used in my implementation is shown below.

為了進行邊緣提取,需要做一些預處理。第一步要進行濾波來濾去噪聲。因為高斯濾波采用一個簡單的掩碼,所以它通常應用于Canny算法。一旦一個合適的掩碼被確定,高斯濾波就可以進行標準的卷積計算。一個卷積往往要小于原始圖像。因此,掩碼要在原始圖像上滑動,每一次計算一個區(qū)域的值。高斯掩碼越大,對噪聲越敏感。隨著高斯掩碼的增大,對應的邊界檢測的誤差越大。以下是我們所用的高斯掩碼:

Step 2
After smoothing the image and eliminating the noise, the next step is to find the edge strength by taking the gradient of the image. The Sobel operator performs a 2-D spatial gradient measurement on an image. Then, the approximate absolute gradient magnitude (edge strength) at each point can be found. The Sobel operator uses a pair of 3x3 convolution masks, one estimating the gradient in the x-direction (columns) and the other estimating the gradient in the y-direction (rows). They are shown below:

進行完平滑處理和濾波處理,下一步是通過圖像的梯度求的邊緣強度。用Sobel運算來求的二維圖像的梯度。(具體見上一篇)

 

The magnitude, or EDGE STRENGTH, of the gradient is then approximated using the formula:

|G| = |Gx| + |Gy|

Step 3
Finding the edge direction is trivial once the gradient in the x and y directions are known. However, you will generate an error whenever sumX is equal to zero. So in the code there has to be a restriction set whenever this takes place. Whenever the gradient in the x direction is equal to zero, the edge direction has to be equal to 90 degrees or 0 degrees, depending on what the value of the gradient in the y-direction is equal to. If GY has a value of zero, the edge direction will equal 0 degrees. Otherwise the edge direction will equal 90 degrees. The formula for finding the edge direction is just:

一旦求的x和y方向的梯度,就可以很容易的求的邊界方向。然而,當強度為0時,會差生錯誤,因此,在代碼中進行了處理。當x方向的梯度等于0時,邊界的方向將被設置未0或者90.進一步確定,若y方向的梯度也等于0,那么邊界方向被設置未0,否則被設置為90.以下是尋找邊緣方向的公式:

theta = invtan (Gy / Gx)

Step 4
Once the edge direction is known, the next step is to relate the edge direction to a direction that can be traced in an image. So if the pixels of a 5x5 image are aligned as follows:

一旦求的邊緣方向,下一步就是將邊界方向與圖像聯(lián)系起來。因此,若5*5的圖像如下圖:

x     x     x     x     x
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
After the edge directions are known, nonmaximum suppression now has to be applied. Nonmaximum suppression is used to trace along the edge in the edge direction and suppress any pixel value (sets it equal to 0) that is not considered to be an edge. This will give a thin line in the output image.

確定邊界的方向后,下一步就是應用非最大抑制算法。非最大抑制算法在邊緣沿著邊緣方向來抑制任何不被認為為邊緣的點。這將使得輸出圖像的邊緣線變細。

 

Step 6
Finally, hysteresis is used as a means of eliminating streaking. Streaking is the breaking up of an edge contour caused by the operator output fluctuating above and below the threshold. If a single threshold, T1 is applied to an image, and an edge has an average strength equal to T1, then due to noise, there will be instances where the edge dips below the threshold. Equally it will also extend above the threshold making an edge look like a dashed line. To avoid this, hysteresis uses 2 thresholds, a high and a low. Any pixel in the image that has a value greater than T1 is presumed to be an edge pixel, and is marked as such immediately. Then, any pixels that are connected to this edge pixel and that have a value greater than T2 are also selected as edge pixels. If you think of following an edge, you need a gradient of T2 to start but you don't stop till you hit a gradient below T1.

 

這是從網上摘抄http://blog.csdn.net/carson2005/article/details/7516434

Canny算子是John.F.Canny20世紀80年代提出的一種多級邊緣檢測算法。該算子最初的提出是為了能夠得到一個最優(yōu)的邊緣檢測,即:檢測到的邊緣要盡可能跟實際的邊緣接近,并盡可能的多,同時,要盡量降低噪聲對邊緣檢測的干擾。

Canny算子邊緣檢測算法的計算步驟:



 

 

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多