[圖像處理] Sobel邊緣檢測算法

完成時間:2017/1/23 

我的實現結果如下:(圖一爲原圖,圖二爲邊緣檢測結果)

               

              

關於Sobel算子(英文部分來源於Wikipedia)

         The Sobel operator, sometimes called the Sobel–Feldman operator or Sobel filter, is used inimage processing and computer vision, particularly within edge detection algorithms where it creates an image emphasising edges. It is named after Irwin Sobel and Gary Feldman, colleagues at the Stanford Artificial Intelligence Laboratory (SAIL).

     Sobel算子,也被稱爲Sobel-Feldman算子,或者Sobel濾波,是在圖像處理和計算機視覺得到廣泛應用的一種圖像邊緣檢測算法。它由斯坦福大學人工智能實驗室(SAIL)的Irwin Sobel和Gray Feldman而得名(在此膜拜數學大神!)。

     The operator uses two 3×3 kernels which are convolved with the original image to calculate approximations of the derivatives – one for horizontal changes, and one for vertical. If we define A as the source image, and Gx and Gy are two images which at each point contain the horizontal and vertical derivative approximations respectively, the computations are as follows:

    Sobel算子使用兩個(3x3)矩陣來對原圖進行卷積運算以計算出兩個方向的灰度差分(偏導)的估計值(一個水平方向、一個豎直方向)。我們假定A是原始圖像(彩色圖像需先轉換爲灰度圖像Gx和Gy分別是在橫向及縱向的灰度偏導的近似值(即兩個方向上對原圖的平面卷積結果)。數學表達如下:

     

    對應的計算過程如下:

       Gx = [ f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1)] - [f(x-1,y-1)+2*f(x-1,y)+f(x-1,y+1) ]
       Gy = [ f(x-1,y-1) + 2f(x,y-1) + f(x+1,y-1)] - [f(x-1, y+1) + 2*f(x,y+1)+f(x+1,y+1) 

    上式中,f(x,y)爲圖像A中(x,y)處的灰度值。由此便可以計算出每個點的Gx和Gy。


    At each point in the image, the resulting gradient approximations can be combined to give the gradient magnitude, using:

   對於圖像中的每個點,其梯度的估計值G便可以通過兩個方向的梯度Gx和Gy藉由下式得出:

     

   此時,我們只需要設定一個閾值Gmax(比如說:100,一般來講0-255左右爲宜),若梯度G大於閾值Gmax,則可認爲該點是一個邊界點

   Using this information, we can also calculate the gradient's direction:

   當然,我們甚至可以通過Gx和Gy求得邊界點梯度變化的方向,只需應用下式即可。

   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章