特征点匹配

clc;
clear;
%%%%%%%%%%%%%目标搜索区域大小
global QQ;
QQ=32;
%%%%%%%%%%%%%矩阵
global K;
K=5;       %3*3
%%%%%%%%%%%%%读取图像1
I1=imread('num272.jpg');
global G1;
G1=rgb2gray(I1);
%info1=imfinfo('num403.jpg');
%%%%%%%%%%%%%%图像2
I2=imread('num275.jpg');
global G2;
G2=rgb2gray(I2);
%info2=imfinfo('num414.jpg');
% global [width,height]=size(I1);
% global aaa=1;
subplot(1,2,1);
imshow(I1);
subplot(1,2,2);
imshow(I2);
set(gcf,'WindowButtonDownFcn',@ButttonDownFcn);


function ButttonDownFcn(src,event)
global G1;
global G2;
global QQ;
global K;
pt = get(gca,'CurrentPoint');
y = round (pt(1,1));
x = round (pt(1,2));
hold on
plot(y,x,'r+');
hold off
fprintf('x=%g,y=%g\n',x,y);
fprintf('%g\n',G1(x,y));

k=K-2;
M=G1(x-k:x+k,y-k:y+k); %选定点周围的3*3矩阵
xx=x;%第二幅图的对应点坐标
yy=y;
G2G=ones(2*QQ+1)*255;

for p=xx-QQ:xx+QQ%离对应点5之内的矩阵
    for q=yy-QQ:yy+QQ
        MM=G2(p-k:p+k,q-k:q+k);%搜索区域内点的3*3矩阵
      G2G(p-(xx-QQ-1),q-(yy-QQ-1))=sum(sum(imabsdiff(M,MM)));%矩阵绝对差之和
        
    end
end

mi=min(G2G);  %找出矩阵中每列中的最小元素,构成行向量m
mm=min(mi); %进一步找出m中的最小元素mm,当然也就是矩阵A中的最小元素
[row,column]=find(G2G==mm);  %给出最小值mm在矩阵A中的行号row和列号column
row=row+xx-QQ-1;%转换坐标
column=column+yy-QQ-1;
fprintf('NEW x=%g,y=%g\n',row,column);
fprintf('%g',G2(x,y));

subplot(1,2,2);
hold on
plot(column,row,'r+');
hold off

 

posted @ 2013-10-08 21:42  Albert_C  阅读(383)  评论(0)    收藏  举报