Sobel算子matlab实现 分类: 图像处理 2...

算子实际上是用来对图像进行卷积处理,其本质是用变分法来处理梯度问题,用途就是边缘检测。45度和135度效果一般,水平检测加垂直检测效果还可以。


function Sobel(name,Threshold)
  f = imread(name);
  f = rgb2gray(f);
  f = im2double(f);
  subplot(231);
  
  imshow(f),title('rawpicture');
  
  a45 = [-2 -1 0;
       -1  0 1;
        0  1 2];
   Sobel45 = imfilter(f,a45,'replicate');
   Sobel45 = Sobel45>=Threshold;
   subplot(232);
   imshow(Sobel45),title('45 Sobel edge detect');
   
   a135 = [0 -1 -2;
          1  0 -1;
          2  1  0];
    Sobel135 = imfilter(f,a135,'replicate');
    Sobel135 = Sobel135>=Threshold; 
    subplot(233);
    imshow(Sobel135),title('135 Sobel edge detect');
    
    [Vertical,Threshold] = edge(f,'sobel', 'vertical');
    subplot(234);
    imshow(Vertical),title('Vertical Sobel edge detect')
    
    [Horizontal,Threshold] = edge(f,'sobel','horizontal');
    subplot(235);
    imshow(Horizontal),title('Horizontal Sobel edge detect');
    
    HandV = edge(f,'sobel',Threshold);
    subplot(236);
    imshow(HandV),title('Horizontal and Vertical Sobel edge detect');
    
    sobell=edge(f,'sobel');
    figure(2),subplot(121),imshow(HandV);
    subplot(122),imshow(sobell);
 
      
end








版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/learnordie/p/4657021.html

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值