当前位置:首页 > 代码 > 正文

sobel算子matlab代码(sobel matlab)

admin 发布:2022-12-19 17:10 143


今天给各位分享sobel算子matlab代码的知识,其中也会对sobel 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)'); % 显示边缘探测图像

求8方向的sobel算子在matlab中的源代码

int t0,t1,t2,t3,t4,t5,t6,t7;/////sobel模板的八个邻域值

int ab1,ab2,ab3,ab4,ma,ma1,ma2;

int m_max_ab=0;

if(m_Img_sobel!=NULL)

{

delete []m_Img_sobel;

m_Img_sobel=NULL;

}

m_Img_sobel=new unsigned char[aLineByte*aHeight];

if(m_iBitCount!=8)

{

// AfxMessageBox("sobel只处理灰度图,请先转换成灰度图");

return false;

}

else

{

for(int h=2;haHeight-1;h++)

{

for(int w=2;waWidth-1;w++)

{

if(*(aImg_zone+h*aLineByte+w)=150*(aImg_zone+h*aLineByte+w)=200)

{

m_max_ab=0;

t0=*(aImgData+(h-1)*aLineByte+(w-1));

t1=*(aImgData+(h-1)*aLineByte+(w));

t2=*(aImgData+(h-1)*aLineByte+(w+1));

t3=*(aImgData+(h)*aLineByte+(w+1));

t4=*(aImgData+(h+1)*aLineByte+(w+1));

t5=*(aImgData+(h+1)*aLineByte+(w));

t6=*(aImgData+(h+1)*aLineByte+(w-1));

t7=*(aImgData+h*aLineByte+(w-1));

ab1=(t0+2*t1+t2)-(t4+2*t5+t6);

if(ab10)

{

ab1=-ab1;

}

ab2=(t0+2*t7+t6)-(t2+2*t3+t4);

if(ab20)

{

ab2=-ab2;

}

ab3=(t0*2+t1+t7)-(t4*2+t3+t5);

if(ab30)

{

ab3=-ab3;

}

ab4=abs((t1+t2*2+t3)-(t5+t6*2+t7));

ma2=max(ab3,ab4);

ma=max(ab1,ab2);

if(ma0)

{

if(ma=255)

{

*(m_Img_sobel+h*aLineByte+w)=ma;

}

else

{

*(m_Img_sobel+h*aLineByte+w)=255;

}

}

else

{

*(m_Img_sobel+h*aLineByte+w)=0;

}

}

}

}

}

关于图像处理,利用sobel算子边缘检测的Matlab程序

这很明显啊,你没有定义g函数。看你程序的意思是先检测出边缘,因为边缘中的线都是白色的,然后就是用for 和 if语句把边缘经过处理,也就是将边缘中白色点变为g,这就要看你具体想以何种方式增强了,如果是对数变换的话,你可以先让g(:,:)=log((ps(:,:))+1)(将这条语句放在for语句的上面);这样增强的结果就是扩展低值灰度,压缩高值灰度,当然了,还有很多其它增强方法,你可以具体再找找图像增强这方面的资料。

关于sobel算子matlab代码和sobel matlab的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/14963.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载