⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myedge_sobel.m

📁 该压缩包的程序实现对图像的边缘进行检测
💻 M
字号:
function pedge_sobel=myedge_sobel(pmat)
%sobel算子检测图像边缘
[row col]=size(pmat);   %原始图像的大小
%对图像进行零填充
pfilled=zeros(row+2,col+2);
pfilled(2:row+1,2:col+1)=pmat;
%定义模板
M1=[-1 0 1;-2 0 2;-1 0 1];
M2=[-1 -2 -1;0 0 0;1 2 1];
%计算各点的灰度值
pedge_sobel=zeros(row,col);
for i=1:row
    for j=1:col
        array=[pfilled(i,j) pfilled(i,j+1) pfilled(i,j+2);pfilled(i+1,j) pfilled(i+1,j+1) pfilled(i+1,j+2);pfilled(i+2,j) pfilled(i+2,j+2) pfilled(i+2,j+2)];
        psx=sum(sum(M1.*array));
        psy=sum(sum(M2.*array));
        psx=double(psx);
        psy=double(psy);
        pedge_sobel(i,j)=sqrt(psx^2+psy^2);
    end
end
%转换为图像格式
pedge_sobel=uint8(pedge_sobel);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -