|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
- % %%%%%%%%%%%%%%%%%%%%%%%%%%% 初始化参数
- 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维图像,(高光谱图像),包括宽度*高度*波段数;
如果背景方面不了解的只是从公式的角度也可以稍微解释下上边的代码,谢谢各位!
[ 本帖最后由 yangfanxing__ 于 2010-3-9 16:25 编辑 ] |
|