【SURF+GTM】基于SURF特征提取,GTM去除错误配准点的图像匹配算法的MATLAB仿真
生活随笔
收集整理的這篇文章主要介紹了
【SURF+GTM】基于SURF特征提取,GTM去除错误配准点的图像匹配算法的MATLAB仿真
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.軟件版本
matlab2021a
2.核心代碼
clear,clcI1 = rgb2gray(imread('fetch.JPG'));I2 = rgb2gray(imread('fetch1.JPG')); % I1=imresize(I1,[290,290]); % I2=imresize(I2,[290,290]);% Get the Key PointsOptions.upright=true;Options.tresh=0.0001;Ipts1=OpenSurf(I1,Options);Ipts2=OpenSurf(I2,Options); % Put the landmark descriptors in a matrixDA = reshape([Ipts1.descriptor],64,[]); DB = reshape([Ipts2.descriptor],64,[]); % Find the best matchesfor i=1:length(Ipts1)for j=1:length(Ipts2)DC(i,j)=norm(DA(:,i)-DB(:,j));end endDM=[]; for i=1:length(Ipts1)[B,IX] = sort(DC(i,:)); % [B,IX] = sort(DC1(i,:)); % if B(1)/B(2)<0.8if min(DC(:,IX(1)))==DC(i,IX(1))DM=[DM;[i,IX(1)]];end end% Show both imagesI = zeros([size(I1,1) size(I1,2)*2 size(I1,3)]);I(:,1:size(I1,2),:)=I1; I(:,size(I1,2)+1:size(I1,2)+size(I2,2),:)=I2;figure, imshow(I/255); hold on;X=zeros(length(DM),2);Y=zeros(length(DM),2); % Show the best matchesfor i=1:length(DM), % c=rand(1,3); % plot([Ipts1(cor1(i)).x Ipts2(cor2(i)).x+size(I1,2)],[Ipts1(cor1(i)).y Ipts2(cor2(i)).y],'-','Color',c) % plot([Ipts1(cor1(i)).x Ipts2(cor2(i)).x+size(I1,2)],[Ipts1(cor1(i)).y Ipts2(cor2(i)).y],'o','Color',c) X(i,:)=[Ipts1(DM(i,1)).x ,Ipts1(DM(i,1)).y]; Y(i,:)=[Ipts2(DM(i,2)).x ,Ipts2(DM(i,2)).y];plot(Ipts1(DM(i,1)).x ,Ipts1(DM(i,1)).y,'go')plot(Ipts2(DM(i,2)).x+size(I1,2) ,Ipts2(DM(i,2)).y,'bo')plot([Ipts1(DM(i,1)).x Ipts2(DM(i,2)).x+size(I1,2)],[Ipts1(DM(i,1)).y Ipts2(DM(i,2)).y],'r-')endK=3; Iteration=30; [AP1,AP2,Q1,Q2,Q11,Q22]=Graph_TMatch(X,Y,K);figure, imshow(I/255); hold on; W1=size(I1,2); S1 = sparse(AP1); [C11,C12,C13] = find(S1);for i=1:length(C11)hold on;plot([Q1(C11(i),1),Q1(C12(i),1)],[Q1(C11(i),2),Q1(C12(i),2)],'-r');end S2 = sparse(AP2); [C21,C22,C23] = find(S2);for i=1:length(C21)hold on;plot([Q2(C21(i),1)+W1,Q2(C22(i),1)+W1],[Q2(C21(i),2),Q2(C22(i),2)],'-r');end figure, imshow(I/255); hold on; plot(Q11(:,1),Q11(:,2),'b+'); plot(Q22(:,1)+W1,Q22(:,2),'g+');for i=1:length(Q11)hold on;plot([Q11(i,1),Q22(i,1)+W1],[Q11(i,2),Q22(i,2)],'-r');end hold off;Pos1=[Q11(:,2),Q11(:,1)];Pos2=[Q22(:,2),Q22(:,1)];% Calculate affine matrix Pos1(:,3)=1; Pos2(:,3)=1; M=Pos1'/Pos2';% Add subfunctions to Matlab Search path functionname='OpenSurf.m'; functiondir=which(functionname); functiondir=functiondir(1:end-length(functionname)); addpath([functiondir '/WarpFunctions'])% Warp the image I1_warped=affine_warp(I1,M,'bicubic');% Show the result figure, subplot(1,4,1), imshow(I1);title('Figure 1'); subplot(1,4,2), imshow(I2);title('Figure 2'); subplot(1,4,3), imshow(I1_warped,[]);title('Warped Figure 1'); subplot(1,4,4), imshow(I1_warped+double(I2),[]);title('Warped Figure 1');Pos1=[Q11(:,2)+0.5*size(I1,2),Q11(:,1)+0.5*size(I1,1)];Pos2=[Q22(:,2)+0.5*size(I2,2),Q22(:,1)+0.5*size(I2,1)];% Calculate affine matrix Pos1(:,3)=1; Pos2(:,3)=1; M=Pos1'/Pos2';I11=zeros(2*size(I1,1),2*size(I1,1)); I22=zeros(2*size(I2,1),2*size(I2,1)); I11(0.5*size(I1,1)+1:1.5*size(I1,1),0.5*size(I1,2)+1:1.5*size(I1,2))=I1; I22(0.5*size(I2,1)+1:1.5*size(I2,1),0.5*size(I2,2)+1:1.5*size(I2,2))=I2; % M(1:2,3)=M(1:2,3)+0.5*size(I1,1); % Warp the image I1_warped=affine_warp(I11,M,'bicubic');% Show the result figure, subplot(1,4,1), imshow(I11,[]);title('Figure 1'); subplot(1,4,2), imshow(I22,[]);title('Figure 2'); subplot(1,4,3), imshow(I1_warped,[]);title('Warped Figure 1'); subplot(1,4,4), imshow(I1_warped+I22,[]);title('Warped Figure 2');3.操作步驟與仿真結(jié)論
?
?
4.參考文獻
[1]宋寶官. 基于改進SURF的醫(yī)學圖像配準算法研究[D]. 東北大學, 2014.
D209
5.完整源碼獲得方式
方式1:微信或者QQ聯(lián)系博主
方式2:訂閱MATLAB/FPGA教程,免費獲得教程案例以及任意2份完整源碼
總結(jié)
以上是生活随笔為你收集整理的【SURF+GTM】基于SURF特征提取,GTM去除错误配准点的图像匹配算法的MATLAB仿真的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【步态识别】基于深度学习的步态识别系统的
- 下一篇: 【信号发生器】基于quartusii的信