Computer Vision I CSE 252a, Fall 2012 David Kriegman Assignment #2 (Due date: 11/6/2012) Name: Student ID: Email: Problem 1 [1 pts] Calculate the number of steradians contained in a spherical wedge with radius r = 1, defined by θ = π 6, ψ = π 6 centered around vector ( 2 2, 2 2, 0). Problem 2 [3 pts] Consider a rectangular surface with vertices (1, 3, 3), (1, 3, 3), (1, 3, 3), and (1, 3, 3). If the radiance on the surface is L (z 2 + y 2 + 1) (with L constant) what is the irradiance arriving at position (0, 0, 0) with normal vector (1, 0, 0)? Figure 1: Problem 2 Setup Problem 3 [3 pts] a. Consider a cylinder with radius r and height h whose base is centered at z = 0 along the xy-plane. If the walls of the cylinder have constant radiance L and the top of the cylinder has constant radiance 7L, what is the irradiance E at the point (0, 0, 0) assuming that the surface at (0, 0, 0) has a normal vector of (0, 0, 1)? b. What is the irradiance if the radiance of the top is now Ld 3 where d is the distance to the center of the top (d [0, r])? Problem 4 [2 pts] A Lambertian surface is one that appears equally bright from all viewing direction. Say in other words, the emitted radiance from a Lambertian surface is not a function of outgoing direction. Assume that we have an ideal Lambertian surface which also reflects all incident lights (absorbing none), the BRDF f(θ i n, ψ i n, θ o ut, ψ o ut) of such a surface will be a constant. What is that constant? 1
Figure 2: Problem 3 Setup Hint: If we integrate the radiance of the surface over all directions, the total emitted energy is equal to the incoming energy. Problem 5 - Photometric Stereo [5 pts] The goal of this part of the assignment is to implement a couple of different algorithms that reconstruct a surface using the concept of photometric stereo. The majority of this problem should be done in MATLAB. There may also be sections in which you need to derive mathematical equations. Lambertian Reconstruction Photometric stereo is a technique to render depth of objects and surfaces from images of the same view with different lighting conditions. Figure 3: Synthetic Data Implement the photometric stereo technique described in Forsyth and Ponce section 2.2 and the lecture notes. a. Write a function that estimates the surface normals and albedo map using the included images and the known light directions. b. Write a program that reconstructs the depth map from the normals. You can first try the naive scanlinebased shape by integration method described in the book. If this does not work well on real images, you can use the MATLAB implementation of the Horn integration technique on the course website. c. Use these functions in a program that reads in the images and corresponding light source directions, calculates the normal and albedo map, and reconstructs the depth map. Calculating Light Direction Often times the light direction is unknown, in these cases it is required to estimate the light direction using a highly specular ball. Derive the equations to find the light direction L, using the center of the ball, C = (x, y) T, and the brightest point in the image B = (x, y) T. You may find this equation useful: L = 2N(R N) R 2
where R is the reflection direction and N is the surface normal. d. Write a function that calculates the light direction in a given image using your derivation. e. Write a program that calculates the light direction of all 8 spheres and uses these to reconstruct the depth map of the bottle using the functions you created in parts a, b, c and d. Do you notice any errors in this depth map? Why? Hertzmann and Seitz Reconstruction Using the surface normals with known light direction is not the only way to create 3D reconstructions. In this section, we look at a method proposed by Hertzmann and Seitz that uses the known BRDF of a material to obtain depth information. f. Implement the photometric stereo algorithm described in section 2 of Shape and Materials by Example: A Photometric Stereo Approach by Hertzmann and Seitz (can be found on the course website). g. Use the algorithm to reconstruct the 3D shape of the bottle using the set of corresponding bottle and sphere images. You may find it useful to use an algorithm to speedup the nearest-neighbor search, such as a kd-tree. What to turn in for Problem 5: Submit a hardcopy of your figures and code on the due date with the following: Your code for: Lambertian reconstruction (normals, albedo and depth). Figures of your normals, albedo and reconstruction of the synthetic data. Your code and derivation for calculating light direction as well as the output of this function on the first three sphere images, include your xy coordinates that you used for C and B. Figures of your reconstruction of the bottle with the lambertian reconstruction. Your code for: Hertzmann-Seitz implementation Figures of your reconstruction of the bottle with the Hertzmann-Seitz reconstruction. Problem 6 - Surface Rendering [5 pts] In this portion of the assignment we will be exploring different methods of approximating local illumination of objects in a scene. As discovered in the photometeric stereo portion of this homework, we know that some light models work better with different view, illumination sources and materials. Now, we will be exploring these systems from the opposite approach. In this section of the homework, you will be asked to calculate the images intensity of a 3D object with known geometry, but with various light sources, different materials, and using a number of illumination models. Lambertian Illumination One of the simplest models available to render 3D objections with illumination is the Lambertian model. This model finds the apparent brightness to an observer using the direction of the light source L and the normal vector on the surface of the object N. The brightness intensity at a given point on an object s surface, I d, with a single light source is found using the following relationship: I d = L N(I l C) where, C and I l are the the color and intensity of the light source respectively. 3
Phong Illumination One major drawback of Lambertian illumination is that it only considers the diffuse light in its calculation of brightness intensity. One other major component to illumination rendering is the specular component. The specular reflectance is the component of light that is reflected in a single direction, as opposed to all directions, which is the case in diffuse reflectance. One of the most used models to compute surface brightness with specular components is the Phong illumination model. This model combines ambient lighting, diffused reflectance as well as specular reflectance to find the brightness on a surface. Phong shading also considers the material in the scene which is characterized by four values: the ambient reflection constant (k a ), the diffuse reflection constant (k d ), the specular reflection constant (k s ) and α the Phong constant, which is the shininess of an object. Furthermore, since the specular component produces rays, only some of which would be observed by a single observer, the observer s viewing direction (V) must also be known. For some scene with known material parameters with M light sources the light intensity I phong on a surface with normal vector N seen from viewing direction V can be computed by: I phong = k a I a + m M { kd (L m N)I m,d + k s (R m V) α I m,s }. R m = 2N(L m N) L m where I a, is the color and intensity of the ambient lighting, I m,d and I m,s are the color values for the diffuse and specular light of the m th light source. Blinn-Phong Illumination One shader that is commonly used in graphics rendering today is a modification to the Phong model called the Blinn-Phong model. This model is the same in many respects to Phong s original model except it uses the halfway vectors to calculate the specular reflectance intensity. The halfway vectors are calculated as follows: H = L + V L + V We use this halfway vector to replace R V with N H. Rendering In this part of the assignment you will be asked to write and use the illumination model programs that you learned about in previous sections. You will be finding the light intensity using all three modeling technique for a torus shape with various lighting and material conditions. The equation of a torus in cartesian coordinates is as follows: or in parametric coordinates: T (x, y, z) = ( r 1 x 2 + y 2 ) 2 + z 2 r 2 2. x(u, v) = (r 1 + r 2 cos v) cos u y(u, v) = (r 1 + r 2 cos v) sin u z(u, v) = r 2 sin v where r 1 and r 2 represent the outer and inner radii respectively. 4
Figure 4: Depiction of a torus a. Write a function that calculates the Lambertian light intensity given the light direction L with color and intensity C and I l, and normal vector N. Then use this function in a program that calculates and displays the torus using each of the two lighting sources found in Table 1. Note: You do not need to worry about material coefficients in this model. b. Write a function that calculates the Phong light intensity given the material constants (k a, k d, k s, α), V, N and some number of M light sources. Then use this function in a program that calculates and displays the torus using each of the sets of coefficients found in Table 2 with each light source individually, and both light sources combined. c. Write a function that calculates the Blinn-Phong light intensity given the material constants (k a, k d, k s, α), V, N and some number of M light sources. Then use this function in a program that calculates and displays the torus using each of the sets of coefficients found in Table 2 with each light source individually, and both light sources combined. Hint: To avoid artifacts due to shadows, ensure that any negative intensities found are set to zero. Table 1: Light Sources m Location Color (RGB) 1 ( 1 3, 1 3, 1 3 )T (1, 1, 1) 2 (1, 0, 0) T (1,.5,.5) Table 2: Material Coefficients Mat. k a k d k s α 1 0 0.1 0.75 5 2 0 0.5 0.1 5 3 0 0.5 0.5 10 4 0 0.1 0.75 10 Table 3: Other Parameters r 1 50px r 2 100px ˆV (0, 0, 1) T What to turn in for Problem 6: Submit a hardcopy of your figures and code on the due date with the following: Your code for: Lambertian Model, Phong Model, Blinn-Phong Model Your code for: The program(s) that used to calculate and display the toruses. Figure of all your renderings for the toruses under the different lighting conditions and materials using all 3 models. Please keep in mind that there are a number of plots, so take care to make them readable. In addition, please email to jmerkow@ucsd.edu a copy of your code and figures for problems 5 and 6. Please send as a zip or tar file with [CSE252AHW2] in the subject line. 5