-
Notifications
You must be signed in to change notification settings - Fork 1
/
stitching_multiple_images.m
54 lines (54 loc) · 2.59 KB
/
stitching_multiple_images.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
function [output] = stitching_multiple_images(input1, input2, input3)
input_rgb_1 = imread(input1);
input_rgb_2 = imread(input2);
input_rgb_3 = imread(input3);
width1 = size(input_rgb_1, 2);
width2 = size(input_rgb_2, 2);
width3 = size(input_rgb_3, 2);
[inlier_num_12, inliers_12] = calculate_inliers(input1, input2);
[inlier_num_23, inliers_23] = calculate_inliers(input2, input3);
[inlier_num_31, inliers_31] = calculate_inliers(input1, input3);
%Determine the order
if(inlier_num_12 > inlier_num_23 && inlier_num_31 > inlier_num_23)%input1 is mid
relative2 = calculate_rel(inliers_12(:,2), width2);% 0:input2 is left of input1, 1: input2 is right of input1
if(relative2 == 0)
disp('order: 2-1-3');
output = stitching_pair_of_images(input2, input1, 2);
imwrite(output, 'output.jpg', 'jpg');
output = stitching_pair_of_images(input3,'output.jpg', 2);
else
disp('order: 3-1-2');
output = stitching_pair_of_images(input3, input1, 2);
imwrite(output, 'output.jpg', 'jpg');
output = stitching_pair_of_images(input2,'output.jpg', 2);
end
elseif(inlier_num_23 > inlier_num_12 && inlier_num_31 > inlier_num_12)%input3 is mid
relative1 = calculate_rel(inliers_31(:,2), width1);% 0:input1 is left of input3, 1: input1 is right of input3
if(relative1 == 0)
disp('order: 1-3-2');
output = stitching_pair_of_images(input1, input3, 2);
imwrite(output, 'output.jpg', 'jpg');
output = stitching_pair_of_images(input2,'output.jpg', 2);
else
disp('order: 2-3-1');
output = stitching_pair_of_images(input2, input3, 2);
imwrite(output, 'output.jpg', 'jpg');
output = stitching_pair_of_images(input1,'output.jpg', 2);
end
elseif(inlier_num_23 > inlier_num_31 && inlier_num_12 > inlier_num_31)%input2 is mid
relative3 = calculate_rel(inliers_23(:,2), width3);% 0:input3 is left of input2, 1: input3 is right of input2
if(relative3 == 0)
disp('order: 3-2-1');
output = stitching_pair_of_images(input3, input2, 2);
imwrite(output, 'output.jpg', 'jpg');
output = stitching_pair_of_images(input1,'output.jpg', 2);
else
disp('order: 1-2-3');
output = stitching_pair_of_images(input1, input2, 2);
imwrite(output, 'output.jpg', 'jpg');
output = stitching_pair_of_images(input3,'output.jpg', 2);
end
end
figure();
imshow(output);
end