Portofolio 7
Portofolio ini membahas masalah rekonstruksi image 3 Dimensi dengan menggunakan 2 image sebuah obyek dari sisi yang berbeda.
Pada portofolio ini menggunakan fungsi tambahan digipts.m untuk mendapatkan titik-titik koordinat dan port7.m untuk menggenerate image 3 dimensi.
Berikut listing fungsi stereo.m:
function [XYZ, uv1, uv2] = stereo(im1, im2, C1, C2)
fprintf(1, ‘Digitise some points in figure 1\n’);
figure(1)
imshow(im1);
[u1,v1] = digipts;
uv1 = [u1,v1]‘;
fprintf(1, ‘Digitise some points in figure 2\n’);
figure(2)
imshow(im2);
[u2,v2] = digipts;
uv2 = [u2,v2]‘;
% check if same number of points are selected
if length(u1) ~= length(u2)
fprintf(1, ‘Same number of points not selected\n’);
end
for i = 1:length(u1)
a = [C1(1:2,1:3) - [u1(i)*C1(3,1:3); v1(i)*C1(3,1:3)];
C2(1:2,1:3) - [u2(i)*C2(3,1:3); v2(i)*C2(3,1:3)]];
c = [u1(i) - C1(1,4);
v1(i) - C1(2,4);
u2(i) - C2(1,4);
v2(i) - C2(2,4)];
b(:, i) = a \ c;
end
XYZ = b’;
Dari fungsi diatas akan menghasilkan titik-titik koordinat 3 dimensi dari ketiga bangun ruang (kubus, balok, dan limas), seperti di bawah ini:
XYZ =
-286.0375 159.3352 143.1264
-174.8785 164.7003 142.1362
-174.4340 19.5256 140.9230
-289.9271 12.3933 145.4859
-286.3933 158.5875 9.6770
-286.8865 12.2145 7.4663
-172.9403 16.8265 3.0686
-87.3991 -70.7070 2.8885
-67.5898 -144.6966 123.9172
20.2380 -180.4104 -4.5407
-137.1213 -207.2377 -1.1814
137.2824 -90.0132 60.1437
204.4657 -94.8841 62.5017
205.9589 -158.4145 59.2061
136.2567 -155.7789 59.6247
134.9462 -94.6917 -5.6162
136.2243 -158.0526 -8.6896
206.4949 -162.9891 -10.8196
138.9923 -339.2021 212.7602
Length matrix of face sides
slengths =
147.0123 111.2927 145.1804 115.8031
115.8031 137.8889 114.1243 138.0532
138.0532 146.3906 133.4519 147.0123
114.8436 133.4519 111.2927 138.0532
138.0532 145.1804 137.8889 147.7028
147.7028 114.1243 146.3906 114.8436
nface =
4 1 2 3 4
4 3 7 6 4
4 6 5 1 4
8 5 1 2 8
8 2 3 7 8
8 7 6 5 8
Length matrix of face sides
Panjang rusuk untuk balok:
slengths =
143.2299 159.6579 153.8694
143.2299 156.1911 145.3598
153.8694 159.6651 145.3598
159.6579 159.6651 156.1911
nface =
1 2 3 1
1 2 4 1
1 3 4 1
2 3 4 2
Panjang rusuk untuk kubus:
slengths =
65.7757 67.4009 63.6334 69.7533
69.7533 70.1771 70.4759 68.3521
68.3521 63.4482 65.9676 65.7757
69.5312 65.9676 67.4009 68.3521
68.3521 63.6334 70.1771 66.0537
66.0537 70.4759 63.4482 69.5312
nface =
4 1 2 3 4
4 3 7 6 4
4 6 5 1 4
8 5 1 2 8
8 2 3 7 8
8 7 6 5 8
Untuk mendapatkan Dua view yang berbeda dari rekonstruksi 3D kubus, balok dan limas dan perkiraan titik koordinat 3D yang tersembunyi, dijalankan fungsi di bawah ini:
function port7()
im1 = imread(’stereo1.jpg’ );
im2 = imread(’stereo2.jpg’ );
C1 = [0.6596 -0.7391 -0.0615 363.4235;
-0.1851 -0.1387 -0.9437 342.7417;
0.0005 0.0003 -0.0003 1.0000];
C2 = [0.9234 -0.2221 -0.0257 347.7796;
-0.0741 -0.2278 -0.9168 339.8960;
0.0002 0.0004 -0.0002 1.0000];
pt3D = stereo(im1, im2, C1, C2)
figure(3)
cube(pt3D(1:7,:));
tetrahedron(pt3D(8:11,:));
cube(pt3D(12:18,:));
% label coordinate axes
text(100,0,0,’x');
text(0,100,0,’y');
text(0,0,100,’z');
% draw in a set of coordinate axes
axislength = 100*eye(3);
for i=1:3
line([0, axislength(i,1)], [0, axislength(i,2)], [0, axislength(i,3)]);
end
axis equal; box on; rotate3D on; grid on;
end
function cube(cubepts3D)
% determine hidden vertex
cubepts3D(8,:) = - cubepts3D(4,:) + cubepts3D(6,:) + cubepts3D(2,:);
% define faces from standard numbering
cubefaces = [4 1 2 3
4 3 7 6
4 6 5 1
8 5 1 2
8 2 3 7
8 7 6 5];
% draw ‘patcheds’ from vertice and face matrix
patch(’Faces’,cubefaces,’Vertices’,cubepts3D, ‘FaceColor’, ‘none’)
fprintf(1, ‘Length matrix of face sides\n’);
[slengths, nface] = sidelengths(cubepts3D, cubefaces)
end
function tetrahedron(tetrahedronpts3D)
% define faces from standard numbering
tetrahedronfaces = [1 2 3
1 2 4
1 3 4
2 3 4];
% draw ‘patcheds’ from vertice and face matrix
patch(’Faces’,tetrahedronfaces,’Vertices’,tetrahedronpts3D, ‘FaceColor’, ‘none’)
fprintf(1, ‘Length matrix of face sides\n’);
[slengths, nface] = sidelengths(tetrahedronpts3D, tetrahedronfaces)
end
function [slengths, nface] = sidelengths(pt3D, face)
[rows, cols] = size(face);
nface = [face face(:,1)];
for i=1:cols
for j=1:rows
slengths(j,i) = norm(pt3D(nface(j,i),:)-pt3D(nface(j,i+1),:));
end
end
end
setelah itu kita akan mendapatkan rekonstruksi 3 dimensi seperti di bawah ini:

