函式edge():查找強度影像的邊緣

常用函式說明:
BW = edge(I) 回傳二值影像 BW,其中的值 1 對應于輸入影像 I 中函式找到邊緣的位置,值 0 對應于其他位置,默認情況下,edge 使用 Sobel 邊緣檢測方法,
BW = edge(I,method) 使用 method 指定的邊緣檢測演算法檢測影像 I 中的邊緣,
BW = edge(I,method,threshold) 回傳強度高于 threshold 的所有邊緣,
BW = edge(I,method,threshold,direction) 指定要檢測的邊緣的方向,Sobel 和 Prewitt 方法可以檢測垂直方向和/或水平方向的邊緣,Roberts 方法可以檢測與水平方向成 45 度角和/或 135 度角的邊緣,僅當 method 是 'Sobel'、'Prewitt' 或 'Roberts' 時,此語法才有效,
邊緣檢測所涉及的method如下:

學習后變成實作的小練習:
clear all
clc
I=imread('cameraman.tif');
figure(1)
subplot(1,2,1)
imshow(I);
title('原始影像');
BW=edge(I,'sobel');
subplot(1,2,2)
imshow(BW);
title('邊緣檢測')
[BW,thresh]=edge(I,'sobel');
disp('Sobel演算法自動選擇的閾值為:')
disp(thresh);
figure(2)
BW1=edge(I,'sobel',0.02,'horizontal');
subplot(2,2,1)
imshow(BW1);
title('水平方向閾值為0.02')
BW2=edge(I,'sobel',0.02,'vertical');
subplot(2,2,2)
imshow(BW2)
title('垂直方向閾值為0.02')
BW3=edge(I,'sobel',0.05,'horizontal');
subplot(2,2,3)
imshow(BW3)
title('水平方向閾值為0.05')
BW4=edge(I,'sobel',0.05,'vertical');
subplot(2,2,4)
imshow(BW4)
title('垂直方向閾值為0.05')
效果圖如下:


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/384428.html
標籤:其他
