电子图像稳定,是指利用数宇图像处理技术消除或者减轻视频图像序列中因为摄像机的抖动而引入的非平稳运动(抖动),使图像序列稳定的处理过程。
图像的帧间运动变化主要有全局变化和局部变化。全局变化是指相机参数变化或者相机抖动等动作引起的图片全局变化。局部运动是指被拍摄物体运动引起的局部变化。图像稳定就是对全局运动进行估计和补偿。运动估计的主要方法有像素递归法Pixel Recursive Algorithm,以及块匹配法Block Matching Algorithm。其中,块匹配法是假设同一图像块的所有像素有相同的运动特征。
全局匹配法的实现过程:将图像划分成m*n大小的子块,取其中一个子块作为参考块,记录其中心的位置,在上一帧相对应位置处取(△m+m)*(△n+n)的搜索窗,在搜索区域内所有的候选块中,找到与当前参考块在某种匹配准则意义下最相似的块,认为是匹配块。参考块与匹配块之间的相对位移即为该块的运动矢量。
块匹配准则函数有 均方误差、最小绝对值误差、归一化二维互相光函数准则。.
全搜索法是在搜索窗中所有可能的偏移位置都进行匹配运算,的到最佳匹配块和偏移矢量。但是缺点在于运算量巨大,不利于实时处理。如图:
( 转)
一种改进的块匹配运动估计法:
取参考块为8×8。搜索范围是由图象的抖动程度决定的,可以根据试验结果调整。一般电视图像序列的最大位移小
于±5,针对本文采用的测试图象序列,确定搜索范围为±8,即搜索窗大小为24×24。其次寻找最佳匹配块。定义可变阈值
TK,计算参考块和搜索窗中第一个候选匹配块所有象素灰度值的绝对误差之和,作为TK初始值。参考块在搜索范围内逐行逐列移动,在与每个候选匹配块的比较过程中,每运算一行就判断一次误差累加值是否超过TK,超过则认为该候选块不是最佳匹配块,结束计算,移至下一候选块。如果直至此次误差累加结束,ε仍然小于TK,则把ε赋值给TK,形成新的阈值,并记录该块位置。当参考块在整个搜索范围内的匹配计算结束时,最后一个赋值给TK的候选块,即与参考块绝对误差最小的块被确定为最佳匹配块,其与参考块的相对位移定义为该块的运动矢量。在给定块大小和搜索范围的情况下计算最佳匹配块,每个参考块有(8×8)个象素,在搜索范围内有(24-8+1)×(24-8+1)=289个候选位置,根据绝对误差函数,没有使用阈值以前与每个候选块的比较需要运行(64+64)次加运算;使用阈值后,假设在第k行误差累加超过TK,结束这次匹配,则运算量是(8+8)×k=(64+64)×k 8次加运算,其中1≤k≤8,将这个结果推广到289个候选块的匹配中,可以看到计算量明显减小,而且计算精度没有受到影响。
最后,附上我实现该算法用来计算图像旋转和平移的程序。
程序1:该程序适用于只有旋转没有平移,而且图像的旋转中心就是图像的中心的情况。
%%%%%%%%%%%%%%%%%全搜索块匹配法做%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;
Image1 = imread('e:\images\a.jpg');
gray1=single(rgb2gray(Image1));%%%%%%%%%%%%%%%不转换数据类型的话,默认是八位,会导致后续相关变量限定在255;
Image2 = imread('e:\images\b.jpg');
gray2=single(rgb2gray(Image2));
center(1:9,1:2)=[22,22;68,22;112,22;22,138;68,138;112,138;22,65;68,65;112,65];
for i=11%:34
for j=11%:34
firstline=abs( gray2(i,j)-gray1(19,19) )+abs( gray2(i,j+1)-gray1(19,20))+abs( gray2(i,j+2)-gray1(19,21))+abs( gray2(i,j+3)-gray1(19,22))+abs( gray2(i,j+4)-gray1(19,23))+abs( gray2(i,j+5)-gray1(19,24))+abs( gray2(i,j+6)-gray1(19,25));
secondline=abs( gray2(i+1,j)-gray1(19+1,19))+abs( gray2(i+1,j+1)-gray1(19+1,20))+abs( gray2(i,j+2)-gray1(19+1,21))+abs( gray2(i,j+3)-gray1(19+1,22))+abs( gray2(i,j+4)-gray1(19+1,23))+abs( gray2(i,j+5)-gray1(19+1,24))+abs( gray2(i,j+6)-gray1(19+1,25));
thirdline=abs( gray2(i+2,j)-gray1(19+2,19))+abs( gray2(i+2,j+1)-gray1(19+2,20))+abs( gray2(i,j+2)-gray1(19+2,21))+abs( gray2(i,j+3)-gray1(19+2,22))+abs( gray2(i,j+4)-gray1(19+2,23))+abs( gray2(i,j+5)-gray1(19+2,24))+abs( gray2(i,j+6)-gray1(19+2,25));
forthline=abs( gray2(i+3,j)-gray1(19+3,19))+abs( gray2(i+3,j+1)-gray1(19+3,20))+abs( gray2(i,j+2)-gray1(19+3,21))+abs( gray2(i,j+3)-gray1(19+3,22))+abs( gray2(i,j+4)-gray1(19+3,23))+abs( gray2(i,j+5)-gray1(19+3,24))+abs( gray2(i,j+6)-gray1(19+3,25));
fifthline=abs( gray2(i+4,j)-gray1(19+4,19))+abs( gray2(i+4,j+1)-gray1(19+4,20))+abs( gray2(i,j+2)-gray1(19+4,21))+abs( gray2(i,j+3)-gray1(19+4,22))+abs( gray2(i,j+4)-gray1(19+4,23))+abs( gray2(i,j+5)-gray1(19+4,24))+abs( gray2(i,j+6)-gray1(19+4,25));
sixthline=abs( gray2(i+5,j)-gray1(19+5,19))+abs( gray2(i+5,j+1)-gray1(19+5,20))+abs( gray2(i,j+2)-gray1(19+5,21))+abs( gray2(i,j+3)-gray1(19+5,22))+abs( gray2(i,j+4)-gray1(19+5,23))+abs( gray2(i,j+5)-gray1(19+5,24))+abs( gray2(i,j+6)-gray1(19+5,25));
seventhline=abs( gray2(i+6,j)-gray1(19+6,19))+abs( gray2(i+6,j+1)-gray1(19+6,20))+abs( gray2(i,j+2)-gray1(19+6,21))+abs( gray2(i,j+3)-gray1(19+6,22))+abs( gray2(i,j+4)-gray1(19+6,23))+abs( gray2(i,j+5)-gray1(19+6,24))+abs( gray2(i,j+6)-gray1(19+6,25));
block1=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK1=block1;
end
end
sum=0;
for p=1:36
for q=1:36
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(19+t,19) )+abs( gray2(p+t,q+1)-gray1(19+t,20))+abs( gray2(p+t,q+2)-gray1(19+t,21))+abs( gray2(p+t,q+3)-gray1(19+t,22))+abs( gray2(p+t,q+4)-gray1(19+t,23))+abs( gray2(p+t,q+5)-gray1(19+t,24))+abs( gray2(p+t,q+6)-gray1(19+t,25));
sum=sum+linet;
if sum>TK1
continue;
end
end
if sum TK1=sum;
center(1,3:4)=[p+3,q+3];
end
end
end
for i=57%:79
for j=11%:34
firstline=abs( gray2(i,j)-gray1(65,19) )+abs( gray2(i,j+1)-gray1(65,20))+abs( gray2(i,j+2)-gray1(65,21))+abs( gray2(i,j+3)-gray1(65,22))+abs( gray2(i,j+4)-gray1(65,23))+abs( gray2(i,j+5)-gray1(65,24))+abs( gray2(i,j+6)-gray1(65,25));
secondline=abs( gray2(i+1,j)-gray1(65+1,19))+abs( gray2(i+1,j+1)-gray1(65+1,20))+abs( gray2(i,j+2)-gray1(65+1,21))+abs( gray2(i,j+3)-gray1(65+1,22))+abs( gray2(i,j+4)-gray1(65+1,23))+abs( gray2(i,j+5)-gray1(65+1,24))+abs( gray2(i,j+6)-gray1(65+1,25));
thirdline=abs( gray2(i+2,j)-gray1(65+2,19))+abs( gray2(i+2,j+1)-gray1(65+2,20))+abs( gray2(i,j+2)-gray1(65+2,21))+abs( gray2(i,j+3)-gray1(65+2,22))+abs( gray2(i,j+4)-gray1(65+2,23))+abs( gray2(i,j+5)-gray1(65+2,24))+abs( gray2(i,j+6)-gray1(65+2,25));
forthline=abs( gray2(i+3,j)-gray1(65+3,19))+abs( gray2(i+3,j+1)-gray1(65+3,20))+abs( gray2(i,j+2)-gray1(65+3,21))+abs( gray2(i,j+3)-gray1(65+3,22))+abs( gray2(i,j+4)-gray1(65+3,23))+abs( gray2(i,j+5)-gray1(65+3,24))+abs( gray2(i,j+6)-gray1(65+3,25));
fifthline=abs( gray2(i+4,j)-gray1(65+4,19))+abs( gray2(i+4,j+1)-gray1(65+4,20))+abs( gray2(i,j+2)-gray1(65+4,21))+abs( gray2(i,j+3)-gray1(65+4,22))+abs( gray2(i,j+4)-gray1(65+4,23))+abs( gray2(i,j+5)-gray1(65+4,24))+abs( gray2(i,j+6)-gray1(65+4,25));
sixthline=abs( gray2(i+5,j)-gray1(65+5,19))+abs( gray2(i+5,j+1)-gray1(65+5,20))+abs( gray2(i,j+2)-gray1(65+5,21))+abs( gray2(i,j+3)-gray1(65+5,22))+abs( gray2(i,j+4)-gray1(65+5,23))+abs( gray2(i,j+5)-gray1(65+5,24))+abs( gray2(i,j+6)-gray1(65+5,25));
seventhline=abs( gray2(i+6,j)-gray1(65+6,19))+abs( gray2(i+6,j+1)-gray1(65+6,20))+abs( gray2(i,j+2)-gray1(65+6,21))+abs( gray2(i,j+3)-gray1(65+6,22))+abs( gray2(i,j+4)-gray1(65+6,23))+abs( gray2(i,j+5)-gray1(65+6,24))+abs( gray2(i,j+6)-gray1(65+6,25));
block2=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK2=block2;
end
end
sum=0;
for p=47:82
for q=1:36
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(65+t,19) )+abs( gray2(p+t,q+1)-gray1(65+t,20))+abs( gray2(p+t,q+2)-gray1(65+t,21))+abs( gray2(p+t,q+3)-gray1(65+t,22))+abs( gray2(p+t,q+4)-gray1(65+t,23))+abs( gray2(p+t,q+5)-gray1(65+t,24))+abs( gray2(p+t,q+6)-gray1(65+t,25));
sum=sum+linet;
if sum>TK2
continue;
end
end
if sum TK2=sum;
center(2,3:4)=[p+3,q+3];
end
end
end
for i=101%:123
for j=11%:34
firstline=abs( gray2(i,j)-gray1(109,19) )+abs( gray2(i,j+1)-gray1(109,20))+abs( gray2(i,j+2)-gray1(109,21))+abs( gray2(i,j+3)-gray1(109,22))+abs( gray2(i,j+4)-gray1(109,23))+abs( gray2(i,j+5)-gray1(109,24))+abs( gray2(i,j+6)-gray1(109,25));
secondline=abs( gray2(i+1,j)-gray1(109+1,19))+abs( gray2(i+1,j+1)-gray1(109+1,20))+abs( gray2(i,j+2)-gray1(109+1,21))+abs( gray2(i,j+3)-gray1(109+1,22))+abs( gray2(i,j+4)-gray1(109+1,23))+abs( gray2(i,j+5)-gray1(109+1,24))+abs( gray2(i,j+6)-gray1(109+1,25));
thirdline=abs( gray2(i+2,j)-gray1(109+2,19))+abs( gray2(i+2,j+1)-gray1(109+2,20))+abs( gray2(i,j+2)-gray1(109+2,21))+abs( gray2(i,j+3)-gray1(109+2,22))+abs( gray2(i,j+4)-gray1(109+2,23))+abs( gray2(i,j+5)-gray1(109+2,24))+abs( gray2(i,j+6)-gray1(109+2,25));
forthline=abs( gray2(i+3,j)-gray1(109+3,19))+abs( gray2(i+3,j+1)-gray1(109+3,20))+abs( gray2(i,j+2)-gray1(109+3,21))+abs( gray2(i,j+3)-gray1(109+3,22))+abs( gray2(i,j+4)-gray1(109+3,23))+abs( gray2(i,j+5)-gray1(109+3,24))+abs( gray2(i,j+6)-gray1(109+3,25));
fifthline=abs( gray2(i+4,j)-gray1(109+4,19))+abs( gray2(i+4,j+1)-gray1(109+4,20))+abs( gray2(i,j+2)-gray1(109+4,21))+abs( gray2(i,j+3)-gray1(109+4,22))+abs( gray2(i,j+4)-gray1(109+4,23))+abs( gray2(i,j+5)-gray1(109+4,24))+abs( gray2(i,j+6)-gray1(109+4,25));
sixthline=abs( gray2(i+5,j)-gray1(109+5,19))+abs( gray2(i+5,j+1)-gray1(109+5,20))+abs( gray2(i,j+2)-gray1(109+5,21))+abs( gray2(i,j+3)-gray1(109+5,22))+abs( gray2(i,j+4)-gray1(109+5,23))+abs( gray2(i,j+5)-gray1(109+5,24))+abs( gray2(i,j+6)-gray1(109+5,25));
seventhline=abs( gray2(i+6,j)-gray1(109+6,19))+abs( gray2(i+6,j+1)-gray1(109+6,20))+abs( gray2(i,j+2)-gray1(109+6,21))+abs( gray2(i,j+3)-gray1(109+6,22))+abs( gray2(i,j+4)-gray1(109+6,23))+abs( gray2(i,j+5)-gray1(109+6,24))+abs( gray2(i,j+6)-gray1(109+6,25));
block3=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK3=block3;
end
end
sum=0;
for p=91:126
for q=1:36
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(109+t,19) )+abs( gray2(p+t,q+1)-gray1(109+t,20))+abs( gray2(p+t,q+2)-gray1(109+t,21))+abs( gray2(p+t,q+3)-gray1(109+t,22))+abs( gray2(p+t,q+4)-gray1(109+t,23))+abs( gray2(p+t,q+5)-gray1(109+t,24))+abs( gray2(p+t,q+6)-gray1(109+t,25));
sum=sum+linet;
if sum>TK3
center(3,3:4)=[104,14];
continue;
end
end
if sum TK3=sum;
center(3,3:4)=[p+3,q+3];
end
end
end
for i=11%:34
for j=127%:149
firstline=abs( gray2(i,j)-gray1(19,135) )+abs( gray2(i,j+1)-gray1(19,136))+abs( gray2(i,j+2)-gray1(19,137))+abs( gray2(i,j+3)-gray1(19,138))+abs( gray2(i,j+4)-gray1(19,139))+abs( gray2(i,j+5)-gray1(19,140))+abs( gray2(i,j+6)-gray1(19,141));
secondline=abs( gray2(i+1,j)-gray1(19+1,135))+abs( gray2(i+1,j+1)-gray1(19+1,136))+abs( gray2(i,j+2)-gray1(19+1,137))+abs( gray2(i,j+3)-gray1(19+1,138))+abs( gray2(i,j+4)-gray1(19+1,139))+abs( gray2(i,j+5)-gray1(19+1,140))+abs( gray2(i,j+6)-gray1(19+1,141));
thirdline=abs( gray2(i+2,j)-gray1(19+2,135))+abs( gray2(i+2,j+1)-gray1(19+2,136))+abs( gray2(i,j+2)-gray1(19+2,137))+abs( gray2(i,j+3)-gray1(19+2,138))+abs( gray2(i,j+4)-gray1(19+2,139))+abs( gray2(i,j+5)-gray1(19+2,140))+abs( gray2(i,j+6)-gray1(19+2,141));
forthline=abs( gray2(i+3,j)-gray1(19+3,135))+abs( gray2(i+3,j+1)-gray1(19+3,136))+abs( gray2(i,j+2)-gray1(19+3,137))+abs( gray2(i,j+3)-gray1(19+3,138))+abs( gray2(i,j+4)-gray1(19+3,139))+abs( gray2(i,j+5)-gray1(19+3,140))+abs( gray2(i,j+6)-gray1(19+3,141));
fifthline=abs( gray2(i+4,j)-gray1(19+4,135))+abs( gray2(i+4,j+1)-gray1(19+4,136))+abs( gray2(i,j+2)-gray1(19+4,137))+abs( gray2(i,j+3)-gray1(19+4,138))+abs( gray2(i,j+4)-gray1(19+4,139))+abs( gray2(i,j+5)-gray1(19+4,140))+abs( gray2(i,j+6)-gray1(19+4,141));
sixthline=abs( gray2(i+5,j)-gray1(19+5,135))+abs( gray2(i+5,j+1)-gray1(19+5,136))+abs( gray2(i,j+2)-gray1(19+5,137))+abs( gray2(i,j+3)-gray1(19+5,138))+abs( gray2(i,j+4)-gray1(19+5,139))+abs( gray2(i,j+5)-gray1(19+5,140))+abs( gray2(i,j+6)-gray1(19+5,141));
seventhline=abs( gray2(i+6,j)-gray1(19+6,135))+abs( gray2(i+6,j+1)-gray1(19+6,136))+abs( gray2(i,j+2)-gray1(19+6,137))+abs( gray2(i,j+3)-gray1(19+6,138))+abs( gray2(i,j+4)-gray1(19+6,139))+abs( gray2(i,j+5)-gray1(19+6,140))+abs( gray2(i,j+6)-gray1(19+6,141));
block4=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK4=block4;
end
end
sum=0;
for p=1:36
for q=117:152
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(19+t,135) )+abs( gray2(p+t,q+1)-gray1(19+t,136))+abs( gray2(p+t,q+2)-gray1(19+t,137))+abs( gray2(p+t,q+3)-gray1(19+t,138))+abs( gray2(p+t,q+4)-gray1(19+t,139))+abs( gray2(p+t,q+5)-gray1(19+t,140))+abs( gray2(p+t,q+6)-gray1(19+t,141));
sum=sum+linet;
if sum>TK4
continue;
end
end
if sum TK4=sum;
center(4,3:4)=[p+3,q+3];
end
end
end
for i=57%:79
for j=127%:149
firstline=abs( gray2(i,j)-gray1(65,135) )+abs( gray2(i,j+1)-gray1(65,136))+abs( gray2(i,j+2)-gray1(65,137))+abs( gray2(i,j+3)-gray1(65,138))+abs( gray2(i,j+4)-gray1(65,139))+abs( gray2(i,j+5)-gray1(65,140))+abs( gray2(i,j+6)-gray1(65,141));
secondline=abs( gray2(i+1,j)-gray1(65+1,135))+abs( gray2(i+1,j+1)-gray1(65+1,136))+abs( gray2(i,j+2)-gray1(65+1,137))+abs( gray2(i,j+3)-gray1(65+1,138))+abs( gray2(i,j+4)-gray1(65+1,139))+abs( gray2(i,j+5)-gray1(65+1,140))+abs( gray2(i,j+6)-gray1(65+1,141));
thirdline=abs( gray2(i+2,j)-gray1(65+2,135))+abs( gray2(i+2,j+1)-gray1(65+2,136))+abs( gray2(i,j+2)-gray1(65+2,137))+abs( gray2(i,j+3)-gray1(65+2,138))+abs( gray2(i,j+4)-gray1(65+2,139))+abs( gray2(i,j+5)-gray1(65+2,140))+abs( gray2(i,j+6)-gray1(65+2,141));
forthline=abs( gray2(i+3,j)-gray1(65+3,135))+abs( gray2(i+3,j+1)-gray1(65+3,136))+abs( gray2(i,j+2)-gray1(65+3,137))+abs( gray2(i,j+3)-gray1(65+3,138))+abs( gray2(i,j+4)-gray1(65+3,139))+abs( gray2(i,j+5)-gray1(65+3,140))+abs( gray2(i,j+6)-gray1(65+3,141));
fifthline=abs( gray2(i+4,j)-gray1(65+4,135))+abs( gray2(i+4,j+1)-gray1(65+4,136))+abs( gray2(i,j+2)-gray1(65+4,137))+abs( gray2(i,j+3)-gray1(65+4,138))+abs( gray2(i,j+4)-gray1(65+4,139))+abs( gray2(i,j+5)-gray1(65+4,140))+abs( gray2(i,j+6)-gray1(65+4,141));
sixthline=abs( gray2(i+5,j)-gray1(65+5,135))+abs( gray2(i+5,j+1)-gray1(65+5,136))+abs( gray2(i,j+2)-gray1(65+5,137))+abs( gray2(i,j+3)-gray1(65+5,138))+abs( gray2(i,j+4)-gray1(65+5,139))+abs( gray2(i,j+5)-gray1(65+5,140))+abs( gray2(i,j+6)-gray1(65+5,141));
seventhline=abs( gray2(i+6,j)-gray1(65+6,135))+abs( gray2(i+6,j+1)-gray1(65+6,136))+abs( gray2(i,j+2)-gray1(65+6,137))+abs( gray2(i,j+3)-gray1(65+6,138))+abs( gray2(i,j+4)-gray1(65+6,139))+abs( gray2(i,j+5)-gray1(65+6,140))+abs( gray2(i,j+6)-gray1(65+6,141));
block5=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK5=block5;
end
end
sum=0;
for p=47:82
for q=117:152
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(65+t,135) )+abs( gray2(p+t,q+1)-gray1(65+t,136))+abs( gray2(p+t,q+2)-gray1(65+t,137))+abs( gray2(p+t,q+3)-gray1(65+t,138))+abs( gray2(p+t,q+4)-gray1(65+t,139))+abs( gray2(p+t,q+5)-gray1(65+t,140))+abs( gray2(p+t,q+6)-gray1(65+t,141));
sum=sum+linet;
if sum>TK5
continue;
end
end
if sum TK5=sum;
center(5,3:4)=[p+3,q+3];
end
end
end
for i=101%:123
for j=127%:149
firstline=abs( gray2(i,j)-gray1(109,135) )+abs( gray2(i,j+1)-gray1(109,136))+abs( gray2(i,j+2)-gray1(109,137))+abs( gray2(i,j+3)-gray1(109,138))+abs( gray2(i,j+4)-gray1(109,139))+abs( gray2(i,j+5)-gray1(109,140))+abs( gray2(i,j+6)-gray1(109,141));
secondline=abs( gray2(i+1,j)-gray1(109+1,135))+abs( gray2(i+1,j+1)-gray1(109+1,136))+abs( gray2(i,j+2)-gray1(109+1,137))+abs( gray2(i,j+3)-gray1(109+1,138))+abs( gray2(i,j+4)-gray1(109+1,139))+abs( gray2(i,j+5)-gray1(109+1,140))+abs( gray2(i,j+6)-gray1(109+1,141));
thirdline=abs( gray2(i+2,j)-gray1(109+2,135))+abs( gray2(i+2,j+1)-gray1(109+2,136))+abs( gray2(i,j+2)-gray1(109+2,137))+abs( gray2(i,j+3)-gray1(109+2,138))+abs( gray2(i,j+4)-gray1(109+2,139))+abs( gray2(i,j+5)-gray1(109+2,140))+abs( gray2(i,j+6)-gray1(109+2,141));
forthline=abs( gray2(i+3,j)-gray1(109+3,135))+abs( gray2(i+3,j+1)-gray1(109+3,136))+abs( gray2(i,j+2)-gray1(109+3,137))+abs( gray2(i,j+3)-gray1(109+3,138))+abs( gray2(i,j+4)-gray1(109+3,139))+abs( gray2(i,j+5)-gray1(109+3,140))+abs( gray2(i,j+6)-gray1(109+3,141));
fifthline=abs( gray2(i+4,j)-gray1(109+4,135))+abs( gray2(i+4,j+1)-gray1(109+4,136))+abs( gray2(i,j+2)-gray1(109+4,137))+abs( gray2(i,j+3)-gray1(109+4,138))+abs( gray2(i,j+4)-gray1(109+4,139))+abs( gray2(i,j+5)-gray1(109+4,140))+abs( gray2(i,j+6)-gray1(109+4,141));
sixthline=abs( gray2(i+5,j)-gray1(109+5,135))+abs( gray2(i+5,j+1)-gray1(109+5,136))+abs( gray2(i,j+2)-gray1(109+5,137))+abs( gray2(i,j+3)-gray1(109+5,138))+abs( gray2(i,j+4)-gray1(109+5,139))+abs( gray2(i,j+5)-gray1(109+5,140))+abs( gray2(i,j+6)-gray1(109+5,141));
seventhline=abs( gray2(i+6,j)-gray1(109+6,135))+abs( gray2(i+6,j+1)-gray1(109+6,136))+abs( gray2(i,j+2)-gray1(109+6,137))+abs( gray2(i,j+3)-gray1(109+6,138))+abs( gray2(i,j+4)-gray1(109+6,139))+abs( gray2(i,j+5)-gray1(109+6,140))+abs( gray2(i,j+6)-gray1(109+6,141));
block6=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK6=block6;
end
end
sum=0;
for p=91:126
for q=117:152
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(109+t,135) )+abs( gray2(p+t,q+1)-gray1(109+t,136))+abs( gray2(p+t,q+2)-gray1(109+t,137))+abs( gray2(p+t,q+3)-gray1(109+t,138))+abs( gray2(p+t,q+4)-gray1(109+t,139))+abs( gray2(p+t,q+5)-gray1(109+t,140))+abs( gray2(p+t,q+6)-gray1(109+t,141));
sum=sum+linet;
if sum>TK6
continue;
end
end
if sum TK6=sum;
center(6,3:4)=[p+3,q+3];
end
end
end
for i=11%:34
for j=54%:34
firstline=abs( gray2(i,j)-gray1(19,62) )+abs( gray2(i,j+1)-gray1(19,63))+abs( gray2(i,j+2)-gray1(19,64))+abs( gray2(i,j+3)-gray1(19,65))+abs( gray2(i,j+4)-gray1(19,66))+abs( gray2(i,j+5)-gray1(19,67))+abs( gray2(i,j+6)-gray1(19,68));
secondline=abs( gray2(i+1,j)-gray1(19+1,62))+abs( gray2(i+1,j+1)-gray1(19+1,63))+abs( gray2(i,j+2)-gray1(19+1,64))+abs( gray2(i,j+3)-gray1(19+1,65))+abs( gray2(i,j+4)-gray1(19+1,66))+abs( gray2(i,j+5)-gray1(19+1,67))+abs( gray2(i,j+6)-gray1(19+1,68));
thirdline=abs( gray2(i+2,j)-gray1(19+2,62))+abs( gray2(i+2,j+1)-gray1(19+2,63))+abs( gray2(i,j+2)-gray1(19+2,64))+abs( gray2(i,j+3)-gray1(19+2,65))+abs( gray2(i,j+4)-gray1(19+2,66))+abs( gray2(i,j+5)-gray1(19+2,67))+abs( gray2(i,j+6)-gray1(19+2,68));
forthline=abs( gray2(i+3,j)-gray1(19+3,62))+abs( gray2(i+3,j+1)-gray1(19+3,63))+abs( gray2(i,j+2)-gray1(19+3,64))+abs( gray2(i,j+3)-gray1(19+3,65))+abs( gray2(i,j+4)-gray1(19+3,66))+abs( gray2(i,j+5)-gray1(19+3,67))+abs( gray2(i,j+6)-gray1(19+3,68));
fifthline=abs( gray2(i+4,j)-gray1(19+4,62))+abs( gray2(i+4,j+1)-gray1(19+4,63))+abs( gray2(i,j+2)-gray1(19+4,64))+abs( gray2(i,j+3)-gray1(19+4,65))+abs( gray2(i,j+4)-gray1(19+4,66))+abs( gray2(i,j+5)-gray1(19+4,67))+abs( gray2(i,j+6)-gray1(19+4,68));
sixthline=abs( gray2(i+5,j)-gray1(19+5,62))+abs( gray2(i+5,j+1)-gray1(19+5,63))+abs( gray2(i,j+2)-gray1(19+5,64))+abs( gray2(i,j+3)-gray1(19+5,65))+abs( gray2(i,j+4)-gray1(19+5,66))+abs( gray2(i,j+5)-gray1(19+5,67))+abs( gray2(i,j+6)-gray1(19+5,68));
seventhline=abs( gray2(i+6,j)-gray1(19+6,62))+abs( gray2(i+6,j+1)-gray1(19+6,63))+abs( gray2(i,j+2)-gray1(19+6,64))+abs( gray2(i,j+3)-gray1(19+6,65))+abs( gray2(i,j+4)-gray1(19+6,66))+abs( gray2(i,j+5)-gray1(19+6,67))+abs( gray2(i,j+6)-gray1(19+6,68));
block7=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK7=block7;
end
end
sum=0;
for p=1:36
for q=44:79
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(19+t,62) )+abs( gray2(p+t,q+1)-gray1(19+t,63))+abs( gray2(p+t,q+2)-gray1(19+t,64))+abs( gray2(p+t,q+3)-gray1(19+t,65))+abs( gray2(p+t,q+4)-gray1(19+t,66))+abs( gray2(p+t,q+5)-gray1(19+t,67))+abs( gray2(p+t,q+6)-gray1(19+t,68));
sum=sum+linet;
if sum>TK7
continue;
end
end
if sum TK7=sum;
center(7,3:4)=[p+3,q+3];
end
end
end
for i=57%:79
for j=54%:34
firstline=abs( gray2(i,j)-gray1(65,62) )+abs( gray2(i,j+1)-gray1(65,63))+abs( gray2(i,j+2)-gray1(65,64))+abs( gray2(i,j+3)-gray1(65,65))+abs( gray2(i,j+4)-gray1(65,66))+abs( gray2(i,j+5)-gray1(65,67))+abs( gray2(i,j+6)-gray1(65,68));
secondline=abs( gray2(i+1,j)-gray1(65+1,62))+abs( gray2(i+1,j+1)-gray1(65+1,63))+abs( gray2(i,j+2)-gray1(65+1,64))+abs( gray2(i,j+3)-gray1(65+1,65))+abs( gray2(i,j+4)-gray1(65+1,66))+abs( gray2(i,j+5)-gray1(65+1,67))+abs( gray2(i,j+6)-gray1(65+1,68));
thirdline=abs( gray2(i+2,j)-gray1(65+2,62))+abs( gray2(i+2,j+1)-gray1(65+2,63))+abs( gray2(i,j+2)-gray1(65+2,64))+abs( gray2(i,j+3)-gray1(65+2,65))+abs( gray2(i,j+4)-gray1(65+2,66))+abs( gray2(i,j+5)-gray1(65+2,67))+abs( gray2(i,j+6)-gray1(65+2,68));
forthline=abs( gray2(i+3,j)-gray1(65+3,62))+abs( gray2(i+3,j+1)-gray1(65+3,63))+abs( gray2(i,j+2)-gray1(65+3,64))+abs( gray2(i,j+3)-gray1(65+3,65))+abs( gray2(i,j+4)-gray1(65+3,66))+abs( gray2(i,j+5)-gray1(65+3,67))+abs( gray2(i,j+6)-gray1(65+3,68));
fifthline=abs( gray2(i+4,j)-gray1(65+4,62))+abs( gray2(i+4,j+1)-gray1(65+4,63))+abs( gray2(i,j+2)-gray1(65+4,64))+abs( gray2(i,j+3)-gray1(65+4,65))+abs( gray2(i,j+4)-gray1(65+4,66))+abs( gray2(i,j+5)-gray1(65+4,67))+abs( gray2(i,j+6)-gray1(65+4,68));
sixthline=abs( gray2(i+5,j)-gray1(65+5,62))+abs( gray2(i+5,j+1)-gray1(65+5,63))+abs( gray2(i,j+2)-gray1(65+5,64))+abs( gray2(i,j+3)-gray1(65+5,65))+abs( gray2(i,j+4)-gray1(65+5,66))+abs( gray2(i,j+5)-gray1(65+5,67))+abs( gray2(i,j+6)-gray1(65+5,68));
seventhline=abs( gray2(i+6,j)-gray1(65+6,62))+abs( gray2(i+6,j+1)-gray1(65+6,63))+abs( gray2(i,j+2)-gray1(65+6,64))+abs( gray2(i,j+3)-gray1(65+6,65))+abs( gray2(i,j+4)-gray1(65+6,66))+abs( gray2(i,j+5)-gray1(65+6,67))+abs( gray2(i,j+6)-gray1(65+6,68));
block8=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK8=block8;
end
end
sum=0;
for p=47:82
for q=44:79
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(65+t,62) )+abs( gray2(p+t,q+1)-gray1(65+t,63))+abs( gray2(p+t,q+2)-gray1(65+t,64))+abs( gray2(p+t,q+3)-gray1(65+t,65))+abs( gray2(p+t,q+4)-gray1(65+t,66))+abs( gray2(p+t,q+5)-gray1(65+t,67))+abs( gray2(p+t,q+6)-gray1(65+t,68));
sum=sum+linet;
if sum>TK8
continue;
end
end
if sum TK8=sum;
center(8,3:4)=[p+3,q+3];
end
end
end
for i=101%:123
for j=54%:34
firstline=abs( gray2(i,j)-gray1(109,62) )+abs( gray2(i,j+1)-gray1(109,63))+abs( gray2(i,j+2)-gray1(109,64))+abs( gray2(i,j+3)-gray1(109,65))+abs( gray2(i,j+4)-gray1(109,66))+abs( gray2(i,j+5)-gray1(109,67))+abs( gray2(i,j+6)-gray1(109,68));
secondline=abs( gray2(i+1,j)-gray1(109+1,62))+abs( gray2(i+1,j+1)-gray1(109+1,63))+abs( gray2(i,j+2)-gray1(109+1,64))+abs( gray2(i,j+3)-gray1(109+1,65))+abs( gray2(i,j+4)-gray1(109+1,66))+abs( gray2(i,j+5)-gray1(109+1,67))+abs( gray2(i,j+6)-gray1(109+1,68));
thirdline=abs( gray2(i+2,j)-gray1(109+2,62))+abs( gray2(i+2,j+1)-gray1(109+2,63))+abs( gray2(i,j+2)-gray1(109+2,64))+abs( gray2(i,j+3)-gray1(109+2,65))+abs( gray2(i,j+4)-gray1(109+2,66))+abs( gray2(i,j+5)-gray1(109+2,67))+abs( gray2(i,j+6)-gray1(109+2,68));
forthline=abs( gray2(i+3,j)-gray1(109+3,62))+abs( gray2(i+3,j+1)-gray1(109+3,63))+abs( gray2(i,j+2)-gray1(109+3,64))+abs( gray2(i,j+3)-gray1(109+3,65))+abs( gray2(i,j+4)-gray1(109+3,66))+abs( gray2(i,j+5)-gray1(109+3,67))+abs( gray2(i,j+6)-gray1(109+3,68));
fifthline=abs( gray2(i+4,j)-gray1(109+4,62))+abs( gray2(i+4,j+1)-gray1(109+4,63))+abs( gray2(i,j+2)-gray1(109+4,64))+abs( gray2(i,j+3)-gray1(109+4,65))+abs( gray2(i,j+4)-gray1(109+4,66))+abs( gray2(i,j+5)-gray1(109+4,67))+abs( gray2(i,j+6)-gray1(109+4,68));
sixthline=abs( gray2(i+5,j)-gray1(109+5,62))+abs( gray2(i+5,j+1)-gray1(109+5,63))+abs( gray2(i,j+2)-gray1(109+5,64))+abs( gray2(i,j+3)-gray1(109+5,65))+abs( gray2(i,j+4)-gray1(109+5,66))+abs( gray2(i,j+5)-gray1(109+5,67))+abs( gray2(i,j+6)-gray1(109+5,68));
seventhline=abs( gray2(i+6,j)-gray1(109+6,62))+abs( gray2(i+6,j+1)-gray1(109+6,63))+abs( gray2(i,j+2)-gray1(109+6,64))+abs( gray2(i,j+3)-gray1(109+6,65))+abs( gray2(i,j+4)-gray1(109+6,66))+abs( gray2(i,j+5)-gray1(109+6,67))+abs( gray2(i,j+6)-gray1(109+6,68));
block9=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK9=block9;
end
end
sum=0;
for p=91:126
for q=44:79
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(109+t,62) )+abs( gray2(p+t,q+1)-gray1(109+t,63))+abs( gray2(p+t,q+2)-gray1(109+t,64))+abs( gray2(p+t,q+3)-gray1(109+t,65))+abs( gray2(p+t,q+4)-gray1(109+t,66))+abs( gray2(p+t,q+5)-gray1(109+t,67))+abs( gray2(p+t,q+6)-gray1(109+t,68));
sum=sum+linet;
if sum>TK9
center(9,3:4)=[104,14];
continue;
end
end
if sum TK9=sum;
center(9,3:4)=[p+3,q+3];
end
end
end
%%%%%%%%%%%%%%%get shift%%%%%%%%%%%%%
ud=0;lr=0;
length=size(center,1);
for t=1:length
ud=ud+center(t,3)-center(t,1);
lr=lr+center(t,4)-center(t,2);
end
ud=ud/length
lr=lr/length
%%%%%%%%%%%%%%%get rotate%%%%%%%%%%%%%
% length=size(center,1);
% sum=0;
% for count=1:length
% va=center(count,3)-center(count,1);
% ha=center(count,4)-center(count,2);
% if ( va==0 )
% ang=0;
% elseif ( va~=0 && ha==0)
% ang=0;
% else rotate=atan(va/ha);
% ang=180*rotate/pi;
% end
% center(count,5)=ang;
% sum=sum+ang;
% end
% meanangle=sum/length
%%%%%%%%%%%%%%%%%用余弦公式求到图片旋转中心的角度变化%%%%%%%%%%%%%%%
imagecenter_v=size(gray1,1)/2;
imagecenter_h=size(gray1,2)/2;
center(5,6:7)=[imagecenter_v,imagecenter_h];
sum_angle=0;
for count=1:length
center_distance= sqrt( abs((center(count,1)-center(count,3))^2 + (center(count,2)-center(count,4))^2 ) );%%%%%%%%%%%%%%中心距离%%%%%
center(count,8)=center_distance;
ori_center_core_distance= sqrt( abs( (center(count,1)-center(5,6))^2 +(center(count,2)-center(5,7))^2 ));%%%%%%%%%%上一帧块中心到图中心的距离%%%%%
center(count,9)=ori_center_core_distance ;
next_center_core_distance= sqrt( abs( (center(count,3)-center(5,6))^2+ (center(count,4)-center(5,7))^2 ));%%%%%%%%%下一帧块中心到图中心的距离%%%%%%%
center(count,10)=next_center_core_distance ;
ang=acos( ((center(count,9))^2 +(center(count,10))^2- (center(count,8))^2 ) /(2*center(count,9)*center(count,10)) );%%%%%%%%%%%%%余弦公式求角度%%%%%%%%%
rotate=180*ang/pi;
center(count,11)=rotate;
sum_angle=sum_angle+center(count,11);
end
%%%%%%%%%%去除奇点:由于视频帧间角度变化小,采用去除最小值和最大值,然后求均值,所有角度与均值的差在阈值内时保留,超出则删去。阈值待定%%%%%%%%%
%%%%%%%%%%冒泡法排序,求去掉最大值最小值后的均值%%%
mean_mid=bubble_mean(center(:,11));
del=0;
sum_angle_final=0;
for count=1:length
center(count,12) = center(count,11)-mean_mid;
if center(count,12)>5
del=del+1;
center(count,12)=0;
end
if center(count,12)~=0
sum_angle_final=sum_angle_final+center(count,11);
end
end
mean_angle_final=sum_angle_final/(length-del)
程序2:该程序能够实现平移和旋转同时发生时,计算旋转角度。同样,旋转中心是图像中心。
%%%%%%%%%%%
%%%%%%%%%%%%%%%%%全搜索块匹配法%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc;
Image1 = imread('e:\images\zstree.jpg');
gray1=single(rgb2gray(Image1));%%%%%%%%%%%%%%%不转换数据类型的话,默认是八位,会导致后续相关变量限定在255;
Image2 = imread('e:\images\zstree3_luan.jpg');
gray2=single(rgb2gray(Image2));
center(1:9,1:2)=[22,22;68,22;112,22;22,138;68,138;112,138;22,65;68,65;112,65];
for i=11%:34
for j=11%:34
firstline=abs( gray2(i,j)-gray1(19,19) )+abs( gray2(i,j+1)-gray1(19,20))+abs( gray2(i,j+2)-gray1(19,21))+abs( gray2(i,j+3)-gray1(19,22))+abs( gray2(i,j+4)-gray1(19,23))+abs( gray2(i,j+5)-gray1(19,24))+abs( gray2(i,j+6)-gray1(19,25));
secondline=abs( gray2(i+1,j)-gray1(19+1,19))+abs( gray2(i+1,j+1)-gray1(19+1,20))+abs( gray2(i,j+2)-gray1(19+1,21))+abs( gray2(i,j+3)-gray1(19+1,22))+abs( gray2(i,j+4)-gray1(19+1,23))+abs( gray2(i,j+5)-gray1(19+1,24))+abs( gray2(i,j+6)-gray1(19+1,25));
thirdline=abs( gray2(i+2,j)-gray1(19+2,19))+abs( gray2(i+2,j+1)-gray1(19+2,20))+abs( gray2(i,j+2)-gray1(19+2,21))+abs( gray2(i,j+3)-gray1(19+2,22))+abs( gray2(i,j+4)-gray1(19+2,23))+abs( gray2(i,j+5)-gray1(19+2,24))+abs( gray2(i,j+6)-gray1(19+2,25));
forthline=abs( gray2(i+3,j)-gray1(19+3,19))+abs( gray2(i+3,j+1)-gray1(19+3,20))+abs( gray2(i,j+2)-gray1(19+3,21))+abs( gray2(i,j+3)-gray1(19+3,22))+abs( gray2(i,j+4)-gray1(19+3,23))+abs( gray2(i,j+5)-gray1(19+3,24))+abs( gray2(i,j+6)-gray1(19+3,25));
fifthline=abs( gray2(i+4,j)-gray1(19+4,19))+abs( gray2(i+4,j+1)-gray1(19+4,20))+abs( gray2(i,j+2)-gray1(19+4,21))+abs( gray2(i,j+3)-gray1(19+4,22))+abs( gray2(i,j+4)-gray1(19+4,23))+abs( gray2(i,j+5)-gray1(19+4,24))+abs( gray2(i,j+6)-gray1(19+4,25));
sixthline=abs( gray2(i+5,j)-gray1(19+5,19))+abs( gray2(i+5,j+1)-gray1(19+5,20))+abs( gray2(i,j+2)-gray1(19+5,21))+abs( gray2(i,j+3)-gray1(19+5,22))+abs( gray2(i,j+4)-gray1(19+5,23))+abs( gray2(i,j+5)-gray1(19+5,24))+abs( gray2(i,j+6)-gray1(19+5,25));
seventhline=abs( gray2(i+6,j)-gray1(19+6,19))+abs( gray2(i+6,j+1)-gray1(19+6,20))+abs( gray2(i,j+2)-gray1(19+6,21))+abs( gray2(i,j+3)-gray1(19+6,22))+abs( gray2(i,j+4)-gray1(19+6,23))+abs( gray2(i,j+5)-gray1(19+6,24))+abs( gray2(i,j+6)-gray1(19+6,25));
block1=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK1=block1;
end
end
sum=0;
for p=1:36
for q=1:36
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(19+t,19) )+abs( gray2(p+t,q+1)-gray1(19+t,20))+abs( gray2(p+t,q+2)-gray1(19+t,21))+abs( gray2(p+t,q+3)-gray1(19+t,22))+abs( gray2(p+t,q+4)-gray1(19+t,23))+abs( gray2(p+t,q+5)-gray1(19+t,24))+abs( gray2(p+t,q+6)-gray1(19+t,25));
sum=sum+linet;
if sum>TK1
continue;
end
end
if sum TK1=sum;
center(1,3:4)=[p+3,q+3];
end
end
end
for i=57%:79
for j=11%:34
firstline=abs( gray2(i,j)-gray1(65,19) )+abs( gray2(i,j+1)-gray1(65,20))+abs( gray2(i,j+2)-gray1(65,21))+abs( gray2(i,j+3)-gray1(65,22))+abs( gray2(i,j+4)-gray1(65,23))+abs( gray2(i,j+5)-gray1(65,24))+abs( gray2(i,j+6)-gray1(65,25));
secondline=abs( gray2(i+1,j)-gray1(65+1,19))+abs( gray2(i+1,j+1)-gray1(65+1,20))+abs( gray2(i,j+2)-gray1(65+1,21))+abs( gray2(i,j+3)-gray1(65+1,22))+abs( gray2(i,j+4)-gray1(65+1,23))+abs( gray2(i,j+5)-gray1(65+1,24))+abs( gray2(i,j+6)-gray1(65+1,25));
thirdline=abs( gray2(i+2,j)-gray1(65+2,19))+abs( gray2(i+2,j+1)-gray1(65+2,20))+abs( gray2(i,j+2)-gray1(65+2,21))+abs( gray2(i,j+3)-gray1(65+2,22))+abs( gray2(i,j+4)-gray1(65+2,23))+abs( gray2(i,j+5)-gray1(65+2,24))+abs( gray2(i,j+6)-gray1(65+2,25));
forthline=abs( gray2(i+3,j)-gray1(65+3,19))+abs( gray2(i+3,j+1)-gray1(65+3,20))+abs( gray2(i,j+2)-gray1(65+3,21))+abs( gray2(i,j+3)-gray1(65+3,22))+abs( gray2(i,j+4)-gray1(65+3,23))+abs( gray2(i,j+5)-gray1(65+3,24))+abs( gray2(i,j+6)-gray1(65+3,25));
fifthline=abs( gray2(i+4,j)-gray1(65+4,19))+abs( gray2(i+4,j+1)-gray1(65+4,20))+abs( gray2(i,j+2)-gray1(65+4,21))+abs( gray2(i,j+3)-gray1(65+4,22))+abs( gray2(i,j+4)-gray1(65+4,23))+abs( gray2(i,j+5)-gray1(65+4,24))+abs( gray2(i,j+6)-gray1(65+4,25));
sixthline=abs( gray2(i+5,j)-gray1(65+5,19))+abs( gray2(i+5,j+1)-gray1(65+5,20))+abs( gray2(i,j+2)-gray1(65+5,21))+abs( gray2(i,j+3)-gray1(65+5,22))+abs( gray2(i,j+4)-gray1(65+5,23))+abs( gray2(i,j+5)-gray1(65+5,24))+abs( gray2(i,j+6)-gray1(65+5,25));
seventhline=abs( gray2(i+6,j)-gray1(65+6,19))+abs( gray2(i+6,j+1)-gray1(65+6,20))+abs( gray2(i,j+2)-gray1(65+6,21))+abs( gray2(i,j+3)-gray1(65+6,22))+abs( gray2(i,j+4)-gray1(65+6,23))+abs( gray2(i,j+5)-gray1(65+6,24))+abs( gray2(i,j+6)-gray1(65+6,25));
block2=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK2=block2;
end
end
sum=0;
for p=47:82
for q=1:36
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(65+t,19) )+abs( gray2(p+t,q+1)-gray1(65+t,20))+abs( gray2(p+t,q+2)-gray1(65+t,21))+abs( gray2(p+t,q+3)-gray1(65+t,22))+abs( gray2(p+t,q+4)-gray1(65+t,23))+abs( gray2(p+t,q+5)-gray1(65+t,24))+abs( gray2(p+t,q+6)-gray1(65+t,25));
sum=sum+linet;
if sum>TK2
continue;
end
end
if sum TK2=sum;
center(2,3:4)=[p+3,q+3];
end
end
end
for i=101%:123
for j=11%:34
firstline=abs( gray2(i,j)-gray1(109,19) )+abs( gray2(i,j+1)-gray1(109,20))+abs( gray2(i,j+2)-gray1(109,21))+abs( gray2(i,j+3)-gray1(109,22))+abs( gray2(i,j+4)-gray1(109,23))+abs( gray2(i,j+5)-gray1(109,24))+abs( gray2(i,j+6)-gray1(109,25));
secondline=abs( gray2(i+1,j)-gray1(109+1,19))+abs( gray2(i+1,j+1)-gray1(109+1,20))+abs( gray2(i,j+2)-gray1(109+1,21))+abs( gray2(i,j+3)-gray1(109+1,22))+abs( gray2(i,j+4)-gray1(109+1,23))+abs( gray2(i,j+5)-gray1(109+1,24))+abs( gray2(i,j+6)-gray1(109+1,25));
thirdline=abs( gray2(i+2,j)-gray1(109+2,19))+abs( gray2(i+2,j+1)-gray1(109+2,20))+abs( gray2(i,j+2)-gray1(109+2,21))+abs( gray2(i,j+3)-gray1(109+2,22))+abs( gray2(i,j+4)-gray1(109+2,23))+abs( gray2(i,j+5)-gray1(109+2,24))+abs( gray2(i,j+6)-gray1(109+2,25));
forthline=abs( gray2(i+3,j)-gray1(109+3,19))+abs( gray2(i+3,j+1)-gray1(109+3,20))+abs( gray2(i,j+2)-gray1(109+3,21))+abs( gray2(i,j+3)-gray1(109+3,22))+abs( gray2(i,j+4)-gray1(109+3,23))+abs( gray2(i,j+5)-gray1(109+3,24))+abs( gray2(i,j+6)-gray1(109+3,25));
fifthline=abs( gray2(i+4,j)-gray1(109+4,19))+abs( gray2(i+4,j+1)-gray1(109+4,20))+abs( gray2(i,j+2)-gray1(109+4,21))+abs( gray2(i,j+3)-gray1(109+4,22))+abs( gray2(i,j+4)-gray1(109+4,23))+abs( gray2(i,j+5)-gray1(109+4,24))+abs( gray2(i,j+6)-gray1(109+4,25));
sixthline=abs( gray2(i+5,j)-gray1(109+5,19))+abs( gray2(i+5,j+1)-gray1(109+5,20))+abs( gray2(i,j+2)-gray1(109+5,21))+abs( gray2(i,j+3)-gray1(109+5,22))+abs( gray2(i,j+4)-gray1(109+5,23))+abs( gray2(i,j+5)-gray1(109+5,24))+abs( gray2(i,j+6)-gray1(109+5,25));
seventhline=abs( gray2(i+6,j)-gray1(109+6,19))+abs( gray2(i+6,j+1)-gray1(109+6,20))+abs( gray2(i,j+2)-gray1(109+6,21))+abs( gray2(i,j+3)-gray1(109+6,22))+abs( gray2(i,j+4)-gray1(109+6,23))+abs( gray2(i,j+5)-gray1(109+6,24))+abs( gray2(i,j+6)-gray1(109+6,25));
block3=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK3=block3;
end
end
sum=0;
for p=91:126
for q=1:36
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(109+t,19) )+abs( gray2(p+t,q+1)-gray1(109+t,20))+abs( gray2(p+t,q+2)-gray1(109+t,21))+abs( gray2(p+t,q+3)-gray1(109+t,22))+abs( gray2(p+t,q+4)-gray1(109+t,23))+abs( gray2(p+t,q+5)-gray1(109+t,24))+abs( gray2(p+t,q+6)-gray1(109+t,25));
sum=sum+linet;
if sum>TK3
center(3,3:4)=[104,14];
continue;
end
end
if sum TK3=sum;
center(3,3:4)=[p+3,q+3];
end
end
end
for i=11%:34
for j=127%:149
firstline=abs( gray2(i,j)-gray1(19,135) )+abs( gray2(i,j+1)-gray1(19,136))+abs( gray2(i,j+2)-gray1(19,137))+abs( gray2(i,j+3)-gray1(19,138))+abs( gray2(i,j+4)-gray1(19,139))+abs( gray2(i,j+5)-gray1(19,140))+abs( gray2(i,j+6)-gray1(19,141));
secondline=abs( gray2(i+1,j)-gray1(19+1,135))+abs( gray2(i+1,j+1)-gray1(19+1,136))+abs( gray2(i,j+2)-gray1(19+1,137))+abs( gray2(i,j+3)-gray1(19+1,138))+abs( gray2(i,j+4)-gray1(19+1,139))+abs( gray2(i,j+5)-gray1(19+1,140))+abs( gray2(i,j+6)-gray1(19+1,141));
thirdline=abs( gray2(i+2,j)-gray1(19+2,135))+abs( gray2(i+2,j+1)-gray1(19+2,136))+abs( gray2(i,j+2)-gray1(19+2,137))+abs( gray2(i,j+3)-gray1(19+2,138))+abs( gray2(i,j+4)-gray1(19+2,139))+abs( gray2(i,j+5)-gray1(19+2,140))+abs( gray2(i,j+6)-gray1(19+2,141));
forthline=abs( gray2(i+3,j)-gray1(19+3,135))+abs( gray2(i+3,j+1)-gray1(19+3,136))+abs( gray2(i,j+2)-gray1(19+3,137))+abs( gray2(i,j+3)-gray1(19+3,138))+abs( gray2(i,j+4)-gray1(19+3,139))+abs( gray2(i,j+5)-gray1(19+3,140))+abs( gray2(i,j+6)-gray1(19+3,141));
fifthline=abs( gray2(i+4,j)-gray1(19+4,135))+abs( gray2(i+4,j+1)-gray1(19+4,136))+abs( gray2(i,j+2)-gray1(19+4,137))+abs( gray2(i,j+3)-gray1(19+4,138))+abs( gray2(i,j+4)-gray1(19+4,139))+abs( gray2(i,j+5)-gray1(19+4,140))+abs( gray2(i,j+6)-gray1(19+4,141));
sixthline=abs( gray2(i+5,j)-gray1(19+5,135))+abs( gray2(i+5,j+1)-gray1(19+5,136))+abs( gray2(i,j+2)-gray1(19+5,137))+abs( gray2(i,j+3)-gray1(19+5,138))+abs( gray2(i,j+4)-gray1(19+5,139))+abs( gray2(i,j+5)-gray1(19+5,140))+abs( gray2(i,j+6)-gray1(19+5,141));
seventhline=abs( gray2(i+6,j)-gray1(19+6,135))+abs( gray2(i+6,j+1)-gray1(19+6,136))+abs( gray2(i,j+2)-gray1(19+6,137))+abs( gray2(i,j+3)-gray1(19+6,138))+abs( gray2(i,j+4)-gray1(19+6,139))+abs( gray2(i,j+5)-gray1(19+6,140))+abs( gray2(i,j+6)-gray1(19+6,141));
block4=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK4=block4;
end
end
sum=0;
for p=1:36
for q=117:152
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(19+t,135) )+abs( gray2(p+t,q+1)-gray1(19+t,136))+abs( gray2(p+t,q+2)-gray1(19+t,137))+abs( gray2(p+t,q+3)-gray1(19+t,138))+abs( gray2(p+t,q+4)-gray1(19+t,139))+abs( gray2(p+t,q+5)-gray1(19+t,140))+abs( gray2(p+t,q+6)-gray1(19+t,141));
sum=sum+linet;
if sum>TK4
continue;
end
end
if sum TK4=sum;
center(4,3:4)=[p+3,q+3];
end
end
end
for i=57%:79
for j=127%:149
firstline=abs( gray2(i,j)-gray1(65,135) )+abs( gray2(i,j+1)-gray1(65,136))+abs( gray2(i,j+2)-gray1(65,137))+abs( gray2(i,j+3)-gray1(65,138))+abs( gray2(i,j+4)-gray1(65,139))+abs( gray2(i,j+5)-gray1(65,140))+abs( gray2(i,j+6)-gray1(65,141));
secondline=abs( gray2(i+1,j)-gray1(65+1,135))+abs( gray2(i+1,j+1)-gray1(65+1,136))+abs( gray2(i,j+2)-gray1(65+1,137))+abs( gray2(i,j+3)-gray1(65+1,138))+abs( gray2(i,j+4)-gray1(65+1,139))+abs( gray2(i,j+5)-gray1(65+1,140))+abs( gray2(i,j+6)-gray1(65+1,141));
thirdline=abs( gray2(i+2,j)-gray1(65+2,135))+abs( gray2(i+2,j+1)-gray1(65+2,136))+abs( gray2(i,j+2)-gray1(65+2,137))+abs( gray2(i,j+3)-gray1(65+2,138))+abs( gray2(i,j+4)-gray1(65+2,139))+abs( gray2(i,j+5)-gray1(65+2,140))+abs( gray2(i,j+6)-gray1(65+2,141));
forthline=abs( gray2(i+3,j)-gray1(65+3,135))+abs( gray2(i+3,j+1)-gray1(65+3,136))+abs( gray2(i,j+2)-gray1(65+3,137))+abs( gray2(i,j+3)-gray1(65+3,138))+abs( gray2(i,j+4)-gray1(65+3,139))+abs( gray2(i,j+5)-gray1(65+3,140))+abs( gray2(i,j+6)-gray1(65+3,141));
fifthline=abs( gray2(i+4,j)-gray1(65+4,135))+abs( gray2(i+4,j+1)-gray1(65+4,136))+abs( gray2(i,j+2)-gray1(65+4,137))+abs( gray2(i,j+3)-gray1(65+4,138))+abs( gray2(i,j+4)-gray1(65+4,139))+abs( gray2(i,j+5)-gray1(65+4,140))+abs( gray2(i,j+6)-gray1(65+4,141));
sixthline=abs( gray2(i+5,j)-gray1(65+5,135))+abs( gray2(i+5,j+1)-gray1(65+5,136))+abs( gray2(i,j+2)-gray1(65+5,137))+abs( gray2(i,j+3)-gray1(65+5,138))+abs( gray2(i,j+4)-gray1(65+5,139))+abs( gray2(i,j+5)-gray1(65+5,140))+abs( gray2(i,j+6)-gray1(65+5,141));
seventhline=abs( gray2(i+6,j)-gray1(65+6,135))+abs( gray2(i+6,j+1)-gray1(65+6,136))+abs( gray2(i,j+2)-gray1(65+6,137))+abs( gray2(i,j+3)-gray1(65+6,138))+abs( gray2(i,j+4)-gray1(65+6,139))+abs( gray2(i,j+5)-gray1(65+6,140))+abs( gray2(i,j+6)-gray1(65+6,141));
block5=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK5=block5;
end
end
sum=0;
for p=47:82
for q=117:152
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(65+t,135) )+abs( gray2(p+t,q+1)-gray1(65+t,136))+abs( gray2(p+t,q+2)-gray1(65+t,137))+abs( gray2(p+t,q+3)-gray1(65+t,138))+abs( gray2(p+t,q+4)-gray1(65+t,139))+abs( gray2(p+t,q+5)-gray1(65+t,140))+abs( gray2(p+t,q+6)-gray1(65+t,141));
sum=sum+linet;
if sum>TK5
continue;
end
end
if sum TK5=sum;
center(5,3:4)=[p+3,q+3];
end
end
end
for i=101%:123
for j=127%:149
firstline=abs( gray2(i,j)-gray1(109,135) )+abs( gray2(i,j+1)-gray1(109,136))+abs( gray2(i,j+2)-gray1(109,137))+abs( gray2(i,j+3)-gray1(109,138))+abs( gray2(i,j+4)-gray1(109,139))+abs( gray2(i,j+5)-gray1(109,140))+abs( gray2(i,j+6)-gray1(109,141));
secondline=abs( gray2(i+1,j)-gray1(109+1,135))+abs( gray2(i+1,j+1)-gray1(109+1,136))+abs( gray2(i,j+2)-gray1(109+1,137))+abs( gray2(i,j+3)-gray1(109+1,138))+abs( gray2(i,j+4)-gray1(109+1,139))+abs( gray2(i,j+5)-gray1(109+1,140))+abs( gray2(i,j+6)-gray1(109+1,141));
thirdline=abs( gray2(i+2,j)-gray1(109+2,135))+abs( gray2(i+2,j+1)-gray1(109+2,136))+abs( gray2(i,j+2)-gray1(109+2,137))+abs( gray2(i,j+3)-gray1(109+2,138))+abs( gray2(i,j+4)-gray1(109+2,139))+abs( gray2(i,j+5)-gray1(109+2,140))+abs( gray2(i,j+6)-gray1(109+2,141));
forthline=abs( gray2(i+3,j)-gray1(109+3,135))+abs( gray2(i+3,j+1)-gray1(109+3,136))+abs( gray2(i,j+2)-gray1(109+3,137))+abs( gray2(i,j+3)-gray1(109+3,138))+abs( gray2(i,j+4)-gray1(109+3,139))+abs( gray2(i,j+5)-gray1(109+3,140))+abs( gray2(i,j+6)-gray1(109+3,141));
fifthline=abs( gray2(i+4,j)-gray1(109+4,135))+abs( gray2(i+4,j+1)-gray1(109+4,136))+abs( gray2(i,j+2)-gray1(109+4,137))+abs( gray2(i,j+3)-gray1(109+4,138))+abs( gray2(i,j+4)-gray1(109+4,139))+abs( gray2(i,j+5)-gray1(109+4,140))+abs( gray2(i,j+6)-gray1(109+4,141));
sixthline=abs( gray2(i+5,j)-gray1(109+5,135))+abs( gray2(i+5,j+1)-gray1(109+5,136))+abs( gray2(i,j+2)-gray1(109+5,137))+abs( gray2(i,j+3)-gray1(109+5,138))+abs( gray2(i,j+4)-gray1(109+5,139))+abs( gray2(i,j+5)-gray1(109+5,140))+abs( gray2(i,j+6)-gray1(109+5,141));
seventhline=abs( gray2(i+6,j)-gray1(109+6,135))+abs( gray2(i+6,j+1)-gray1(109+6,136))+abs( gray2(i,j+2)-gray1(109+6,137))+abs( gray2(i,j+3)-gray1(109+6,138))+abs( gray2(i,j+4)-gray1(109+6,139))+abs( gray2(i,j+5)-gray1(109+6,140))+abs( gray2(i,j+6)-gray1(109+6,141));
block6=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK6=block6;
end
end
sum=0;
for p=91:126
for q=117:152
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(109+t,135) )+abs( gray2(p+t,q+1)-gray1(109+t,136))+abs( gray2(p+t,q+2)-gray1(109+t,137))+abs( gray2(p+t,q+3)-gray1(109+t,138))+abs( gray2(p+t,q+4)-gray1(109+t,139))+abs( gray2(p+t,q+5)-gray1(109+t,140))+abs( gray2(p+t,q+6)-gray1(109+t,141));
sum=sum+linet;
if sum>TK6
continue;
end
end
if sum TK6=sum;
center(6,3:4)=[p+3,q+3];
end
end
end
for i=11%:34
for j=54%:34
firstline=abs( gray2(i,j)-gray1(19,62) )+abs( gray2(i,j+1)-gray1(19,63))+abs( gray2(i,j+2)-gray1(19,64))+abs( gray2(i,j+3)-gray1(19,65))+abs( gray2(i,j+4)-gray1(19,66))+abs( gray2(i,j+5)-gray1(19,67))+abs( gray2(i,j+6)-gray1(19,68));
secondline=abs( gray2(i+1,j)-gray1(19+1,62))+abs( gray2(i+1,j+1)-gray1(19+1,63))+abs( gray2(i,j+2)-gray1(19+1,64))+abs( gray2(i,j+3)-gray1(19+1,65))+abs( gray2(i,j+4)-gray1(19+1,66))+abs( gray2(i,j+5)-gray1(19+1,67))+abs( gray2(i,j+6)-gray1(19+1,68));
thirdline=abs( gray2(i+2,j)-gray1(19+2,62))+abs( gray2(i+2,j+1)-gray1(19+2,63))+abs( gray2(i,j+2)-gray1(19+2,64))+abs( gray2(i,j+3)-gray1(19+2,65))+abs( gray2(i,j+4)-gray1(19+2,66))+abs( gray2(i,j+5)-gray1(19+2,67))+abs( gray2(i,j+6)-gray1(19+2,68));
forthline=abs( gray2(i+3,j)-gray1(19+3,62))+abs( gray2(i+3,j+1)-gray1(19+3,63))+abs( gray2(i,j+2)-gray1(19+3,64))+abs( gray2(i,j+3)-gray1(19+3,65))+abs( gray2(i,j+4)-gray1(19+3,66))+abs( gray2(i,j+5)-gray1(19+3,67))+abs( gray2(i,j+6)-gray1(19+3,68));
fifthline=abs( gray2(i+4,j)-gray1(19+4,62))+abs( gray2(i+4,j+1)-gray1(19+4,63))+abs( gray2(i,j+2)-gray1(19+4,64))+abs( gray2(i,j+3)-gray1(19+4,65))+abs( gray2(i,j+4)-gray1(19+4,66))+abs( gray2(i,j+5)-gray1(19+4,67))+abs( gray2(i,j+6)-gray1(19+4,68));
sixthline=abs( gray2(i+5,j)-gray1(19+5,62))+abs( gray2(i+5,j+1)-gray1(19+5,63))+abs( gray2(i,j+2)-gray1(19+5,64))+abs( gray2(i,j+3)-gray1(19+5,65))+abs( gray2(i,j+4)-gray1(19+5,66))+abs( gray2(i,j+5)-gray1(19+5,67))+abs( gray2(i,j+6)-gray1(19+5,68));
seventhline=abs( gray2(i+6,j)-gray1(19+6,62))+abs( gray2(i+6,j+1)-gray1(19+6,63))+abs( gray2(i,j+2)-gray1(19+6,64))+abs( gray2(i,j+3)-gray1(19+6,65))+abs( gray2(i,j+4)-gray1(19+6,66))+abs( gray2(i,j+5)-gray1(19+6,67))+abs( gray2(i,j+6)-gray1(19+6,68));
block7=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK7=block7;
end
end
sum=0;
for p=1:36
for q=44:79
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(19+t,62) )+abs( gray2(p+t,q+1)-gray1(19+t,63))+abs( gray2(p+t,q+2)-gray1(19+t,64))+abs( gray2(p+t,q+3)-gray1(19+t,65))+abs( gray2(p+t,q+4)-gray1(19+t,66))+abs( gray2(p+t,q+5)-gray1(19+t,67))+abs( gray2(p+t,q+6)-gray1(19+t,68));
sum=sum+linet;
if sum>TK7
continue;
end
end
if sum TK7=sum;
center(7,3:4)=[p+3,q+3];
end
end
end
for i=57%:79
for j=54%:34
firstline=abs( gray2(i,j)-gray1(65,62) )+abs( gray2(i,j+1)-gray1(65,63))+abs( gray2(i,j+2)-gray1(65,64))+abs( gray2(i,j+3)-gray1(65,65))+abs( gray2(i,j+4)-gray1(65,66))+abs( gray2(i,j+5)-gray1(65,67))+abs( gray2(i,j+6)-gray1(65,68));
secondline=abs( gray2(i+1,j)-gray1(65+1,62))+abs( gray2(i+1,j+1)-gray1(65+1,63))+abs( gray2(i,j+2)-gray1(65+1,64))+abs( gray2(i,j+3)-gray1(65+1,65))+abs( gray2(i,j+4)-gray1(65+1,66))+abs( gray2(i,j+5)-gray1(65+1,67))+abs( gray2(i,j+6)-gray1(65+1,68));
thirdline=abs( gray2(i+2,j)-gray1(65+2,62))+abs( gray2(i+2,j+1)-gray1(65+2,63))+abs( gray2(i,j+2)-gray1(65+2,64))+abs( gray2(i,j+3)-gray1(65+2,65))+abs( gray2(i,j+4)-gray1(65+2,66))+abs( gray2(i,j+5)-gray1(65+2,67))+abs( gray2(i,j+6)-gray1(65+2,68));
forthline=abs( gray2(i+3,j)-gray1(65+3,62))+abs( gray2(i+3,j+1)-gray1(65+3,63))+abs( gray2(i,j+2)-gray1(65+3,64))+abs( gray2(i,j+3)-gray1(65+3,65))+abs( gray2(i,j+4)-gray1(65+3,66))+abs( gray2(i,j+5)-gray1(65+3,67))+abs( gray2(i,j+6)-gray1(65+3,68));
fifthline=abs( gray2(i+4,j)-gray1(65+4,62))+abs( gray2(i+4,j+1)-gray1(65+4,63))+abs( gray2(i,j+2)-gray1(65+4,64))+abs( gray2(i,j+3)-gray1(65+4,65))+abs( gray2(i,j+4)-gray1(65+4,66))+abs( gray2(i,j+5)-gray1(65+4,67))+abs( gray2(i,j+6)-gray1(65+4,68));
sixthline=abs( gray2(i+5,j)-gray1(65+5,62))+abs( gray2(i+5,j+1)-gray1(65+5,63))+abs( gray2(i,j+2)-gray1(65+5,64))+abs( gray2(i,j+3)-gray1(65+5,65))+abs( gray2(i,j+4)-gray1(65+5,66))+abs( gray2(i,j+5)-gray1(65+5,67))+abs( gray2(i,j+6)-gray1(65+5,68));
seventhline=abs( gray2(i+6,j)-gray1(65+6,62))+abs( gray2(i+6,j+1)-gray1(65+6,63))+abs( gray2(i,j+2)-gray1(65+6,64))+abs( gray2(i,j+3)-gray1(65+6,65))+abs( gray2(i,j+4)-gray1(65+6,66))+abs( gray2(i,j+5)-gray1(65+6,67))+abs( gray2(i,j+6)-gray1(65+6,68));
block8=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK8=block8;
end
end
sum=0;
for p=47:82
for q=44:79
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(65+t,62) )+abs( gray2(p+t,q+1)-gray1(65+t,63))+abs( gray2(p+t,q+2)-gray1(65+t,64))+abs( gray2(p+t,q+3)-gray1(65+t,65))+abs( gray2(p+t,q+4)-gray1(65+t,66))+abs( gray2(p+t,q+5)-gray1(65+t,67))+abs( gray2(p+t,q+6)-gray1(65+t,68));
sum=sum+linet;
if sum>TK8
continue;
end
end
if sum TK8=sum;
center(8,3:4)=[p+3,q+3];
end
end
end
for i=101%:123
for j=54%:34
firstline=abs( gray2(i,j)-gray1(109,62) )+abs( gray2(i,j+1)-gray1(109,63))+abs( gray2(i,j+2)-gray1(109,64))+abs( gray2(i,j+3)-gray1(109,65))+abs( gray2(i,j+4)-gray1(109,66))+abs( gray2(i,j+5)-gray1(109,67))+abs( gray2(i,j+6)-gray1(109,68));
secondline=abs( gray2(i+1,j)-gray1(109+1,62))+abs( gray2(i+1,j+1)-gray1(109+1,63))+abs( gray2(i,j+2)-gray1(109+1,64))+abs( gray2(i,j+3)-gray1(109+1,65))+abs( gray2(i,j+4)-gray1(109+1,66))+abs( gray2(i,j+5)-gray1(109+1,67))+abs( gray2(i,j+6)-gray1(109+1,68));
thirdline=abs( gray2(i+2,j)-gray1(109+2,62))+abs( gray2(i+2,j+1)-gray1(109+2,63))+abs( gray2(i,j+2)-gray1(109+2,64))+abs( gray2(i,j+3)-gray1(109+2,65))+abs( gray2(i,j+4)-gray1(109+2,66))+abs( gray2(i,j+5)-gray1(109+2,67))+abs( gray2(i,j+6)-gray1(109+2,68));
forthline=abs( gray2(i+3,j)-gray1(109+3,62))+abs( gray2(i+3,j+1)-gray1(109+3,63))+abs( gray2(i,j+2)-gray1(109+3,64))+abs( gray2(i,j+3)-gray1(109+3,65))+abs( gray2(i,j+4)-gray1(109+3,66))+abs( gray2(i,j+5)-gray1(109+3,67))+abs( gray2(i,j+6)-gray1(109+3,68));
fifthline=abs( gray2(i+4,j)-gray1(109+4,62))+abs( gray2(i+4,j+1)-gray1(109+4,63))+abs( gray2(i,j+2)-gray1(109+4,64))+abs( gray2(i,j+3)-gray1(109+4,65))+abs( gray2(i,j+4)-gray1(109+4,66))+abs( gray2(i,j+5)-gray1(109+4,67))+abs( gray2(i,j+6)-gray1(109+4,68));
sixthline=abs( gray2(i+5,j)-gray1(109+5,62))+abs( gray2(i+5,j+1)-gray1(109+5,63))+abs( gray2(i,j+2)-gray1(109+5,64))+abs( gray2(i,j+3)-gray1(109+5,65))+abs( gray2(i,j+4)-gray1(109+5,66))+abs( gray2(i,j+5)-gray1(109+5,67))+abs( gray2(i,j+6)-gray1(109+5,68));
seventhline=abs( gray2(i+6,j)-gray1(109+6,62))+abs( gray2(i+6,j+1)-gray1(109+6,63))+abs( gray2(i,j+2)-gray1(109+6,64))+abs( gray2(i,j+3)-gray1(109+6,65))+abs( gray2(i,j+4)-gray1(109+6,66))+abs( gray2(i,j+5)-gray1(109+6,67))+abs( gray2(i,j+6)-gray1(109+6,68));
block9=firstline+secondline+thirdline+fifthline+fifthline+sixthline+seventhline;
TK9=block9;
end
end
sum=0;
for p=91:126
for q=44:79
sum=0;
for t=0:6
linet=abs( gray2(p+t,q)-gray1(109+t,62) )+abs( gray2(p+t,q+1)-gray1(109+t,63))+abs( gray2(p+t,q+2)-gray1(109+t,64))+abs( gray2(p+t,q+3)-gray1(109+t,65))+abs( gray2(p+t,q+4)-gray1(109+t,66))+abs( gray2(p+t,q+5)-gray1(109+t,67))+abs( gray2(p+t,q+6)-gray1(109+t,68));
sum=sum+linet;
if sum>TK9
center(9,3:4)=[104,14];
continue;
end
end
if sum TK9=sum;
center(9,3:4)=[p+3,q+3];
end
end
end
%%%%%%%%%%%%%%%get shift%%%%%%%%%%%%%
ud=0;lr=0;
length=size(center,1);
for t=1:length
ud=ud+center(t,3)-center(t,1);
lr=lr+center(t,4)-center(t,2);
end
ud=ud/length
lr=lr/length
%%%%%%%%%%%%%%%get rotate%%%%%%%%%%%%%
% length=size(center,1);
% sum=0;
% for count=1:length
% va=center(count,3)-center(count,1);
% ha=center(count,4)-center(count,2);
% if ( va==0 )
% ang=0;
% elseif ( va~=0 && ha==0)
% ang=0;
% else rotate=atan(va/ha);
% ang=180*rotate/pi;
% end
% center(count,5)=ang;
% sum=sum+ang;
% end
% meanangle=sum/length
%%%%%%%%%%%%%%%%%用余弦公式求到图片旋转中心的角度变化%%%%%%%%%%%%%%%
imagecenter_v=size(gray1,1)/2;
imagecenter_h=size(gray1,2)/2;
center(5,6:7)=[imagecenter_v,imagecenter_h];
sum_angle=0;
for count=1:length
center_distance= sqrt( abs((center(count,1)-center(count,3))^2 + (center(count,2)-center(count,4))^2 ) );%%%%%%%%%%%%%%中心距离%%%%%
center(count,8)=center_distance;
ori_center_core_distance= sqrt( abs( (center(count,1)-center(5,6))^2 +(center(count,2)-center(5,7))^2 ));%%%%%%%%%%上一帧块中心到图中心的距离%%%%%
center(count,9)=ori_center_core_distance ;
next_center_core_distance= sqrt( abs( (center(count,3)-center(5,6))^2+ (center(count,4)-center(5,7))^2 ));%%%%%%%%%下一帧块中心到图中心的距离%%%%%%%
center(count,10)=next_center_core_distance ;
ang=acos( ((center(count,9))^2 +(center(count,10))^2- (center(count,8))^2 ) /(2*center(count,9)*center(count,10)) );%%%%%%%%%%%%%余弦公式求角度%%%%%%%%%
rotate=180*ang/pi;
center(count,11)=rotate;
sum_angle=sum_angle+center(count,11);
end
%%%%%%%%%%去除奇点:由于视频帧间角度变化小,采用去除最小值和最大值,然后求均值,所有角度与均值的差在阈值内时保留,超出则删去。阈值待定%%%%%%%%%
%%%%%%%%%%冒泡法排序,求去掉最大值最小值后的均值%%%
mean_mid=bubble_mean(center(:,11));
del=0;
sum_angle_final=0;
for count=1:length
center(count,12) = center(count,11)-mean_mid;
if center(count,12)>5
del=del+1;
center(count,12)=0;
end
if center(count,12)~=0
sum_angle_final=sum_angle_final+center(count,11);
end
end
mean_angle_final=sum_angle_final/(length-del)