-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_script1.m
executable file
·61 lines (51 loc) · 1.92 KB
/
demo_script1.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
58
59
60
61
close all;
clear all;
% read images
image1 = imread('boat1.pgm');
image2 = imread('boat2.pgm');
% obtain matching points
[points1, points2] = keypoint_matching(image1, image2);
% display image side by side
figure(1), imshow([image1,image2]), title('Before Ransac');
width_image1 = size(image1,2);
% draw random 50 lines of matching points
perm = randperm(size(points1,2));
for j = 1:50
i = perm(j);
x = [points1(1,i) width_image1 + points2(1,i)];
y = [points1(2,i) points2(2,i)];
hold on;
line(x,y,'Color','y','linewidth',2);
end
%transforming image 1 to image 2
best_transform = RANSAC(points1, points2, 100, 3);
h = best_transform;
H = [h(1) h(2) h(5); h(3) h(4) h(6); 0 0 1]';
tform = maketform('affine', H);
J = imtransform(image1, tform);
new_image1 = transform_image(image1,best_transform);
new_image1 = uint8(new_image1);
figure(2), imshow([image1,image2]), title('After Ransac');
new_coordinates = transform_coordinates(points1(1,:),points1(2,:),best_transform);
% show lines after RANSAC
for j = 1:50
i = perm(j);
x = [points1(1,i) width_image1 + new_coordinates(1,i)];
y = [points1(2,i) new_coordinates(2,i)];
hold on;
line(x,y,'Color','y','linewidth',2);
end
figure(3)
subplot(2,2,1), imshow(new_image1), title('Transformed image1 using our implementation');
subplot(2,2,2), imshow(J), title('Tranformed image1 using imtransform');
%------- Image 2 to Image 1-------------------------
% transforming image 2 to image 1
best_transform = RANSAC(points2, points1, 100, 3);
new_image2 = transform_image(image2,best_transform);
new_image2 = uint8(new_image2);
h = best_transform;
H = [h(1) h(2) h(5); h(3) h(4) h(6); 0 0 1]';
tform = maketform('affine', H);
I = imtransform(image2, tform);
subplot(2,2,3), imshow(new_image2), title('Tranformed image2 using our implementation');
subplot(2,2,4), imshow(I), title('Tranformed image2 using imtransform');