matlabsobel边缘检测代码(log算子边缘检测 matlab代码)
admin 发布:2022-12-19 17:57 176
今天给各位分享matlabsobel边缘检测代码的知识,其中也会对log算子边缘检测 matlab代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、关于图像处理,利用sobel算子边缘检测的Matlab程序
- 2、matlab canny算子边缘检测函数代码是什么?
- 3、用Sobel算子、Roberts算子、Prewitt算子对图像进行边缘检测的程序,在matlab环境下,程序要完整,最好有图
- 4、Matlab边缘检测问题
- 5、急求 sobel算子检测边缘 Matlab程序代码
关于图像处理,利用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;
用Sobel算子、Roberts算子、Prewitt算子对图像进行边缘检测的程序,在matlab环境下,程序要完整,最好有图
close all
clear all
I=imread('tig.jpg'); %读取图像
I1=im2double(I); %将彩图序列变成双精度
I2=rgb2gray(I1); %将彩色图变成灰色图
[thr, sorh, keepapp]=ddencmp('den','wv',I2);
I3=wdencmp('gbl',I2,'sym4',2,thr,sorh,keepapp); %小波除噪
I4=medfilt2(I3,[9 9]); %中值滤波
I5=imresize(I4,0.2,'bicubic'); %图像大小
BW1=edge(I5,'sobel'); %sobel图像边缘提取
BW2=edge(I5,'roberts'); %roberts图像边缘提取
BW3=edge(I5,'prewitt'); %prewitt图像边缘提取
BW4=edge(I5,'log'); %log图像边缘提取
BW5=edge(I5,'canny'); %canny图像边缘提取
h=fspecial('gaussian',5); %高斯滤波
BW6=edge(I5,'zerocross',[ ],h); %zerocross图像边缘提取
figure;
subplot(1,3,1); %图划分为一行三幅图,第一幅图
imshow(I2); %绘图
figure;
subplot(1,3,1);
imshow(BW1);
title('Sobel算子');
subplot(1,3,2);
imshow(BW2);
title('Roberts算子');
subplot(1,3,3);
imshow(BW3);
title('Prewitt算子');
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('采用第二种近似算法进行边缘检测后的图像');
急求 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)'); % 显示边缘探测图像
matlabsobel边缘检测代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于log算子边缘检测 matlab代码、matlabsobel边缘检测代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-17网站检测,网站检测工具有哪些
- 05-09网页代码,网页代码快捷键
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06代码源软件库(程序代码库)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接