Problem Set for 3D Geometric Transformations and Rotation Matrices - Prof. David Jacobs, Assignments of Computer Science

A problem set for a course on 3d geometric transformations, focusing on rotation matrices, their properties, and the conditions they must meet to represent a 2d or 3d rotation. It also includes examples of different rotation matrices and their effects on 3d points, as well as a challenge problem to test understanding of rigid 3d motion.

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-kud-1
koofers-user-kud-1 🇺🇸

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Problem Set 7
CMSC 426
Assigned Tuesday, November 22, Due Thursday, December 8
1. 2D Motion with a Matrix
a. For each of the following matrices, indicate whether it represents a 2D
rotation. Explain your answer.
100
0
3
3
3
6
0
3
6
3
3
100
0
2
3
2
2
0
2
1
2
2
100
0
2
1
4
1
0
4
1
2
1
In each of these matrices, we only need to worry about the upper 2x2 part of the matrix.
The third row and column are there for translation, but since they are 0 except for the 1
in the third row and column, they do not encode any translation.
The first matrix is not a rotation matrix because each of the first two columns has a
magnitude that is not equal to 1. So, for example, if you apply the matrix to the point
(1 0)T it will be mapped to the point (1/2, -1/4)T which is a distance of sqrt(5)/4 from the
origin.
With the second matrix, each of the columns does have a unit magnitude. However, the
first two columns are not orthogonal to each other. We can see this by taking their inner
product:
0
4
6
4
2
2
3
,
2
1
,
2
2
,
2
2
Since their inner product is not zero, they are not orthogonal. This means, for example,
that if we apply this matrix to the points (1,0) and (0,1) we will wind up with two points
that are not perpendicular any more. A simpler way to see this is that a matrix, M, can
only represent a 2D rotation if M(1,2) = - M(2,1) and M(1,1) = M(2,2) (this is a
necessary, but not a sufficient condition, because it does not ensure that the columns have
unit length). However, this condition doesn’t generalize easily to 3D rotations.
With the third matrix we can check that each column is a unit vector, because it has a
magnitude of 3/9 + 6/9. And the two columns are orthogonal to each other, because they
have an inner product of zero. We could also note that they have the form M(1,2) = -
M(2,1) and M(1,1) = M(2,2).
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Problem Set for 3D Geometric Transformations and Rotation Matrices - Prof. David Jacobs and more Assignments Computer Science in PDF only on Docsity!

Problem Set 7

CMSC 426

Assigned Tuesday, November 22, Due Thursday, December 8

  1. 2D Motion with a Matrix a. For each of the following matrices, indicate whether it represents a 2D rotation. Explain your answer.

In each of these matrices, we only need to worry about the upper 2x2 part of the matrix. The third row and column are there for translation, but since they are 0 except for the 1 in the third row and column, they do not encode any translation.

The first matrix is not a rotation matrix because each of the first two columns has a magnitude that is not equal to 1. So, for example, if you apply the matrix to the point (1 0)T^ it will be mapped to the point (1/2, -1/4)T^ which is a distance of sqrt(5)/4 from the origin.

With the second matrix, each of the columns does have a unit magnitude. However, the first two columns are not orthogonal to each other. We can see this by taking their inner product:

Since their inner product is not zero, they are not orthogonal. This means, for example, that if we apply this matrix to the points (1,0) and (0,1) we will wind up with two points that are not perpendicular any more. A simpler way to see this is that a matrix, M, can only represent a 2D rotation if M(1,2) = - M(2,1) and M(1,1) = M(2,2) (this is a necessary, but not a sufficient condition, because it does not ensure that the columns have unit length). However, this condition doesn’t generalize easily to 3D rotations.

With the third matrix we can check that each column is a unit vector, because it has a magnitude of 3/9 + 6/9. And the two columns are orthogonal to each other, because they have an inner product of zero. We could also note that they have the form M(1,2) = - M(2,1) and M(1,1) = M(2,2).

We have to check one more thing. We have to make sure that the matrix has a determinant of 1, which it does (3/9 - - 6/9 = 1). If the matrix had a determinant of -1, this would mean that it encoded a rotation and a reflection.

b. Give a matrix that will represent a 45 degree clockwise rotation of 2D points.

Using the formula for counterclockwise rotation, and a rotation of -45 degrees, we have:

sin cos 0

cos sin 0

2

2 2

2

2

2 2

2

We can check that this rotation is clockwise, because if we apply it to (1 0 1) we will get a point with a negative y component.

c. Give a matrix that will rotate points clockwise by 90 degrees about the point (1,2). That is, the effect should be as if you held the point (1,2) fixed and rotated everything about that point by 90 degrees.

We can do this by combining together three matrices. The first will translate the points so that (1,2) is translated to the origin. Then a second matrix can rotate the points about the origin. Finally, a third matrix will translate the points so the origin goes back to (1,2). Doing this, we get:

If we want to check that this is correct, we can apply it to (1,2) and see that it produces (1,2). At the same time, we can check that the point (2,2), which is just 1 away in the x direction should be rotated to be 1 below (1,2), to the point (1,1).

  1. 3D Motion with a Matrix a. For each of the following matrices, indicate whether it represents a 3D rotation.

The third matrix is a rotation matrix. It is easy to see that the columns have unit magnitude, and they all have inner products of 0. And we can check:

_a = 0 1 0 0 -1 0 0 0 0 0 1 0 0 0 0 1

det(a) ans = 1_

b. Give matrices that will have the following effects: i. Translate 3D points in the direction (2,-1,3).

ii. Translate 3D points in the direction (1,0,-1) and then scale them by a factor of 2.

We can do this by combining two matrices:

iii. Scale the points by a factor of 2 and then translate them in the direction (1,0,-1).

