电子图像稳定,是指利用数宇图像处理技术消除或者减轻视频图像序列中因为摄像机的抖动而引入的非平稳运动(抖动),使图像序列稳定的处理过程。
图像的帧间运动变化主要有全局变化和局部变化。全局变化是指相机参数变化或者相机抖动等动作引起的图片全局变化。局部运动是指被拍摄物体运动引起的局部变化。图像稳定就是对全局运动进行估计和补偿。运动估计的主要方法有像素递归法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个候选块的匹配中,可以看到计算量明显减小,而且计算精度没有受到影响。
于±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
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
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
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( g
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
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
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
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( g