邊緣檢測matlab算法匯總


邊緣檢測matlab算法匯總

1.      基於一階微分算子檢測邊緣圖像

一階微分邊緣算子又稱梯度邊緣算子,它是利用圖像在邊緣處的階躍性,及圖像梯度在邊緣去得極大值得特征性進行邊緣檢測。

Sobel算子:image =edge(in_image,’sobel’,threshold,direction);

Prewitt算子: image = edge(in_image,’prewitt’,threshold,direction);

Roberts算子: image = edge(in_image,’sobel’,threshold);

其中,in_image 是灰度圖像,threshold是閾值,direction是方向。

優點:實現簡單、運算速度快

缺點:易受噪音影響,主要原因其一是實際邊緣灰度與理想邊緣灰度存在差異,有可能檢測出多個邊緣;其二是算子尺度固定不利於檢測出不同尺度的邊緣。

Canny算子:image = edge(in_image,’canny’,threshold);

其中,in_image 是灰度圖像,threshold是閾值。

         canny算子主要在原一階微分算子基礎上進行了擴展,增加了非最大值抑制和雙閾值兩項改進。利用非最大值抑制不僅可以有效地抑制多響應邊緣,而且還可以提高邊緣的定位精度。利用雙閾值可以有效減少邊緣的漏檢率。主要分為4步進行:高斯平滑去噪、計算梯度與方向角、非最大值抑制、滯后閾值化。 

2.      基於二階微分算子檢測邊緣圖像

二階微分邊緣檢測算子是利用圖像在邊緣處的階躍性導致圖像二階微分在邊緣處出現零值這一特性進行邊緣檢測的,因此該算法又稱零點算子和拉普拉斯算子。

高斯拉普拉斯方法(laplacian of Gaussian, LoG):image = edge(in_image,’log’,threshold);

其中,in_image 是灰度圖像,threshold是閾值。

Log算子檢測邊緣的結果要由於roberts和sobel算子,檢測出來的邊緣比較完整,且抗噪能力較好。

 

3.      基於SUSAN特征檢測算子的邊緣提取

SUSAN(Smallest Univalue Segment AssimilatingNucleus),又稱最小核值相似區。它使用一個原型模板和一個圓的中心點,通過圓心點像元值與模板圓內其他像元值的比較,統計出圓中心點像元值近似的像元數量,並與所設定的閾值進行比較,以確定是否是邊緣。

[plain]  view plain  copy
  1. function image_out = susan(im,threshold)  
  2. % 功能:實現運用SUNSAN算子進行邊緣檢測  
  3. % 輸入:image_in-輸入的待檢測的圖像  
  4. %       threshold-閾值  
  5. % 輸出:image_out-檢測邊緣出的二值圖像  
  6.   
  7. % 將輸入的圖像矩陣轉換成double型  
  8. d = length(size(im));  
  9. if d==3  
  10.     image=double(rgb2gray(im));  
  11. elseif d==2  
  12.     image=double(im);  
  13. end  
  14.    
  15. % 建立SUSAN模板  
  16.    
  17. mask = ([ 0 0 1 1 1 0 0 ;0 1 1 1 1 1 0;1 1 1 1 1 1 1;1 1 1 1 1 1 1;1 1 1 1 1 1 1;0 1 1 1 1 1 0;0 0 1 1 1 0 0]);    
  18.    
  19. R=zeros(size(image));  
  20. % 定義USAN 區域  
  21. nmax = 3*37/4;  
  22.   
  23.  [a b]=size(image);  
  24. new=zeros(a+7,b+7);  
  25. [c d]=size(new);  
  26. new(4:c-4,4:d-4)=image;  
  27.     
  28. for i=4:c-4  
  29.       
  30.     for j=4:d-4  
  31.           
  32.         current_image = new(i-3:i+3,j-3:j+3);  
  33.         current_masked_image = mask.*current_image;  
  34.      
  35. %   調用susan_threshold函數進行閾值比較處理  
  36.                   
  37.         current_thresholded = susan_threshold(current_masked_image,threshold);  
  38.         g=sum(current_thresholded(:));  
  39.           
  40.         if nmax<g  
  41.             R(i,j) = g-nmax;  
  42.         else  
  43.             R(i,j) = 0;  
  44.         end  
  45.     end  
  46. end  
  47.    
  48. image_out=R(4:c-4,4:d-4);  
[plain]  view plain  copy
  1.   
[plain]  view plain  copy
  1. susan_threshold函數  
[html]  view plain  copy
  1. function thresholded = susan_threshold(image,threshold)  
  2. % 功能:設定SUSAN算法的閾值  
  3.   
  4. [a b]=size(image);  
  5. intensity_center = image((a+1)/2,(b+1)/2);  
  6.    
  7. temp1 = (image-intensity_center)/threshold;  
  8. temp2 = temp1.^6;  
  9. thresholded = exp(-1*temp2);  

優點:抗噪能力好、計算量小速度快、可以檢測邊緣的方向信息。






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM