请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 4134|回复: 0

kirsch方向算子

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2017-2-5 12:06:20 | 显示全部楼层 |阅读模式
     Roberts算子、Prewitt算子、Sobel算子都只包含两个方向的模板,每种模板只对相应的方向敏感,对该方向上的变化有明显的输出,而对其他方向的变化响应不大。为了检测各个方向的边缘,需要有各个方向的微分模板。8个方向的kirsch模板较为常用,这8个方向依次成45夹角
   用卷积函数conv2处理的MATLAB程序代码:
  1. %% kirsch模板  方向算子
  2. clc,clear,close all                    % 清屏、清工作区、关闭窗口
  3. warning off                         % 消除警告
  4. feature jit off                        % 加速代码执行
  5. [filename ,pathname]=...
  6.     uigetfile({'*.bmp';'*.jpg';},'选择图片');                         %选择图片路径
  7. str = [pathname filename];                                                %合成路径+文件名
  8. im = imread(str);                                                          % 读图   
  9. % i= rgb2gray(im);
  10.     hsi=rgb2hsi(im);
  11.     H = hsi(:, :, 1);
  12.     S = hsi(:, :, 2);
  13.     I = hsi(:, :, 3);
  14.     a= I;
  15. a = medfilt2(a,[5,5]);                                                  % 中值滤波
  16. b=[-5 3 3;-5 0 3;-5 3 3]/1512;
  17. c=[3 3 3;-5 0 3;-5 -5 3]/1512;
  18. d=[3 3 3;3 0 3;-5 -5 -5]/1512;
  19. e=[3 3 3;3 0 -5; 3 -5 -5]/1512;
  20. f=[3 3 -5;3 0 -5;3 3 -5]/1512;
  21. g=[3 -5 -5;3 0 -5;3 3 3]/1512;
  22. h=[-5 -5 -5;3 0 3;3 3 3]/1512;
  23. i=[-5 -5 3;-5 0 3;3 3 3]/1512;
  24. b=conv2(a,b,'same');b=abs(b);
  25. c=conv2(a,c,'same');c=abs(c);
  26. d=conv2(a,d,'same');d=abs(d);
  27. e=conv2(a,e,'same');e=abs(e);
  28. f=conv2(a,f,'same');f=abs(f);
  29. g=conv2(a,g,'same');g=abs(g);
  30. h=conv2(a,h,'same');h=abs(h);
  31. i=conv2(a,i,'same');i=abs(i);
  32. p=max(b,c);
  33. p=max(d,p);
  34. p=max(e,p);
  35. p=max(f,p);
  36. p=max(g,p);
  37. p=max(h,p);
  38. p=max(i,p);
  39. figure,
  40. subplot(2,4,1),imshow(b,[]),
  41. subplot(2,4,2),imshow(c,[]),
  42. subplot(2,4,3),imshow(d,[]),
  43. subplot(2,4,4),imshow(e,[]),
  44. subplot(2,4,5),imshow(f,[]),
  45. subplot(2,4,6),imshow(g,[]),
  46. subplot(2,4,7),imshow(h,[]),
  47. subplot(2,4,8),imshow(i,[])
  48. figure,
  49. subplot(121),imshow(im,[]);title('原始图像')
  50. subplot(122),imshow(p,[]);title('kirsch模板')
复制代码





算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 13:16 , Processed in 0.217717 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表