Hello Mat

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

fspecial滤波算子

[复制链接]

1323

主题

1551

帖子

0

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22647
发表于 2017-3-8 23:25:43 | 显示全部楼层 |阅读模式
  1. function h = fspecial(type,p2)

  2. if nargin < 2
  3.     switch type
  4.         case 'average'
  5.         p2 = [3 3];  % siz
  6.     case 'disk'
  7.         p2 = 5;      % rad
  8.     end
  9. end

  10. switch type
  11.   case 'average' % Smoothing filter
  12.      siz = p2;
  13.      h   = ones(siz)/prod(siz);

  14.   case 'disk' % Disk filter
  15.      rad   = p2;
  16.      crad  = ceil(rad-0.5);
  17.      [x,y] = meshgrid(-crad:crad,-crad:crad);
  18.      maxxy = max(abs(x),abs(y));
  19.      minxy = min(abs(x),abs(y));
  20.      m1 = (rad^2 <  (maxxy+0.5).^2 + (minxy-0.5).^2).*(minxy-0.5) + ...
  21.           (rad^2 >= (maxxy+0.5).^2 + (minxy-0.5).^2).* ...
  22.                 sqrt(rad^2 - (maxxy + 0.5).^2);
  23.      m2 = (rad^2 >  (maxxy-0.5).^2 + (minxy+0.5).^2).*(minxy+0.5) + ...
  24.           (rad^2 <= (maxxy-0.5).^2 + (minxy+0.5).^2).* ...
  25.            sqrt(rad^2 - (maxxy - 0.5).^2);
  26.      sgrid = (rad^2*(0.5*(asin(m2/rad) - asin(m1/rad)) + ...
  27.              0.25*(sin(2*asin(m2/rad)) - sin(2*asin(m1/rad)))) - ...
  28.              (maxxy-0.5).*(m2-m1) + (m1-minxy+0.5)) ...
  29.                   .*((((rad^2 < (maxxy+0.5).^2 + (minxy+0.5).^2) & ...
  30.              (rad^2 > (maxxy-0.5).^2 + (minxy-0.5).^2)) | ...
  31.                   ((minxy==0)&(maxxy-0.5 < rad)&(maxxy+0.5>=rad))));
  32.      sgrid = sgrid + ((maxxy+0.5).^2 + (minxy+0.5).^2 < rad^2);
  33.      sgrid(crad+1,crad+1) = min(pi*rad^2,pi/2);
  34.      if ((crad>0) && (rad > crad-0.5) && (rad^2 < (crad-0.5)^2+0.25))
  35.         m1  = sqrt(rad^2 - (crad - 0.5).^2);
  36.              m1n = m1/rad;
  37.         sg0 = 2*(rad^2*(0.5*asin(m1n) + 0.25*sin(2*asin(m1n)))-m1*(crad-0.5));
  38.         sgrid(2*crad+1,crad+1) = sg0;
  39.         sgrid(crad+1,2*crad+1) = sg0;
  40.         sgrid(crad+1,1)        = sg0;
  41.         sgrid(1,crad+1)        = sg0;
  42.         sgrid(2*crad,crad+1)   = sgrid(2*crad,crad+1) - sg0;
  43.         sgrid(crad+1,2*crad)   = sgrid(crad+1,2*crad) - sg0;
  44.         sgrid(crad+1,2)        = sgrid(crad+1,2)      - sg0;
  45.         sgrid(2,crad+1)        = sgrid(2,crad+1)      - sg0;
  46.      end
  47.      sgrid(crad+1,crad+1) = min(sgrid(crad+1,crad+1),1);
  48.      h = sgrid/sum(sgrid(:));

  49. end
  50.   
  51. end
复制代码


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-22 22:52 , Processed in 0.217794 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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