yangfanxing__ 发表于 2010-3-9 16:17

关于Matlab的RX算法,请教注释的几个问题

% %%%%%%%%%%%%%%%%%%%%%%%%%%% 初始化参数

function RXdet = RX(A,winlenth,shape)

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

switch shape
case 0
target_spatial=[0 0 1 0 0;
0 0 1 0 0;
1 1 1 1 1;
0 0 1 0 0;
0 0 1 0 0];
case 1
target_spatial=[1 0 1;
0 1 0;
1 0 1];
case 2
target_spatial=[1 0 0 0 1; %%% 主程序中取shape=2
0 1 0 1 0;
0 0 1 0 0;
0 1 0 1 0;
1 0 0 0 1];
case 3
target_spatial=[1 0 0 0 0 0 1
0 1 0 0 0 1 0;
0 0 1 0 1 0 0;
0 0 0 1 0 0 0;
0 0 1 0 1 0 0
0 1 0 0 0 1 0
1 0 0 0 0 0 1];
otherwise
disp('Unknown shape.')
end

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

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

AA((winlenth+1)/2:(winlenth-1)/2+SizeA(1), (winlenth+1)/2:(winlenth-1)/2+SizeA(2),:)=A; %中
AA((winlenth-1)/2:-1:1,(winlenth+1)/2:(winlenth-1)/2+SizeA(2),:)=A(1:(winlenth-1)/2,:,:); %上
AA(winlenth-1+SizeA(1):-1:(winlenth+1)/2+SizeA(1),(winlenth+1)/2:(winlenth-1)/2+SizeA(2),:)...%下
=A(SizeA(1)-(winlenth-3)/2:SizeA(1),:,:); %
AA((winlenth+1)/2:(winlenth-1)/2+SizeA(1),(winlenth-1)/2:-1:1,:)=A(:,1:(winlenth-1)/2,:); %左
AA((winlenth+1)/2:(winlenth-1)/2+SizeA(1),winlenth-1+SizeA(2):-1:(winlenth+1)/2+SizeA(2),:)...%右
=A(:,SizeA(2)-(winlenth-3)/2:SizeA(2),:); %
AA((winlenth-1)/2:-1:1,(winlenth-1)/2:-1:1,:)=A(1:(winlenth-1)/2,1:(winlenth-1)/2,:); %左上
AA(winlenth-1+SizeA(1):-1:(winlenth+1)/2+SizeA(1),winlenth-1+SizeA(2):-1:(winlenth+1)/2+... %右下
SizeA(2),:)=A(SizeA(1)-(winlenth-3)/2:SizeA(1),SizeA(2)-(winlenth-3)/2:SizeA(2),:); %
AA(winlenth-1+SizeA(1):-1:(winlenth+1)/2+SizeA(1),(winlenth-1)/2:-1:1,:)... %左下
=A(SizeA(1)-(winlenth-3)/2:SizeA(1),1:(winlenth-1)/2,:); %
AA((winlenth-1)/2:-1:1,winlenth-1+SizeA(2):-1:(winlenth+1)/2+SizeA(2),:)... %右上
=A(1:(winlenth-1)/2,SizeA(2)-(winlenth-3)/2:SizeA(2),:); %

clear A;

spatial_pattern=zeros(winlenth,winlenth);
spatial_pattern((winlenth-3)/2:(winlenth+5)/2,(winlenth-3)/2:(winlenth+5)/2)=target_spatial;
s=zeros(1,winlenth*winlenth);
for i=1:winlenth
for j=1:winlenth
s((i-1)*winlenth+j)=spatial_pattern(i,j);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%% RX运算%%%%%%%%
%【滑】 【动】 【窗】 【去均值】???????????????????
for i=(winlenth+1)/2:(winlenth-1)/2+SizeA(1)
for j=(winlenth+1)/2:(winlenth-1)/2+SizeA(2)
AAA=AA(i-(winlenth-1)/2:i+(winlenth-1)/2,j-(winlenth-1)/2:j+(winlenth-1)/2,:);%滑
x=[];

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

for m=1:winlenth
for n=1:winlenth %动
xn(:)=AAA(m,n,:);
x=;
end
end %窗

WinMean=mean(x,2);
WinCov=cov(x');
% WinCov(1,1)
InvCov=inv(WinCov);
clear WinCov;

for n=1:winlenth*winlenth %去均值
x(:,n)=x(:,n)-WinMean;
end %
% figure,imshow();
xx=x*s';
RXdet(i-(winlenth-1)/2,j-(winlenth-1)/2)=xx'*InvCov*xx/(s*s');
end
end
figure,imshow(RXdet,[]);以上部分不能懂,望能看得懂的帮帮我呀!

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

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

[ 本帖最后由 yangfanxing__ 于 2010-3-9 16:25 编辑 ]

yangfanxing__ 发表于 2010-3-11 16:28

问题搁浅。。。顶顶吧~

夏竹 发表于 2013-3-15 17:06

您好
我现在在做高光谱图像的异常检测,我看到了您之前的帖子,请问现在您还有RX算法或者相关算法的代码吗?我刚入门,好多东西自己都找不到,请您帮帮我。我的邮箱是183541477@qq.com,请您把相关资料发给我,真的非常感谢。祝您一切顺利。
页: [1]
查看完整版本: 关于Matlab的RX算法,请教注释的几个问题