PORTOFOLIO 7

Kali ini kita akan membahas tentang rekonstruksi objek 2 dimensi menjadi 3 dimensi.

Pada portofolio ini kita memerlukan digipts.m dan portofolio7.m untuk membangkitkan image 3 dimensi.

dibawah ini adalh listing 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 dihasilkan titik-titik koordinat 3 dimensi dari ketiga bangun ruang (kubus, balok, dan limas), seperti di bawah ini:

XYZ =

-286.2951 157.9628 143.0423

-175.3818 163.1173 142.7176

-175.5998 16.6768 141.1072

-289.0643 13.0795 143.6164

-285.5844 161.7196 8.2758

-287.0630 12.1030 5.9668

-174.9637 14.4183 4.0810

-86.9674 -69.5001 0.6049

-66.2381 -144.2762 121.3230

20.2380 -180.4104 -4.5407

-136.9644 -207.1403 -0.7542

136.7599 -90.1582 62.6987

208.8604 -92.0420 60.2097

206.8196 -158.9134 58.7466

137.3153 -155.6600 59.8104

133.7304 -94.9047 -4.4448

137.0247 -158.4058 -10.0663

205.6730 -162.3611 -10.7847

 

Panjang rusuk untuk balok:

slengths =

144.9110 111.0335 146.4495 113.5492

113.5492 137.0463 112.1391 137.6676

137.6676 149.6418 134.8208 144.9110

112.2506 134.8208 111.0335 137.6676

137.6676 146.4495 137.0463 147.7343

147.7343 112.1391 149.6418 112.2506

dengan sisi-sisinya:

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

 

Panjang rusuk untuk limas:

slengths =

143.5062 156.9251 154.3392

143.5062 154.4569 146.4458

154.3392 159.5037 146.4458

156.9251 159.5037 154.4569

dengan sisi-sisinya:

nface =

1 2 3 1

1 2 4 1

1 3 4 1

2 3 4 2

 

Panjang rusuk untuk kubus:

slengths =

65.5678 72.1681 66.9186 69.5886

69.5886 69.6261 68.7659 69.9313

69.9313 63.8345 67.3792 65.5678

75.0216 67.3792 72.1681 69.9313

69.9313 66.9186 69.6261 67.6446

67.6446 68.7659 63.8345 75.0216

dengan sisi-sisinya:

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 portofolio7()

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

dari fungsi diatas kita akan menentukan kokordinat titik-titik dengan urutan seperti berikut :

st1.jpg

st2.jpg

kita akan mendapatkan rekonstruksi 3 D :

1.jpg

2.jpg

Leave a Reply