matlab实时边缘检测sobel代码的简单介绍
admin 发布:2022-12-19 15:24 137
今天给各位分享matlab实时边缘检测sobel代码的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、急求 sobel算子检测边缘 Matlab程序代码
- 2、Matlab边缘检测问题
- 3、MATLAB 进行边缘检测进行到[gv1,vertical] = edge(f,'sobel','vertical');出错 求指导
- 4、关于图像处理,利用sobel算子边缘检测的Matlab程序
- 5、matlab canny算子边缘检测函数代码
- 6、matlab 图像边缘检测
急求 sobel算子检测边缘 Matlab程序代码
f=imread('peppers.png'); % 读入图像
f=rgb2gray(f); % 灰度转换
f=im2double(f); % 数据类型转换
% 使用垂直Sobel算子,自动选择阈值
[VSFAT Threshold]=edge(f,'sobel','vertical'); % 边缘探测
figure, imshow(f),title('Original Image'), % 显示原始图像
figure,imshow(VSFAT),title('Sobel Filter - Automatic Threshold'); % 显示边缘探测图像
%使用水平和垂直Sobel算子,自动选择阈值
SFST=edge(f,'sobel',Threshold);
figure,imshow(SFST),title('Sobel Filter (Horizontal and Vertical)'); % 显示边缘探测图像
%使用指定45度角Sobel算子滤波器,指定阈值
s45=[-2 -1 0;-1 0 1;0 1 2];
SFST45=imfilter(f,s45,'replicate');
SFST45=SFST45=Threshold;
figure,imshow(SFST45),title('Sobel Filter (45 Degree)'); % 显示边缘探测图像
%使用指定-45度角Sobel算子滤波器,指定阈值
sm45=[0 1 2;-1 0 1;-2 -1 0];
SFSTM45=imfilter(f,sm45,'replicate');
SFSTM45=SFSTM45=Threshold;
figure,imshow(SFSTM45),title('Sobel Filter (-45 Degree)'); % 显示边缘探测图像
Matlab边缘检测问题
用mesh语句似乎可以,具体也不了解你的情况,感觉怪怪的,发一段我以前些的程序,用罗伯特算子写的,把算子一改就是sobel了。两种边缘检测近似算法奉上:
clc
close all
clear all
%%%生成高斯平滑滤波模板%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
hg=zeros(3,3); %设定高斯平滑滤波模板的大小为3*3
delta=0.5;
for x=1:1:3
for y=1:1:3
u=x-2;
v=y-2;
hg(x,y)=exp(-(u^2+v^2)/(2*pi*delta^2));
end
end
h=hg/sum(hg(:));
%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%读入图像%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%
f = imread('1111.tif'); % 读入图像文件
f=rgb2gray(im2double(f));
imshow(f)
title('原始图像');
[m,n]=size(f);
ftemp=zeros(m,n);
rowhigh=m-1;
colhigh=n-1;
%%%高斯滤波%%%
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1); f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];
A=h.*mod;
ftemp(x,y)=sum(A(:));
end
end
f=ftemp
figure,imshow(f)
title('通过高斯滤波器后的图像');
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%利用roberts算子进行边缘检测%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sx=[-1 -2 -1;0 0 0;1 2 1];
sy=[-1 0 1;-2 0 2;-1 0 1];
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1); f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];
fsx=sx.*mod;
fsy=sy.*mod;
ftemp(x,y)=sqrt((sum(fsx(:)))^2+(sum(fsy(:)))^2);
end
end
fr=im2uint8(ftemp);
figure,imshow(fr)
title('用roberts算子边缘检测的原始图像');
%%%域值分割%%%
TH1=60; %设定阈值
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
if (fr(x,y)=TH1)((fr(x,y-1) = fr(x,y)) (fr(x,y) fr(x,y+1)) )
fr(x,y)=200;
elseif(fr(x,y)=TH1)( (fr(x-1,y) =fr(x,y)) (fr(x,y) fr(x+1,y)))
fr(x,y)=200;
else fr(x,y)=50;
end
end
end
figure,imshow(fr)
title('用roberts算子边缘检测并细化后的图像');
%%%%%%%%%%%%%%%%%%%%%%%%%%
利用第一种近似算法进行边缘检测%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%3*3的sobel算子%%%%%%%%
sx=[-1 -2 -1;0 0 0;1 2 1];
sy=[-1 0 1;-2 0 2;-1 0 1];
%sx=[0 1 2;-1 0 1;-2 -1 0];
%sy=[-2 -1 0;-1 0 1;0 1 2];
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1); f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];
fsx=sx.*mod;
fsy=sy.*mod;
ftemp(x,y)=abs(sum(fsx(:)))+abs(sum(fsy(:)));
end
end
fs=im2uint8(ftemp);
figure,imshow(fs)
title('用第一种近似算法进行边缘检测的原始图像');
%%%域值分割%%%
TH2=200; %设定阈值
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
if (fs(x,y)=TH2)((fs(x,y-1) = fs(x,y)) (fs(x,y) fs(x,y+1)) )
fs(x,y)=200;
elseif(fs(x,y)=TH2)( (fs(x-1,y) =fs(x,y)) (fs(x,y) fs(x+1,y)))
fs(x,y)=200;
else fs(x,y)=50;
end
end
end
figure,imshow(fs)
title('采用第一种近似算法进行边缘检测后的图像');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%利用第二种近似算法进行边缘检测%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%3*3的sobel算子%%%%%%%%
sx=[-1 -2 -1;0 0 0;1 2 1];
sy=[-1 0 1;-2 0 2;-1 0 1];
%sx=[0 1 2;-1 0 1;-2 -1 0];
%sy=[-2 -1 0;-1 0 1;0 1 2];
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
mod=[f(x-1,y-1) f(x-1,y) f(x-1,y+1); f(x,y-1) f(x,y) f(x,y+1);f(x+1,y-1) f(x+1,y) f(x+1,y+1)];
fsx=sx.*mod;
fsy=sy.*mod;
ftemp(x,y)=max(abs(sum(fsx(:))),abs(sum(fsy(:))));
end
end
fs=im2uint8(ftemp);
figure,imshow(fs)
title('用第二种近似算法进行边缘检测的原始图像');
%%%域值分割%%%
TH2=200; %设定阈值
for x=2:1:rowhigh-1
for y=2:1:colhigh-1
if (fs(x,y)=TH2)((fs(x,y-1) = fs(x,y)) (fs(x,y) fs(x,y+1)) )
fs(x,y)=200;
elseif(fs(x,y)=TH2)( (fs(x-1,y) =fs(x,y)) (fs(x,y) fs(x+1,y)))
fs(x,y)=200;
else fs(x,y)=50;
end
end
end
figure,imshow(fs)
title('采用第二种近似算法进行边缘检测后的图像');
MATLAB 进行边缘检测进行到[gv1,vertical] = edge(f,'sobel','vertical');出错 求指导
从提示看,脚本中定义函数,不允许。但从你贴上来程序看,又没有定义函数,可能你只复制了部分程序,不是完整程序。
关于图像处理,利用sobel算子边缘检测的Matlab程序
这很明显啊,你没有定义g函数。看你程序的意思是先检测出边缘,因为边缘中的线都是白色的,然后就是用for 和 if语句把边缘经过处理,也就是将边缘中白色点变为g,这就要看你具体想以何种方式增强了,如果是对数变换的话,你可以先让g(:,:)=log((ps(:,:))+1)(将这条语句放在for语句的上面);这样增强的结果就是扩展低值灰度,压缩高值灰度,当然了,还有很多其它增强方法,你可以具体再找找图像增强这方面的资料。
matlab canny算子边缘检测函数代码
I = imread('lena.bmp'); %%如果是其他类型图像,请先转换为灰度图
%%没有噪声时的检测结果
BW_sobel = edge(I,'sobel');
BW_prewitt = edge(I,'prewitt');
BW_roberts = edge(I,'roberts');
BW_laplace = edge(I,'log');
BW_canny = edge(I,'canny'); figure(1);
subplot(2,3,1),imshow(I),xlabel('原始图像');
subplot(2,3,2),imshow(BW_sobel),xlabel('sobel检测');
subplot(2,3,3),imshow(BW_prewitt),xlabel('prewitt检测');
subplot(2,3,4),imshow(BW_roberts),xlabel('roberts检测');
subplot(2,3,5),imshow(BW_laplace),xlabel('laplace检测');
subplot(2,3,6),imshow(BW_canny),xlabel('canny检测');
%%加入高斯噪声(μ=0,σ^2=0.01)检测结果
I_g1 = imnoise(I,'gaussian',0,0.01);
BW_sobel = edge(I_g1,'sobel');
BW_prewitt = edge(I_g1,'prewitt');
BW_roberts = edge(I_g1,'roberts');
BW_laplace = edge(I_g1,'log');
BW_canny = edge(I_g1,'canny'); figure(2);
subplot(2,3,1),imshow(I_g1),xlabel('加入高斯噪声(μ=0,σ^2=0.01)图像');
subplot(2,3,2),imshow(BW_sobel),xlabel('sobel检测');
subplot(2,3,3),imshow(BW_prewitt),xlabel('prewitt检测');
subplot(2,3,4),imshow(BW_roberts),xlabel('roberts检测');
subplot(2,3,5),imshow(BW_laplace),xlabel('laplace检测');
subplot(2,3,6),imshow(BW_canny),xlabel('canny检测');
%%加入高斯噪声(μ=0,σ^2=0.02)检测结果
I_g2 = imnoise(I,'gaussian',0,0.02);
BW_sobel = edge(I_g2,'sobel');
BW_prewitt = edge(I_g2,'prewitt');
BW_roberts = edge(I_g2,'roberts');
BW_laplace = edge(I_g2,'log');
BW_canny = edge(I_g2,'canny'); figure(3);
subplot(2,3,1),imshow(I_g2),xlabel('加入高斯噪声(μ=0,σ^2=0.02)图像');
subplot(2,3,2),imshow(BW_sobel),xlabel('sobel检测');
subplot(2,3,3),imshow(BW_prewitt),xlabel('prewitt检测');
subplot(2,3,4),imshow(BW_roberts),xlabel('roberts检测');
subplot(2,3,5),imshow(BW_laplace),xlabel('laplace检测');
subplot(2,3,6),imshow(BW_canny),xlabel('c
一、没有噪声时的检测结果 1 原始图像
2 Sobel算子边缘检测 3 Prewitt算子边缘检测 4 Roberts算子边缘检测 5 Laplace算子边缘检测 6 Canny算子边缘检测
二、加入高斯噪声(μ=0,σ^2=0.01)检测结果 1 原始图像
2 Sobel算子边缘检测 3 Prewitt算子边缘检测 4 Roberts算子边缘检测 5 Laplace算子边缘检测 6 Canny算子边缘检测
三、加入高斯噪声(μ=0,σ^2=0.02)检测结果 1 原始图像
2 Sobel算子边缘检测 3 Prewitt算子边缘检测 4 Roberts算子边缘检测 5 Laplace算子边缘检测 6 Canny算子边缘检测
clear all; close all;
warning off all;
matlab 图像边缘检测
你把这行代码BW3=edge(I,'soble'); 改成BW3=edge(I,'sobel');就可以运行了,我试过了,这地方拼写错了,所以无法运行。
matlab实时边缘检测sobel代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、matlab实时边缘检测sobel代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-18百度搜索风云榜官网,百度搜索风云榜实时热点
- 05-17百度搜索大数据查询,百度实时大数据
- 05-17网站检测,网站检测工具有哪些
- 05-17做公司网页,做公司网页有什么简单的方法
- 05-12深圳seo公司的简单介绍
- 05-11设计一个简单的网页,独立站建站平台有哪些
- 05-09网页代码,网页代码快捷键
- 05-09hao123网址之家官网的简单介绍
- 05-07孝感seo的简单介绍
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接