canny算子边缘检测canny算子边缘检测
canny算子边缘检测,详细地代码,希望对大家有帮助
function CVHomework1
% r = imread('132194.jpg');
% I=rgb2gray(r);
I = imread('rice.png');
BW = canny_edge(I, 1.7);
figure,imshow(I)
figure,imshow(BW)
% Canny边缘检测的函数
% Input:
% a: input image
% sigma: Gaussian的均方差
function e=canny_edge(a,sigma)
a = double(a); % 将图像像素数据转换为double类型
[m,n] = size(a);
e = repmat(logical(uint8(0)),m,n);% 生成初始矩阵
OffGate = 0.0001;
Perc = 0.7;
Th = 0.4;
pw = 1:30;% hardcoding. But it's large enough if sigma isn't too large

sig2 = sigma * sigma;% 方差
width = max(find(exp(-(pw.*pw)/(2*sig2)) > OffGate));% 寻找截断点
t = (-width:width);
len = 2*width+1;
t3=[t-0.5;t;t+0.5];
dgau = (-t.*exp(-(t.*t)/(2*sig2))/sig2).'; % 一阶高斯函数的导数
ra = size(a,1);% 图像行数
ca = size(a,2);% 图像列数
ay = 255*a;
ax = 255*a';
完整见附件
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-37358-1.html
很对