1、 邊緣提取算法
方法一:一階微分算子
-
Sobel算子
Sobel算子檢測方法對灰度漸變和噪聲較多的圖像處理效果較好,Sobel算子對邊緣定位不是很准確,圖像的邊緣不止一個像素。
-
Roberts算子
Roberts算子檢測方法對具有陡峭的低噪聲的圖像處理效果較好,但是利用roberts算子提取邊緣的結果是邊緣比較粗,因此邊緣的定位不是很准確。
-
Prewitt算子
Prewitt算子檢測方法對灰度漸變和噪聲較多的圖像處理效果較好。但邊緣較寬,而且間斷點多。
-
Canny算子
Canny算子是目前邊緣檢測最常用的算法,效果也是最理想的。
Canny邊緣檢測算法不是簡單的模板卷積而已,通過梯度方向和雙閾值法來檢測邊緣點,具體算法可以參考:http://www.cnblogs.com/AndyJee/p/3734805.html;
Canny方法不容易受噪聲干擾,能夠檢測到真正的弱邊緣。優點在於,使用兩種不同的閾值分別檢測強邊緣和弱邊緣,並且當弱邊緣和強邊緣相連時,才將弱邊緣包含在輸出圖像中。
方法二:二階微分算子
-
Laplacian算子
Laplacian算子法對噪聲比較敏感,所以很少用該算子檢測邊緣,而是用來判斷邊緣像素視為與圖像的明區還是暗區。
2、 實驗結果分析
一、邊緣提取:
- Sobel算子檢測方法對灰度漸變和噪聲較多的圖像處理效果較好,sobel算子對邊緣定位不是很准確,圖像的邊緣不止一個像素;
- Roberts算子檢測方法對具有陡峭的低噪聲的圖像處理效果較好,但是利用roberts算子提取邊緣的結果是邊緣比較粗,因此邊緣的定位不是很准確;
- Prewitt算子檢測方法對灰度漸變和噪聲較多的圖像處理效果較好。但邊緣較寬,而且間斷點多;
- Laplacian算子法對噪聲比較敏感,所以很少用該算子檢測邊緣,而是用來判斷邊緣像素視為與圖像的明區還是暗區;
- Canny方法不容易受噪聲干擾,能夠檢測到真正的弱邊緣。優點在於,使用兩種不同的閾值分別檢測強邊緣和弱邊緣,並且當弱邊緣和強邊緣相連時,才將弱邊緣包含在輸出圖像中。
二、邊緣復合增強
- Sobel、Robert、Prewitt算子的增強效果並不是很明顯,尤其是Robert算子,因為它提取的邊緣點過於稀疏和離散;
- Laplacian算子和canny算子的增強效果都比較理想, 將邊緣疊加上去后,整個手的輪廓和邊緣都很清晰,直觀上看,canny算子實現的效果比Laplacian算子好,最明顯的地方就是手指尖的邊緣。
3、程序實現
下面的程序就實現上面效果的完整Matlab代碼:
clear;clc; I=imread('x1.tif'); % I=rgb2gray(I); % gray transform J=imadjust(I,[0.1 0.9],[0 1],1); % Edge detection % Sobel BW1=edge(I,'sobel'); sobelBW1=im2uint8(BW1)+J; figure; %imshow(BW1); subplot(1,2,1); imshow(J); title('original image'); subplot(1,2,2); imshow(sobelBW1); title('Sobel augmented image'); % Roberts BW2=edge(I,'roberts'); robertBW2=im2uint8(BW2)+J; figure; %imshow(BW2); subplot(1,2,1); imshow(J); title('original image'); subplot(1,2,2); imshow(robertBW2); title('robert augmented image'); % prewitt BW3=edge(I,'prewitt'); prewittBW3=im2uint8(BW3)+J; figure; %imshow(BW3); subplot(1,2,1); imshow(J); title('original image'); subplot(1,2,2); imshow(prewittBW3); title('Prewitt augmented image'); % log BW4=edge(I,'log'); logBW4=im2uint8(BW4)+J; figure; %imshow(BW4); subplot(1,2,1); imshow(J); title('original image'); subplot(1,2,2); imshow(logBW4); title('Laplacian augmented image'); % canny BW5=edge(I,'canny'); cannyBW5=im2uint8(BW5)+J; figure; %imshow(BW5); subplot(1,2,1); imshow(J); title('original image'); subplot(1,2,2); imshow(cannyBW5); title('Canny augmented image'); % gaussian & canny % h=fspecial('gaussian',5); % fI=imfilter(I,h,'replicate'); % BW6=edge(fI,'canny'); % figure; % imshow(BW6); figure; subplot(2,3,1), imshow(BW1); title('sobel edge detect'); subplot(2,3,2), imshow(BW2); title('roberts edge detect'); subplot(2,3,3), imshow(BW3); title('prewitt edge detect'); subplot(2,3,4), imshow(BW4); title('log edge detect'); subplot(2,3,5), imshow(BW5); title('canny edge detect'); % subplot(2,3,6), imshow(BW6); % title('gasussian&canny edge detect'); figure; subplot(2,3,1), imshow(sobelBW1); title('sobel edge detect'); subplot(2,3,2), imshow(robertBW2); title('roberts edge detect'); subplot(2,3,3), imshow(prewittBW3); title('prewitt edge detect'); subplot(2,3,4), imshow(logBW4); title('laplacian edge detect'); subplot(2,3,5), imshow(cannyBW5); title('canny edge detect');
下面的Matlab程序是精簡的邊緣提取實現:
clear;clc;
I=imread('lena.bmp');
I=rgb2gray(I);
imshow(I,[]);
title('Original Image');
sobelBW=edge(I,'sobel');
figure;
imshow(sobelBW);
title('Sobel Edge');
robertsBW=edge(I,'roberts');
figure;
imshow(robertsBW);
title('Roberts Edge');
prewittBW=edge(I,'prewitt');
figure;
imshow(prewittBW);
title('Prewitt Edge');
logBW=edge(I,'log');
figure;
imshow(logBW);
title('Laplasian of Gaussian Edge');
cannyBW=edge(I,'canny');
figure;
imshow(cannyBW);
title('Canny Edge');