forked from LJY-RS/RIFT-multimodal-image-matching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRIFT_demo.m
57 lines (47 loc) · 1.57 KB
/
RIFT_demo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
% This is a simplest implementation of the proposed RIFT algorithm. In this implementation,...
% rotation invariance part and corner point detection are not included.
clc;clear;close all;
warning('off')
addpath sar-optical % type of multi-modal data
str1='pair1.jpg'; % image pair
str2='pair2.jpg';
im1 = im2uint8(imread(str1));
im2 = im2uint8(imread(str2));
if size(im1,3)==1
temp=im1;
im1(:,:,1)=temp;
im1(:,:,2)=temp;
im1(:,:,3)=temp;
end
if size(im2,3)==1
temp=im2;
im2(:,:,1)=temp;
im2(:,:,2)=temp;
im2(:,:,3)=temp;
end
disp('RIFT feature detection and description')
% RIFT feature detection and description
[des_m1,des_m2] = RIFT_no_rotation_invariance(im1,im2,4,6,96);
disp('nearest matching')
% nearest matching
[indexPairs,matchmetric] = matchFeatures(des_m1.des,des_m2.des,'MaxRatio',1,'MatchThreshold', 100);
matchedPoints1 = des_m1.kps(indexPairs(:, 1), :);
matchedPoints2 = des_m2.kps(indexPairs(:, 2), :);
[matchedPoints2,IA]=unique(matchedPoints2,'rows');
matchedPoints1=matchedPoints1(IA,:);
disp('outlier removal')
%outlier removal
H=FSC(matchedPoints1,matchedPoints2,'affine',2);
Y_=H*[matchedPoints1';ones(1,size(matchedPoints1,1))];
Y_(1,:)=Y_(1,:)./Y_(3,:);
Y_(2,:)=Y_(2,:)./Y_(3,:);
E=sqrt(sum((Y_(1:2,:)-matchedPoints2').^2));
inliersIndex=E<3;
cleanedPoints1 = matchedPoints1(inliersIndex, :);
cleanedPoints2 = matchedPoints2(inliersIndex, :);
disp('Show matches')
% Show results
figure; showMatchedFeatures(im1, im2, cleanedPoints1, cleanedPoints2, 'montage');
disp('registration result')
% registration
image_fusion(im2,im1,double(H));