慕哥6287543
%% 互相关函数,获取到输入块block1 在block2中相关最高的位置及对应的相关函数结果% 输入参数% Block1:需要匹配的块,在Block2中检索与该快相似性最高的块;大小小于等于Block2% Block2:大于等于Block1% 其中Block1与Block2的正中心重合,即Block1的位置在Block2的正中心% lateralstep:互相关过程中,横向移动步进,单位为像素点的整数倍% axialstep:互相关过程中,纵向移动步进,单位为像素点的整数倍% halflateralnum:横向块移动次数的一半,负数向左,正数向右% halfaxialnum:纵向块移动次数的一半,负数向上,正数向下% 输出参数% x:在Block2中,与Block1最相似的块移动的横向距离,单位为像素点% y:在Block2中,与Block1最相似的块移动的纵向距离,单位为像素点% R12:Block1与Block2中最相似的块之间的互相关结果(复数)%% 对Block2是有要求的,BLock2是Block1步进的偶数倍,即要保证Block1在Block2中的移动是对称的function [x y R12] = ZPP_CrossCorrelation(Block1,Block2,lateralstep,axialstep,halflateralnum,halfaxialnum)[m1 n1] = size(Block1);[m2 n2] = size(Block2);Ra = zeros(halfaxialnum*2+1,halflateralnum*2+1);pro_data = Block1;for i = 1 : halfaxialnum*2+1for j = 1 : halflateralnum*2+1clear temp;clear post_data;axial_num = (1:m1) + (i - 1)*axialstep;lateral_num = (1:n1) + (j - 1)*lateralstep;post_data = Block2(axial_num,lateral_num);temp = pro_data.*conj(post_data);Ra(i,j) = sum(temp(:));% 加上相关系数,使用相关系数去解temp1 = abs(Ra(i,j));temp_2 = pro_data.^2;temp2 = sum(temp_2(:));temp_3 = post_data.^2;temp3 = sum(temp_3(:));temp4 = sqrt(temp2*temp3);RA_Ctn(i,j) = temp1/temp4;endend% [temp_y temp_x] = find(abs(Ra) == max(abs(Ra(:)))); % 找出最大值的点[temp_y temp_x] = find(abs(RA_Ctn) == max(abs(RA_Ctn(:)))); % 找出最大值的点x = (temp_x - 1 - halflateralnum) * lateralstep; % 横向移动的间距为第几列y = (temp_y - 1 - halfaxialnum) * axialstep; % 纵向移动的间距为第几行R12 = Ra(temp_y,temp_x);end