资源简介
该程序实现了基于matlab的canny算子的边缘检测,检测效果十分理想,已经尝试过,并且可以运行。
代码片段和文件信息
function e=canny_edge(Isigma)
%functione=edge(I‘canny‘threshsigma);
%该函数实现Canny算子提取边缘点
%输入图像为I,标准差sigma,输出为边缘图像e
I=255*double(I);%将图像转化为double型
[mn]=size(I);
Rr=2:m-1;cc=2:n-1;
e=repmat(logical(uint8(0))mn);
%产生同样大小的边缘图像e,初始化为1 ,即初始化边缘
GaussianDieOff=0.0001;%设定高斯函数消失门限
PercentOfPixelsNotEdges=0.7;%用于计算边缘门限
ThresholdRatio=0.2;%设置两个门限的比例
%首先设计高斯滤波器和它的微分
pw=1:30;
%设定滤波器宽度
ssq=sigma*sigma;
%计算方差
width = find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff1‘last‘);
if isempty(width)
width = 1; %当使用者键入很小的sigma时
end
%计算滤波算子宽度
t = (-width:width);
gau = exp(-(t.*t)/(2*ssq))/(2*pi*ssq); % 一维高斯滤波器
[xy]=meshgrid(-width:width-width:width);
dgau2D=-x.*exp(-(x.*x+y.*y)/(2*ssq))/(pi*ssq);%高斯滤波器的一阶导数
%平滑图像
aSmooth=imfilter(Igau‘conv‘‘replicate‘); % 按行滤波
aSmooth=imfilter(aSmoothgau‘‘conv‘‘replicate‘); % 再按列滤波
ax = imfilter(aSmooth dgau2D ‘conv‘‘replicate‘);
ay = imfilter(aSmooth dgau2D‘ ‘conv‘‘replicate‘);
mag=sqrt((ax.*ax)+(ay.*ay));
%计算滤波结果的幅度
magmax=max(mag(:));
if magmax>0
mag=mag/magmax;
%对滤波幅度进行归一化
end
%下面根据滤波幅度的概率密度计算滤波门限
[countsx]=imhist(mag64);
%计算滤波结果的幅度的直方图
highThresh=min(find(cumsum(counts)>PercentOfPixelsNotEdges*m*n))/64;
%通过设定非边缘点的比例来确定高门限
lowThresh=ThresholdRatio*highThresh;
%设置低门限为高门限乘以比例因子
thresh=[lowThreshhighThresh];
%下面进行非极大抑制
%大于高门限的点归于强边缘图像
%小于低门限的点归于弱边缘图像
idxStrong=[];
for dir=1:4
idxLocalMax=cannyFindLocalMaxima(diraxaymag);
idxWeak=idxLocalMax(mag(idxLocalMax)>lowThresh);
e(idxWeak)=1;
idxStrong=[idxStrong;idxWeak(mag(idxWeak)>highThresh)];
end
rstrong=rem(idxStrong-1m)+1;%rem是求余数
cstrong=floor((idxStrong-1)/m)+1;%向-∞取整
e=bwselect(ecstrongrstrong8);
%通过形态学算子将两幅图像的边缘进行连接
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Local Function : cannyFindLocalMaxima
%
function idxLocalMax = cannyFindLocalMaxima(directionixiymag)
%
% This sub-function helps with the non-maximum suppression in the Canny
% edge detector. The input parameters are:
%
% direction - the index of which direction the gradient is pointing
% read from the diagram below. direction is 1 2 3 or 4.
% ix
- 上一篇:史密斯圆图的matlab程序
- 下一篇:mclmcrrt8_3.dll
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论