Minggu, 18 Mei 2008

Portofolio 7

Portofolio 7:


>>portofolio 7





hasil:


pt3D =

-286.0283 159.4041 142.0436
-177.4378 163.8930 143.5515
-177.4575 17.6164 140.7850
-290.2918 12.1955 145.2484
-286.7534 160.7354 8.3899
-287.7561 12.6779 6.4816
-174.6022 14.6008 2.7149
-84.5654 -68.1487 0.4912
-68.3572 -146.0519 123.5506
18.9348 -178.8454 -4.1677
-136.9619 -207.2383 -1.7911
136.3903 -91.5529 62.7009
206.1682 -94.1534 62.1509
208.5392 -158.4030 57.5592
137.3153 -155.6600 59.8104
133.9942 -92.6254 -5.9321
133.3809 -160.9251 -8.6149
204.9606 -163.8064 -10.6342

Length matrix of face sides

slengths =

147.3052 108.6937 146.3028 113.0525
113.0525 138.1325 113.2328 138.7908
138.7908 148.0732 133.6623 147.3052
111.9686 133.6623 108.6937 138.7908
138.7908 146.3028 138.1325 149.7892
149.7892 113.2328 148.0732 111.9686


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

slengths =

146.5443 158.1369 151.6171
146.5443 155.4379 148.6489
151.6171 158.4790 148.6489
158.1369 158.4790 155.4379


nface =

1 2 3 1
1 2 4 1
1 3 4 1
2 3 4 2

Length matrix of face sides

slengths =

64.1789 69.8286 64.4571 71.3123
71.3123 68.5008 71.6662 68.7402
68.7402 68.3551 68.6831 64.1789
68.5777 68.6831 69.8286 68.7402
68.7402 64.4571 68.5008 64.5929
64.5929 71.6662 68.3551 68.5777


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


listing of portofolio7:

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


listing of digipits.m:

% DIGIPTS - digitise points in an image
%
% Function to digitise points in an image. Points are digitised by clicking
% with the left mouse button. Clicking any other button terminates the
% function. Each location digitised is marked with a red '+'.
%
% Usage: [u,v] = digipts
%
% where u and v are nx1 arrays of x and y coordinate values digitised in
% the image.
%
% This function uses the cross-hair cursor provided by GINPUT. This is
% much more useable than IMPIXEL

% Peter Kovesi
% School of Computer Science & Software Engineering
% The University of Western Australia
% pk @ csse uwa edu au
% http://www.csse.uwa.edu.au/~pk
%
% May 2002

function [u,v] = digipts

hold on
u = []; v = [];
but = 1;
while but == 1
[x y but] = ginput(1);
if but == 1
u = [u;x];
v = [v;y];

plot(u,v,'r+');
end
end

hold off


listing of stereo.m:

% STEREO
%
% Usage: pt3D = stereo(im1, im2, C1, C2)
%
% Where: im1 and im2 are the two stereo images
% C1 and C2 are the calibration matrices
% for these two images respectively
%
% The function will prompt you to digitise some points in the first image
% (finishing by clicking the right button). The function then
% prompts you to digitise the equivalent points (which you must digitise
% in exactly the same sequence) in the second image.
% The function then solves the stereo equations
% and returns the 3D coordinates of the points in pt3D.
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';

Tidak ada komentar: