├── README.md
├── data
├── gang1.bmp
└── gang2.bmp
├── hnormalise.m
├── homography2d.m
├── html
├── main_msac.html
├── main_msac.png
├── main_msac_01.png
└── main_msac_02.png
├── iscolinear.m
├── main.m
├── main_msac.m
├── main_ransac.m
├── match.m
├── match_ransac.m
├── normalise2dpts.m
├── ransac.m
├── ransacfitfundmatrix.m
└── ransacfithomography.m
/README.md:
--------------------------------------------------------------------------------
1 | # Multi-sensor-images-matching(异源图像匹配/配准)
2 | - Original Paper: A Multi-sensor Image Matching Method Based on KAZE-HOG Features (https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8981033), ICIVC 2019.
3 | - Code: https://github.com/devenin/Multi-sensor-images-matching
4 | ### Requirements
5 | Please, use Matlab 2019a or latest vision.
6 |
--------------------------------------------------------------------------------
/data/gang1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devenin/Multi-sensor-images-matching/3f5bb69dd34bf3fc04e9e69257d5b592bc7cc3af/data/gang1.bmp
--------------------------------------------------------------------------------
/data/gang2.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devenin/Multi-sensor-images-matching/3f5bb69dd34bf3fc04e9e69257d5b592bc7cc3af/data/gang2.bmp
--------------------------------------------------------------------------------
/hnormalise.m:
--------------------------------------------------------------------------------
1 | % HNORMALISE - Normalises array of homogeneous coordinates to a scale of 1
2 | %
3 | % Usage: nx = hnormalise(x)
4 | %
5 | % Argument:
6 | % x - an Nxnpts array of homogeneous coordinates.
7 | %
8 | % Returns:
9 | % nx - an Nxnpts array of homogeneous coordinates rescaled so
10 | % that the scale values nx(N,:) are all 1.
11 | %
12 | % Note that any homogeneous coordinates at infinity (having a scale value of
13 | % 0) are left unchanged.
14 | % Peter Kovesi
15 | % School of Computer Science & Software Engineering
16 | % The University of Western Australia
17 | % pk at csse uwa edu au
18 | % http://www.csse.uwa.edu.au/~pk
19 | %
20 | % February 2004
21 | function nx = hnormalise(x)
22 |
23 | [rows,npts] = size(x);
24 | nx = x;
25 | % Find the indices of the points that are not at infinity
26 | finiteind = find(abs(x(rows,:)) > eps);
27 | if length(finiteind) ~= npts
28 | warning('Some points are at infinity');
29 | end
30 | % Normalise points not at infinity
31 | for r = 1:rows-1
32 | nx(r,finiteind) = x(r,finiteind)./x(rows,finiteind);
33 | end
34 | nx(rows,finiteind) = 1;
35 |
--------------------------------------------------------------------------------
/homography2d.m:
--------------------------------------------------------------------------------
1 | % HOMOGRAPHY2D - computes 2D homography
2 | %
3 | % Usage: H = homography2d(x1, x2)
4 | % H = homography2d(x)
5 | %
6 | % Arguments:
7 | % x1 - 3xN set of homogeneous points
8 | % x2 - 3xN set of homogeneous points such that x1<->x2
9 | %
10 | % x - If a single argument is supplied it is assumed that it
11 | % is in the form x = [x1; x2]
12 | % Returns:
13 | % H - the 3x3 homography such that x2 = H*x1
14 | %
15 | % This code follows the normalised direct linear transformation
16 | % algorithm given by Hartley and Zisserman "Multiple View Geometry in
17 | % Computer Vision" p92.
18 | %
19 |
20 | % Peter Kovesi
21 | % School of Computer Science & Software Engineering
22 | % The University of Western Australia
23 | % pk at csse uwa edu au
24 | % http://www.csse.uwa.edu.au/~pk
25 | %
26 | % May 2003 - Original version.
27 | % Feb 2004 - Single argument allowed for to enable use with RANSAC.
28 | % Feb 2005 - SVD changed to 'Economy' decomposition (thanks to Paul O'Leary)
29 |
30 | function H = homography2d(varargin)
31 |
32 | [x1, x2] = checkargs(varargin(:));
33 |
34 | % Attempt to normalise each set of points so that the origin
35 | % is at centroid and mean distance from origin is sqrt(2).
36 | [x1, T1] = normalise2dpts(x1);
37 | [x2, T2] = normalise2dpts(x2);
38 |
39 | % Note that it may have not been possible to normalise
40 | % the points if one was at infinity so the following does not
41 | % assume that scale parameter w = 1.
42 |
43 | Npts = length(x1);
44 | A = zeros(3*Npts,9);
45 |
46 | O = [0 0 0];
47 | for n = 1:Npts
48 | X = x1(:,n)';
49 | x = x2(1,n); y = x2(2,n); w = x2(3,n);
50 | A(3*n-2,:) = [ O -w*X y*X];
51 | A(3*n-1,:) = [ w*X O -x*X];
52 | A(3*n ,:) = [-y*X x*X O ];
53 | end
54 |
55 | [U,D,V] = svd(A,0); % 'Economy' decomposition for speed
56 |
57 | % Extract homography
58 | H = reshape(V(:,9),3,3)';
59 |
60 | % Denormalise
61 | H = T2\H*T1;
62 |
63 |
64 | %--------------------------------------------------------------------------
65 | % Function to check argument values and set defaults
66 |
67 | function [x1, x2] = checkargs(arg);
68 |
69 | if length(arg) == 2
70 | x1 = arg{1};
71 | x2 = arg{2};
72 | if ~all(size(x1)==size(x2))
73 | error('x1 and x2 must have the same size');
74 | elseif size(x1,1) ~= 3
75 | error('x1 and x2 must be 3xN');
76 | end
77 |
78 | elseif length(arg) == 1
79 | if size(arg{1},1) ~= 6
80 | error('Single argument x must be 6xN');
81 | else
82 | x1 = arg{1}(1:3,:);
83 | x2 = arg{1}(4:6,:);
84 | end
85 | else
86 | error('Wrong number of arguments supplied');
87 | end
--------------------------------------------------------------------------------
/html/main_msac.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | clc;
70 | clear all;
71 | I1= imread('gang1.bmp');
72 | I1=rgb2gray(I1);
73 | I2= imread('gang2.bmp');
74 | I2=rgb2gray(I2);
75 |
76 |
77 |
78 |
79 |
80 | points1 = detectKAZEFeatures(I1);
81 | points2 = detectKAZEFeatures(I2);
82 |
83 |
84 |
85 |
86 |
87 |
88 | [f1, vpts1] = extractHOGFeatures(I1, points1);
89 |
90 | [f2, vpts2] = extractHOGFeatures(I2, points2);
91 |
92 |
93 | indexPairs = matchFeatures(f1, f2,'Method','NearestNeighborSymmetric','MatchThreshold',100) ;
94 |
95 |
96 | matched_pts1 = vpts1(indexPairs(:, 1));
97 | matched_pts2 = vpts2(indexPairs(:, 2));
98 |
99 | resultpairs1 = matched_pts1.Location;
100 | resultpairs2 = matched_pts2.Location;
101 |
102 |
103 | figure('name','匹配后的图像');
104 | showMatchedFeatures(I1,I2,matched_pts1,matched_pts2,'montage');
105 | legend('matched points 1','matched points 2');
106 |
107 |
108 | [tform, inlierBoxPoints, inlierScenePoints] = estimateGeometricTransform(matched_pts1, matched_pts2, 'projective');
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | figure;
117 | showMatchedFeatures(I1, I2, inlierBoxPoints, inlierScenePoints, 'montage','Parent',axes);
118 | title('MSAC去除误匹配点');
119 |
警告: Maximum number of trials reached. Consider increasing the maximum
120 | distance or decreasing the desired confidence.
121 |
--------------------------------------------------------------------------------
/html/main_msac.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devenin/Multi-sensor-images-matching/3f5bb69dd34bf3fc04e9e69257d5b592bc7cc3af/html/main_msac.png
--------------------------------------------------------------------------------
/html/main_msac_01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devenin/Multi-sensor-images-matching/3f5bb69dd34bf3fc04e9e69257d5b592bc7cc3af/html/main_msac_01.png
--------------------------------------------------------------------------------
/html/main_msac_02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devenin/Multi-sensor-images-matching/3f5bb69dd34bf3fc04e9e69257d5b592bc7cc3af/html/main_msac_02.png
--------------------------------------------------------------------------------
/iscolinear.m:
--------------------------------------------------------------------------------
1 | function r = iscolinear(p1,p2,p3,flag)
2 |
3 | if nargin ==3
4 | flag='inhomog';
5 | end
6 | if ~all(size(p1)==size(p2))|~all(size(p1)==size(p3))|...
7 | ~(length(p1)==2|length(p1)==3)
8 | error('points must have the same dimension of 2 or 3');
9 | end
10 | if length(p1)==2
11 | p1(3)=1;p2(3)=1;p3(3)=1;
12 | end
13 | if flag(1)=='h'
14 | r=abs(dot(cross(p1,p2),p3))