invcov matlab,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=[x,xn];

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维图像,(高光谱图像),包括宽度*高度*波段数;

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值