图像中角点特征点提取与匹配算法.docx
- 文档编号:5709897
- 上传时间:2022-12-31
- 格式:DOCX
- 页数:20
- 大小:2.83MB
图像中角点特征点提取与匹配算法.docx
《图像中角点特征点提取与匹配算法.docx》由会员分享,可在线阅读,更多相关《图像中角点特征点提取与匹配算法.docx(20页珍藏版)》请在冰豆网上搜索。
图像中角点特征点提取与匹配算法
角点提取与匹配算法实验报告
1说明
本文实验的目标是对于两幅相似的图像,通过角点检测算法,进而找出这两幅图像的共同点,从而可以把这两幅图像合并成一幅图像。
下面描述该实验的基本步骤:
1.本文所采用的角点检测算法是Harris角点检测算法,该算法的基本原理是取以目标像素点为中心的一个小窗口,计算窗口沿任何方向移动后的灰度变化,并用解析形式表达。
设以像素点(x,y)为中心的小窗口在X方向上移动u,y方向上移动v,Harris给出了灰度变化度量的解析表达式:
(1)
其中,
为窗口内的灰度变化度量;
为窗口函数,一般定义为
;I为图像灰度函数,略去无穷小项有:
(2)
将
化为二次型有:
(3)
M为实对称矩阵:
(4)
通过对角化处理得到:
(5)
其中,R为旋转因子,对角化处理后并不改变以u,v为坐标参数的空间曲面的形状,其特征值反应了两个主轴方向的图像表面曲率。
当两个特征值均较小时,表明目标点附近区域为“平坦区域”;特征值一大一小时,表明特征点位于“边缘”上;只有当两个特征值均比较大时,沿任何方向的移动均将导致灰度的剧烈变化。
Harris的角点响应函数(CRF)表达式由此而得到:
(6)
其中:
det(M)表示矩阵M的行列式,trace(M)表示矩阵的迹。
当目标像素点的CRF值大于给定的阈值时,该像素点即为角点。
下面是图像一用Harris角点检测算法得到的角点坐标位置
x
212
301
309
353
58
201
178
58
202
186
329
161
202
58
57
201
306
y
2
65
68
77
94
94
142
143
144
150
150
170
177
178
228
228
228
在图像一上画出该角点的坐标位置如下图所示:
其中蓝色小方块代表的是检测出来的角点坐标位置。
2.匹配。
将两幅图像进行Harris角点检测后,分别得到角点对应与该图像的坐标位置,以该坐标位置为中心,分别取其附近的8个像素值,然后进行与另一幅图像进行匹配,找出距离最小的点作为匹配点。
例如下面是图像一角点坐标位置
x
212
301
309
353
58
201
178
58
202
186
329
161
202
58
57
201
306
y
2
65
68
77
94
94
142
143
144
150
150
170
177
178
228
228
228
与该位置对应的8个像素值分别为
角点1
角点2
角点3
。
。
。
角点17
(x-1,y-1)
30
7
35
。
。
。
142
(x-1,y)
48
59
17
。
。
。
9
(x-1,y+1)
37
108
128
。
。
。
63
(x,y+1)
31
114
15
。
。
。
101
(x+1,y+1)
143
183
32
。
。
。
95
(x+1,y)
101
177
25
。
。
。
20
(x+1,y-1)
2
92
24
。
。
。
49
(x,y-1)
3
22
30
。
。
。
198
接着,将图像一中的角点1与图像二中的所有角点进行相减,得到一个最小误差值,并记录下该位置,这样依次将图像一中的角点2,角点3一直到角点17都进行相减,即可得到两幅图像之间的最佳匹配点。
下面是两幅图像角点匹配的最佳坐标位置
匹配点
0
10
13
14
15
16
17
0
0
0
4
0
5
12
0
0
0
误差值
0
336
105
64
53
34
104
0
0
0
389
0
204
400
0
0
0
其中匹配点的值为0代表没有找到匹配点
3.显示匹配点。
对已经找出的匹配点,在图像上进行显示,这样有利于人眼判断该算法是否匹配正确。
下面是第一次显示找到的匹配点(两幅图像中共有9个匹配点)
下面是第二次显示找到的匹配点(比上一次少一个,判断依据是将误差值最大的点去除)
从上面可以看出,14号点已经被删除,原因是该点的误差值最大
下面是最后一次显示找到的匹配点
只留下最后三个匹配点,如果少于三个匹配点,则很难进行两幅图像的合并,所以当只有留下三个匹配点的时候,程序退出。
2实验结果
实验一
原始图像
第一次匹配的结果
最后一次匹配的结果
实验二
原始图像
第一次匹配的结果
最后一次匹配的结果
实验三
原始图像
第一次匹配的结果
最后一次匹配的结果
实验四
原始图像
第一次匹配的结果
最后一次匹配的结果
可以看出,利用该算法进行两幅图像匹配结果还算正确。
算法代码(用matlab语言写的)
functiontest()
%Thetestfunctiongivesanexampleofkeypointextractionusingthe
%methods:
%-Harris
%
%Example
%=======
%test();
%Harris
%importthefirstpicture
%img11=imread('door1.jpg');
%img11=imread('gx21.jpg');
%img11=imread('woman1.jpg');
%img1=double(img11(:
:
1));
img11=imread('91.jpg');
img1=rgb2gray(img11);
img1=double(img1(:
:
));
pt1=kp_harris(img1);
%draw(img11,pt1,'Harris');
%importthesecondpicture
%img21=imread('door2.jpg');
%img21=imread('gx22.jpg');
%img21=imread('woman2.jpg');
%img2=double(img21(:
:
1));
img21=imread('92.jpg');
img2=rgb2gray(img21);
img2=double(img2(:
:
));
pt2=kp_harris(img2);
%draw(img21,pt2,'Harris');
%matchkeypointswithintwopictures.
result=match(img1,pt1,img2,pt2);
result(1,intersect(find(result(1,:
)>0),find(result(2,:
)==0)))=0;
%result
%pause;
while(length(find(result(1,:
)>0))>3)
result
draw2(img11,img21,pt1,pt2,result);
%find(result(1,:
)>0)
pause;
[indexindex]=max(result(2,:
));
result(1,index
(1))=0;
result(2,index
(1))=0;
%result(1,I
(1))=result(2,I
(1))=0
end
draw2(img11,img21,pt1,pt2,result);
end
functiondraw2(img1,img2,pt1,pt2,result)
h=figure;
%set(gcf,'outerposition',get(0,'screensize'));
subplot(1,2,1);
%holdon;
imshow(img1);
subplot(1,2,2);
%holdon;
imshow(img2);
s=size(pt1,2);
subplot(1,2,1);
fori=1:
size(pt1,1)
rectangle('Position',[pt1(i,2)-s,pt1(i,1)-s,2*s,2*s],'Curvature',[00],'EdgeColor','b','LineWidth',2);
%text(pt1(i,2)+3,pt1(i,1)+3,num2str(i),'BackgroundColor',[111]);
%text(pt2(i,2),pt2(i,1),num2str(i));
%plot(pt2(i,2),pt2(i,1));
end
subplot(1,2,2);
fori=1:
size(pt2,1)
rectangle('Position',[pt2(i,2)-s,pt2(i,1)-s,2*s,2*s],'Curvature',[00],'EdgeColor','b','LineWidth',2);
end
%result
%size(pt1)
%size(pt2)
fori=1:
size(result,2)
if(result(1,i)~=0)
subplot(1,2,1);
text(pt1(result(1,i),2)+3,pt1(result(1,i),1)+3,num2str(i),'BackgroundColor',[111]);
%result(1,i)
%pt1(result(1,i),2)
%pt1(result(1,i),1)
subplot(1,2,2);
text(pt2(i,2)+3,pt2(i,1)+3,num2str(i),'BackgroundColor',[111]);
end
end
end
functionresult=match(img1,pt1,img2,pt2)
%得到标定点周围的像素值
regionValue1=getRegionValue(img1,pt1);
len1=size(regionValue1,2);
regionValue2=getRegionValue(img2,pt2);
len2=size(regionValue2,2);
%找出最佳匹配点
result=zeros(2,len2);
fori=1:
len1
B=regionValue1(:
i);
%abs(regionValue2-B(:
ones(1,size(regionValue2,2))))
%sum(abs(regionValue2-B(:
ones(1,size(regionValue2,2)))))
[value,index]=sort(sum(abs(regionValue2-B(:
ones(1,size(regionValue2,2))))));
%value
(1)
%index
(1)
%saveindexandvalue
if((result(1,index
(1))==0)||(result(2,index
(1))>value
(1)))
result(1,index
(1))=i;
result(2,index
(1))=value
(1);
end
end
end
functionregionValue=getRegionValue(img,pt)
len=size(pt,1);
regionValue=zeros(8,len);
maxX=size(img,1);
maxY=size(img,2);
fori=1:
len
x=pt(i,1);
y=pt(i,2);
%1
if(x-1<1||y-1<1)
regionValue(1,i)=100;
else
regionValue(1,i)=img(x,y)-img(x-1,y-1);
end
%2
if(x-1<1)
regionValue(2,i)=200;
else
regionValue(2,i)=img(x,y)-img(x-1,y);
end
%3
if(x-1<1||y+1>maxY)
regionValue(3,i)=300;
else
regionValue(3,i)=img(x,y)-img(x-1,y+1);
end
%4
if(y+1>maxY)
regionValue(4,i)=400;
else
regionValue(4,i)=img(x,y)-img(x,y+1);
end
%5
if(x+1>maxX||y+1>maxY)
regionValue(5,i)=500;
else
regionValue(5,i)=img(x,y)-img(x+1,y+1);
end
%6
if(x+1>maxX)
regionValue(6,i)=600;
else
regionValue(6,i)=img(x,y)-img(x+1,y);
end
%7
if(x+1>maxX||y-1<1)
regionValue(7,i)=700;
else
regionValue(7,i)=img(x,y)-img(x+1,y-1);
end
%8
if(y-1<1)
regionValue(8,i)=800;
else
regionValue(8,i)=img(x,y)-img(x,y-1);
end
end
end
functionpoints=kp_harris(im)
%ExtractkeypointsusingHarrisalgorithm(withanimprovement
%version)
%INPUT
%=====
%im:
thegraylevelimage
%
%OUTPUT
%======
%points:
theinterestpointsextracted
%
%REFERENCES
%==========
%C.G.HarrisandM.J.Stephens."Acombinedcornerandedgedetector",
%ProceedingsFourthAlveyVisionConference,Manchester.
%pp147-151,1988.
%
%AlisonNoble,"DescriptionsofImageSurfaces",PhDthesis,Department
%ofEngineeringScience,OxfordUniversity1989,p45.
%
%C.Schmid,R.MohrandandC.Bauckhage,"d",
%Int.JournalofComputerVision,37
(2),151-172,2000.
%
%EXAMPLE
%=======
%points=kp_harris(im)
%onlyluminancevalue
%size(im)
im=double(im(:
:
1));
sigma=1.5;
%derivativemasks
s_D=0.7*sigma;
x=-round(3*s_D):
round(3*s_D);
dx=x.*exp(-x.*x/(2*s_D*s_D))./(s_D*s_D*s_D*sqrt(2*pi));
dy=dx';
%imagederivatives
Ix=conv2(im,dx,'same');
Iy=conv2(im,dy,'same');
%sumoftheAuto-correlationmatrix
s_I=sigma;
g=fspecial('gaussian',max(1,fix(6*s_I+1)),s_I);
Ix2=conv2(Ix.^2,g,'same');%Smoothedsquaredimagederivatives
Iy2=conv2(Iy.^2,g,'same');
Ixy=conv2(Ix.*Iy,g,'same');
%interestpointresponse
cim=(Ix2.*Iy2-Ixy.^2)./(Ix2+Iy2+eps);
%findlocalmaximaon3x3neighborgood
[r,c,max_local]=findLocalMaximum(cim,3*s_I);
%setthreshold1%ofthemaximumvalue
%t=0.01*max(max_local(:
));
t=0.6*max(max_local(:
));%door.jpg
%t=0.48*max(max_local(:
));%sunflower.jpg
%findlocalmaximagreaterthanthreshold
[r,c]=find(max_local>=t);
%buildinterestpoints
points=[r,c];
end
function[row,col,max_local]=findLocalMaximum(val,radius)
%Determinethelocalmaximumofagivenvalue
%
%
%INPUT
%=====
%val:
theNxMmatrixcontainingvalues
%radius:
theradiusoftheneighborhood
%
%OUTPUT
%======
%row:
therowpositionofthelocalmaxima
%col:
thecolumnpositionofthelocalmaxima
%max_local:
theNxMmatrixcontainingvaluesofvalonuniquelocalmaximum
%
%EXAMPLE
%=======
%[l,c,m]=findLocalMaximum(img,radius);
%FINDUNIQUELOCALMAXIMAUSINGFILTERING(FAST)
mask=fspecial('disk',radius)>0;
nb=sum(mask(:
));
highest=ordfilt2(val,nb,mask);
second_highest=ordfilt2(val,nb-1,mask);
index=highest==val&highest~=second_highest;
max_local=zeros(size(val));
max_local(index)=val(index);
[row,col]=find(index==1);
end
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图像 中角点 特征 提取 匹配 算法