资源简介
基于图像边缘检测的Canny算法,梯度幅值和角度,进行非极大值抑制
代码片段和文件信息
clear;
close all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%
%%%Input parameters%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
MaskSize = 3;
Sigma = 5; %(for Gaussian)
Threshold = 0.30; %(building brick 0.13 monkey 0.22 lena0.18 building outline )
% ThresholdRatio = 0;
ThresholdRatio = 1e-40;
%==========================================================================
%===================Opening the files of images============================
%==========================================================================
[filename pathname]=uigetfile({‘*.jpg‘;...
‘*.bmp‘;...
‘*.gif‘;...
‘*.png‘;...
‘*.tif‘}...
‘Open the files of images‘);
if filename~=0
openfilename = strcat(pathnamefilename); %processing diversified forms of images
eval([‘info=imfinfo(‘‘‘openfilename ‘‘‘);‘]);
switch info.ColorType
case ‘truecolor‘
eval([‘RGB = imread(‘‘‘openfilename ‘‘‘);‘]); %[X map] = rgb2ind(RGB 256);
InImg = rgb2gray(RGB);
clear RGB;
case ‘indexed‘
eval([‘[X map] = imread(‘‘‘openfilename ‘‘‘);‘]);
InImg = ind2gray(X map);
clear X;
case ‘grayscale‘
eval([‘InImg = imread(‘‘‘openfilename ‘‘‘);‘]);
end
else
return;
end
st = cputime;
% subplot(211);imagesc(InImg);title(‘lotus picture‘);
InImg = double(InImg);
[rows cols] = size(InImg);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate Filtered Gradient
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GausDer_x = ones(MaskSizeMaskSize);
GausDer_y = ones(MaskSizeMaskSize);
Amp=-1/sqrt(2*pi*Sigma);
for g_x=1:MaskSize;
for g_y=1:MaskSize;
x = g_x-(MaskSize+1)/2;
y = g_y-(MaskSize+1)/2;
GausDer_x(g_xg_y)=Amp*(x/Sigma^2).*exp(-(x^2+y^2)/(2*Sigma^2));
GausDer_y(g_xg_y)=Amp*(y/Sigma^2).*exp(-(x^2+y^2)/(2*Sigma^2)); %derivative of a Gaussian
end
end
GausDer_x(g_xg_y) = sum(sum(GausDer_x(g_xg_y)));
GausDer_y(g_xg_y) = sum(sum(GausDer_x(g_xg_y))); %normalization
Img_gx = conv2(InImgGausDer_x‘same‘);
Img_gy = conv2(InImgGausDer_y‘same‘);
F = sqrt(Img_gx.*Img_gx+Img_gy.*Img_gy); %the magnitude of the gradient
D = atan(Img_gy./Img_gx); %edge orientation of the gradient
figure(1);
subplot(121);
imagesc(F);
title(‘Gradient Amplitude‘);
subplot(122);
imagesc(D);
title(‘Gradient Angle‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Nonmaximum suppression
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
EdgGrad = zeros(rows cols);
EdgDirc = zeros(rows cols);
for i = 2: (rows-1)
for j = 2: (cols-1)
switch fix(8*D(ij)/pi)
case 0 % from 0 - pi/8 and 7pi/8 -pi
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-06-09 14:05 53623196Cmp_vis_canny\
文件 7315 2018-06-09 10:56 53623196Cmp_vis_canny\Cmp_vis_canny.m
文件 30046 2018-06-09 11:00 53623196Cmp_vis_canny\edge detection.jpg
文件 460040 2018-06-09 10:59 53623196Cmp_vis_canny\edge gradient.fig
文件 136304 2018-06-09 11:00 53623196Cmp_vis_canny\edge gradient.jpg
文件 11914 2006-08-09 11:57 53623196Cmp_vis_canny\flower.jpg
文件 2120064 2018-06-09 10:57 53623196Cmp_vis_canny\gradient.fig
文件 147180 2018-06-09 11:00 53623196Cmp_vis_canny\gradient.jpg
文件 26152 2018-06-09 10:21 53623196Cmp_vis_canny\lotus.jpg
文件 25586 2018-06-09 11:01 53623196Cmp_vis_canny\unti
- 上一篇:驱动2.0.7z
- 下一篇:DWM1000中文版数据手册
相关资源
- 改进的自适应阈值Canny边缘检测
- Hausdorff距离匹配代码
- Canny算子分割遥感影像
- A Computational Approach to Edge Detection
- canny经典论文 原文
- Canny算子源代码
- 基于机器视觉的列车前方障碍物检测
- 基于canny算子和光流法的运动目标检测
- 《图像分割--canny算子》超详细PPT,适
- 基于边缘检测的canny算法
- 论文研究-基于改进的Canny算子的焊缝
- 基于Qt与OpenCV的图片读取、保存,并利
- ENVI/IDL环境下的CANNY算法
- 一种改进的基于Canny算子的图像边缘提
- Log和Canny边缘检测算子
- 用CANNY算子提取边缘
- Canny边缘检测基本原理.doc
评论
共有 条评论