Similarly, we can combine the same two matrices in a different order. Note that we obtain a different result.

c. Give a rotation matrix that will rotate the y axis so that it points in the same direction as (1,1,1) , while rotating the x axis so that it points in the direction (-1, 0, 1).

The first column of the matrix will give the location, after rotation, of the point (1,0,0). We want this to be in the direction (-1,0,1), but it should be only a distance of 1 from the origin, so it should go to (-1,0,1)/sqrt(2). The second should point in the direction (1,1,1) but have unit length, so it should be (1 1 1)/sqrt(3). The third column needs to be orthogonal to these two columns. Let’s say the third column is (a,b,c). Then, to get orthogonality, we need –a+c = 0 and a+b+c = 0. So we have a = c, and 2a + b = 0 which means b = -2a. These equations are satisfied by (1, -2, 1), or by any scaled version of this vector. If we scale this vector to have unit length, it becomes (1, -2, 1)/sqrt(6). This would give us the matrix:

If we take the determinant of this matrix, we get:

_A = -0.7071 0.5774 0. 0 0.5774 -0. 0.7071 0.5774 0.

det(A) ans =_

-

So this isn’t right. This matrix also reflects points. Where did we go wrong? Instead of scaling the third column by sqrt(6) we can scale it by –sqrt(6). Then it will still be orthogonal to the other columns, but the determinant will be reversed in sign. So the right answer is:





















S

b. Challenge problem: Do the matrices that you found really represent a rigid 3D motion? Explain how you would determine this.

The fourth column represents translation, so anything can go there. The condition for the rest of this to be consistent with a real motion is that S(1,1:3) and S(2,1:3) should have the same magnitude and be orthogonal. This is true for this matrix. Likewise, we need S(3,1:3) and S(4,1:3) to have the same magnitude as each other, and to be orthogonal, which is also true. Note that we do not need, for example, to have S(1,1:3) and S(3,1:3) have the same magnitude, because they come from different transformations, that represent the camera at different distances from the points, and so can involve different scale factors.

c. Suppose there is a fifth scene point, which produces the image coordinates:   p^15 9 , 3 p 52 5 , 7

Find the 3D coordinates of this scene point.

One way to solve this is to invert S, and multiply this by the vector (9,3,5,7)T, which represents the image coordinates of the 5th^ point. We get:

_>> inv([2 2 1 3; 1 -2 2 6; 3 0 3 2; 3 0 -3 4]) ans = -0.1429 -0.1429 0.3095 0. 0.4048 -0.0952 -0.1548 -0. 0.0476 0.0476 0.1190 -0. 0.1429 0.1429 -0.1429 0.

ans*[9;3;5;7] ans =

0 1._

  1. Corner Detection. You should implement the corner detector that we discussed in class. Recall that to do this we perform the following steps. First, for every point in the image, we form a matrix, C, which is based on the image gradients in the neighborhood of this point. You should compute image gradients in the same way that you did for edge detection, smoothing the image first. I suggest that you

reuse the routines image_gradient and smooth_image from the edge detection problem set. Use a 5x5 neighborhood to form C. Then use singular value decomposition, with the matlab routine svd , to find the singular values of C. This is summarized in the equations:

The measure of cornerness for a point will be the smallest of the two singular values. Since you have a measure of cornerness for every pixel in the image, you should output a matrix that is the same size as the input image, and that contains the cornerness for each pixel. So your complete program will have the form: M = image_cornerness(I,sigma). Here I is the input image, and sigma is a value indicating how much to smooth the image before computing the image gradient. I have given you a function display_best_corners , which will take as input an image, and the output of your cornerness routine, and will output an image that shows where the corners are.

We can use this, on the swan image for example, with the calls:

M = image_cornerness(swanbw, 2); imshow(display_best_corners(swanbw, M, 20));

This will display the 20 best corners in the swan image. A link to a picture of the result is in swancorners.jpg.

Let’s step through an example of how this will work. Suppose we have an image with a corner:

I = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 10 0 0 0 10 10 10 10 0 0 0 10 10 10 10 0 0 0 10 10 10 10

Computing the x and y components of the image gradient, I get:

Ix = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 0 0 0 0 0 5 5 0 0 0

1 2

1 2

UsingSVD 2

2

0

R R

I I I

I II

C

x y y

x x y 

  

 ^  

 

 

   

 





% We want to sum IxIx, IxIy and IyIy within each region. % It's faster to precompute these at each pixel and then % sum them. sumfil = ones(5,5); % Filtering with this will sum up everything in a 5x % window. M11 = imfilter(IxIx, sumfil); M12 = imfilter(IxIy, sumfil); M22 = imfilter(IyIy, sumfil); % M11(i,j), for example, has the sum of IxIx within a 5x % region around pixel (i,j). C = zeros(h,w); % C will contain the cornerness measure for each pixel. % We'll loop through each pixel to compute this, because % I don't think there's any way to do this all at once. for i = 1:h for j = 1:w d = svd([M11(i,j), M12(i,j); M12(i,j), M22(i,j)]); % d will contain the singular values of the matrix % based on derivatives. C(i,j) = d(2); % svd always returns singular values in descending % order, so we can just take the second one. end end

function Is = smooth_image(I, sigma) % This is the same as the function used in edge detection. if sigma == 0 Is = double(I); % There will be no smoothing. This is especially % useful for debugging later functions. else n = 1+2ceil(4sigma); % The length of the filter will be odd, and at least % four times sigma. Is = imfilter(double(I), fspecial('gaussian', n, sigma), 'replicate'); end

function [Dx Dy] = image_gradient(I) % This is the same as the function used in edge detection. Dx = imfilter(I, [-.5 0 .5],'replicate'); Dy = imfilter(I, [-.5; 0; .5], 'replicate');