-
Notifications
You must be signed in to change notification settings - Fork 0
/
surffAndRansac.m
57 lines (49 loc) · 2.03 KB
/
surffAndRansac.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
function [xmin,xmax,ymin,ymax] = surffAndRansac(image1,image2)
maxIterations = 1000;
correct = 0;
cont = 0;
while (correct ~= 1) & (cont < maxIterations)
original = image2;
distorted = image1;
ptsOriginal = detectSURFFeatures(original);
ptsDistorted = detectSURFFeatures(distorted);
%ptsOriginal = detectHarrisFeatures(original);
%ptsDistorted = detectHarrisFeatures(distorted);
[featuresOriginal,validPtsOriginal] = extractFeatures(original,ptsOriginal);
[featuresDistorted,validPtsDistorted] = extractFeatures(distorted,ptsDistorted);
index_pairs = matchFeatures(featuresOriginal,featuresDistorted,'MaxRatio',0.8,'MatchThreshold',80);
matchedPtsOriginal = validPtsOriginal(index_pairs(:,1));
matchedPtsDistorted = validPtsDistorted(index_pairs(:,2));
%figure;
%showMatchedFeatures(original,distorted,matchedPtsOriginal,matchedPtsDistorted);
%title('Matched SURF points,including outliers');
[tform,inlierPtsDistorted,inlierPtsOriginal] = estimateGeometricTransform(matchedPtsDistorted,matchedPtsOriginal,'similarity');
%figure;
%showMatchedFeatures(original,distorted,inlierPtsOriginal,inlierPtsDistorted);
%title('Matched inlier points');
[nr,nc]= size(ptsDistorted.Location);
arrayX = zeros([1 nr]);
arrayY = zeros([1 nr]);
for k = 1:nr
x = ptsDistorted.Location(k,1);
y = ptsDistorted.Location(k,2);
[X,Y] = transformPointsForward(tform,x,y);
arrayX(1,k) = X;
arrayY(1,k) = Y;
end
xmin = min(arrayX);
xmax = max(arrayX);
ymin = min(arrayY);
ymax = max(arrayY);
if goodPoint(xmin,ymin,image2) == 1 & goodPoint(xmax,ymax,image2) == 1
correct = 1;
end
end
end
function correct = goodPoint(x,y,image)
correct = 0;
[nr,nc]= size(image(:,:,1));
if x > 0 & x < nc & y > 0 & y < nr
correct = 1;
end
end