Stereo Vision Algorithms: 1D and 2D Implementations and Perspective Projection - Prof. Dav, Assignments of Computer Science

The code and explanations for two stereo vision algorithms: 1d and 2d. The 1d algorithm uses the extend_match function to find the disparity between corresponding pixels in two arrays, while the 2d algorithm applies the same concept to 2d images. Additionally, the document includes the perspective projection equations to determine the 3d coordinates of points in the world from their 2d coordinates in the images.

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-spj
koofers-user-spj 🇺🇸

8 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1.
a)
40.04 0.03 0.02 0.01 0.02
30.03 0.02 0.01 0.02 0.03
20.02 0.01 0.02 0.01 0.02
10.01 0 0.01 0.02 0.03
00 0.01 0.02 0.03 0.04
01234
41 or 2 2 1 1 or 3
32 1 2 or 3 2 or 3
21 or 2 2 or 3 1 1 or 3
11 3 3 1 or 3
1 2 3 4
[0] -> [X 0] -> [-1 X 0] -> [0 -1 X 0]
-> [-1 -1 X 0]
-> [0] -> [1 0] -> [X 1 0] -> [0 X 1 0]
[X]-> [-1 X] -> [-1 -1 X] -> [0 -1 -1 X]
-> [-1 -1 -1 X]
b)
function [c, i] = extend_match (x, y, c1, c2, c3, oc)
[c, i] = min([c1 + oc, c2 + oc, sqrt((x-y)^2) + c3]) ;
Results)
extend_match(1,1,3.7,3.9,3.5,0.01)
ans = 3.5000
extend_match(1,0,3.7,3.9,3.5,0.01)
ans = 3.7100
c)
function d = stereo_1d(v1, v2, oc)
d1 = length(v1) ;
d2 = length(v2) ;
d = [] ;
CM = zeros(d1+1, d2+1) ; % For containing the matching cost
MM = zeros(d1, d2) ; % For reconstructing the optimum path
pf3
pf4
pf5

Partial preview of the text

Download Stereo Vision Algorithms: 1D and 2D Implementations and Perspective Projection - Prof. Dav and more Assignments Computer Science in PDF only on Docsity!

a)

4 1 or 2 2 1 1 or 3 3 2 1 2 or 3 2 or 3 2 1 or 2 2 or 3 1 1 or 3 1 1 3 3 1 or 3 1 2 3 4 [0] -> [X 0 ] -> [-1 X 0] -> [0 -1 X 0] -> [-1 -1 X 0] -> [0] -> [1 0] -> [X 1 0] -> [0 X 1 0] [X]-> [-1 X] -> [-1 -1 X] -> [0 -1 -1 X] -> [-1 -1 -1 X]

b)

function [c, i] = extend_match (x, y, c1, c2, c3, oc) [c, i] = min([c1 + oc, c2 + oc, sqrt((x-y)^2) + c3]) ; Results) extend_match(1,1,3.7,3.9,3.5,0.01) ans = 3. extend_match(1,0,3.7,3.9,3.5,0.01) ans = 3.

c)

function d = stereo_1d(v1, v2, oc) d1 = length(v1) ; d2 = length(v2) ; d = [] ; CM = zeros(d1+1, d2+1) ; % For containing the matching cost MM = zeros(d1, d2) ; % For reconstructing the optimum path

for i = 0 : d for j = 0 : d if i == 0 || j == 0 CM(i+1,j+1) = oc * max([i j]) ; else [CM(i+1,j+1) MM(i, j)] = ... extend_match(v1(i), v2(j), CM(i, j+1), CM(i+1, j), CM(i, j), oc) ; end end end i = d1 ; j = d2 ; disparity = 0 ; while ( i ~= 0 && j ~= 0 ) switch MM(i,j) case 1 , disparity = disparity - 1 ; d = [' X ' d] ; i = i - 1 ; case 2 , disparity = disparity + 1 ; j = j - 1 ; case 3 , if disparity < 0 d = [' -' char('0' + abs(disparity)) ' ' d] ; else d = [' ' char('0' + disparity) ' ' d] ; end i = i -1 ; j = j -1 ; otherwise, sprintf('\nError occured during computation.\n') ; end end for j = 1 : i d = [ d 'X'] ; end Results) v1 = [1 0 1 1 0 1 1 0 0 1 1 0 1 1 1] ; v2 = [1 0 1 0 1 0 1 1 0 0 1 1 1 1 1] ; stereo_1d(v1, v2, 0.01) ans = 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 X 0 0 0

else [CM(i+1,j+1) MM(i, j)] = ... extend_match(v1(i), v2(j), CM(i, j+1), CM(i+1, j), CM(i, j), oc) ; end end end i = d1 ; j = d2 ; disparity = 0 ; sprintf('Done part 1') ; while ( i ~= 0 && j ~= 0 ) switch MM(i,j) case 1 , disparity = disparity - 1 ; d = [DL+10 d] ; i = i - 1 ; case 2 , disparity = disparity + 1 ; j = j - 1 ; case 3 , if disparity > DL d = [DL+10 d] ; elseif disparity < -DL d = [-DL-10 d] ; else d = [disparity d] ; end i = i -1 ; j = j -1 ; otherwise, sprintf('\nError occured during computation.\n') ; end end for j = 1 : i d = [DL+10 d] ; end function D = stereo_2DF(V1, V2, oc) if size(V1) ~= size(V2) error('DIM NEQ', 'The dimension of the images are not compatible', size(V1), size(V2)) ; end D = [];

[n_rows n_cols] = size(V1) ; for i = 1 : n_rows DM = stereo_1DF(V1(i,:) , V2(i,:), oc, 15) ; D = [D ; DM ] ; end D = D - min(min(D)) ; D = D / max(max(D)) * 255 ; D = uint8(D) ; Results)

Distance from P to line l : (v-1) / sqrt(2) Distance from O to Q : (v+1) / sqrt(2) Distance from O to R : 1 / sqrt(2) By the rule of similar triangle, Distance from R to S = u = ((v-1) / sqrt(2) ) / (v+1) = (v-1) / (v + 1) * 1/sqrt(2) [Another solution] First, think about the coordinate system of the case that the image plane along the line z=1 (the second image). We can have this coordinate system as a reference coordinate system. Then any point (x,z) in that plane would be mapped to v = x/z. If we observe that point (x,z) at the coordinate system of second image, it looks like the point is rotated around the y-axis – origin is the same- and the degree of the rotation is cosθ = 1/sqrt(2) , sinθ = 1/sqrt(2) , θ = π/4. (Think about the rotation matrix you’ve learned from the class) Therefore if we transform the (x,z) to the second image coordinate system, we will have x’ = (x-z) / sqrt(2) and z’ = (x+z) / sqrt(2). Then the projection of that point on x + z = 1 is u = x ‘/z ‘ * ( 1/sqrt(2) ) = (x-z) / (x+z) * (1/ sqrt(2)). v = x / z, x = zv u = (x-z) / (x+z) * (1/ sqrt(2)) = (v-1) / (v+1) * (1/ sqrt(2)) a) when v = 0, the corresponding u is (– 1 / sqrt(2)) b) (v-1) / (v+1) * (1/ sqrt(2)) Dist(O,Q) = (v+1) / sqrt(2) S O

R

Q

Dist(P,l) = (v-1) / sqrt(2) P = (v,1) Line l : (x – z) / sqrt(2) = 0