声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1905|回复: 2

[图像处理] 关于Matlab的RX算法,请教注释的几个问题

[复制链接]
发表于 2010-3-9 16:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  1. % %%%%%%%%%%%%%%%%%%%%%%%%%%% 初始化参数

  2. function RXdet = RX(A,winlenth,shape)

  3. %这3个参数应该是指图像矩阵,波段数,第三个是什么呢???????????????????????????????
  4. %一下的shape都是什么意思?

  5. switch shape
  6. case 0
  7. target_spatial=[0 0 1 0 0;
  8. 0 0 1 0 0;
  9. 1 1 1 1 1;
  10. 0 0 1 0 0;
  11. 0 0 1 0 0];
  12. case 1
  13. target_spatial=[1 0 1;
  14. 0 1 0;
  15. 1 0 1];
  16. case 2
  17. target_spatial=[1 0 0 0 1; %%% 主程序中取shape=2
  18. 0 1 0 1 0;
  19. 0 0 1 0 0;
  20. 0 1 0 1 0;
  21. 1 0 0 0 1];
  22. case 3
  23. target_spatial=[1 0 0 0 0 0 1
  24. 0 1 0 0 0 1 0;
  25. 0 0 1 0 1 0 0;
  26. 0 0 0 1 0 0 0;
  27. 0 0 1 0 1 0 0
  28. 0 1 0 0 0 1 0
  29. 1 0 0 0 0 0 1];
  30. otherwise
  31. disp('Unknown shape.')
  32. end

  33. SizeA=size(A);
  34. if length(SizeA)==2 %% 若为二维图象,将其看作一幅第三维为1的三维图象
  35. SizeA(3) = 1;
  36. end

  37. %这一段是什么东西????????????????????????????????????????????????

  38. AA((winlenth+1)/2:(winlenth-1)/2+SizeA(1), (winlenth+1)/2:(winlenth-1)/2+SizeA(2),:)=A; %中
  39. AA((winlenth-1)/2:-1:1,(winlenth+1)/2:(winlenth-1)/2+SizeA(2),:)=A(1:(winlenth-1)/2,:,:); %上
  40. AA(winlenth-1+SizeA(1):-1:(winlenth+1)/2+SizeA(1),(winlenth+1)/2:(winlenth-1)/2+SizeA(2),:)...%下
  41. =A(SizeA(1)-(winlenth-3)/2:SizeA(1),:,:); %
  42. AA((winlenth+1)/2:(winlenth-1)/2+SizeA(1),(winlenth-1)/2:-1:1,:)=A(:,1:(winlenth-1)/2,:); %左
  43. AA((winlenth+1)/2:(winlenth-1)/2+SizeA(1),winlenth-1+SizeA(2):-1:(winlenth+1)/2+SizeA(2),:)...%右
  44. =A(:,SizeA(2)-(winlenth-3)/2:SizeA(2),:); %
  45. AA((winlenth-1)/2:-1:1,(winlenth-1)/2:-1:1,:)=A(1:(winlenth-1)/2,1:(winlenth-1)/2,:); %左上
  46. AA(winlenth-1+SizeA(1):-1:(winlenth+1)/2+SizeA(1),winlenth-1+SizeA(2):-1:(winlenth+1)/2+... %右下
  47. SizeA(2),:)=A(SizeA(1)-(winlenth-3)/2:SizeA(1),SizeA(2)-(winlenth-3)/2:SizeA(2),:); %
  48. AA(winlenth-1+SizeA(1):-1:(winlenth+1)/2+SizeA(1),(winlenth-1)/2:-1:1,:)... %左下
  49. =A(SizeA(1)-(winlenth-3)/2:SizeA(1),1:(winlenth-1)/2,:); %
  50. AA((winlenth-1)/2:-1:1,winlenth-1+SizeA(2):-1:(winlenth+1)/2+SizeA(2),:)... %右上
  51. =A(1:(winlenth-1)/2,SizeA(2)-(winlenth-3)/2:SizeA(2),:); %

  52. clear A;

  53. spatial_pattern=zeros(winlenth,winlenth);
  54. spatial_pattern((winlenth-3)/2:(winlenth+5)/2,(winlenth-3)/2:(winlenth+5)/2)=target_spatial;
  55. s=zeros(1,winlenth*winlenth);
  56. for i=1:winlenth
  57. for j=1:winlenth
  58. s((i-1)*winlenth+j)=spatial_pattern(i,j);
  59. end
  60. end
  61. %%%%%%%%%%%%%%%%%%%%%%%%%% RX运算%%%%%%%%
  62. %【滑】 【动】 【窗】 【去均值】???????????????????
  63. for i=(winlenth+1)/2:(winlenth-1)/2+SizeA(1)
  64. for j=(winlenth+1)/2:(winlenth-1)/2+SizeA(2)
  65. AAA=AA(i-(winlenth-1)/2:i+(winlenth-1)/2,j-(winlenth-1)/2:j+(winlenth-1)/2,:);%滑
  66. x=[];

  67. xn=zeros(SizeA(3),1);

  68. for m=1:winlenth
  69. for n=1:winlenth %动
  70. xn(:)=AAA(m,n,:);
  71. x=[x,xn];
  72. end
  73. end %窗

  74. WinMean=mean(x,2);
  75. WinCov=cov(x');
  76. % WinCov(1,1)
  77. InvCov=inv(WinCov);
  78. clear WinCov;

  79. for n=1:winlenth*winlenth %去均值
  80. x(:,n)=x(:,n)-WinMean;
  81. end %
  82. % figure,imshow();
  83. xx=x*s';
  84. RXdet(i-(winlenth-1)/2,j-(winlenth-1)/2)=xx'*InvCov*xx/(s*s');
  85. end
  86. end
  87. figure,imshow(RXdet,[]);
复制代码
以上部分不能懂,望能看得懂的帮帮我呀!

PS:RX算法公式
dis = (r-u)'*inv(cov)*(r-u),
    “其中
    r为判别点向量,
    u为背景区域样本均值,
    cov为背景区域样本协方差矩阵。”
处理的对象是3维图像,(高光谱图像),包括宽度*高度*波段数;

如果背景方面不了解的只是从公式的角度也可以稍微解释下上边的代码,谢谢各位!

[ 本帖最后由 yangfanxing__ 于 2010-3-9 16:25 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2010-3-11 16:28 | 显示全部楼层
问题搁浅。。。顶顶吧~
发表于 2013-3-15 17:06 | 显示全部楼层
您好
我现在在做高光谱图像的异常检测,我看到了您之前的帖子,请问现在您还有RX算法或者相关算法的代码吗?我刚入门,好多东西自己都找不到,请您帮帮我。我的邮箱是183541477@qq.com,请您把相关资料发给我,真的非常感谢。祝您一切顺利。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-17 19:42 , Processed in 0.062928 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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