CS 332

Assignment 5

Due: Thursday, October 20

This assignment contains problems related to image formation and the recovery of 3D shape from shading. The code files for this assignment are stored in the /home/cs332/download/shading subdirectory on the CS file server.

Problem 1 (25 points): Representations of Surface Orientation

Part a: In general, any visible surface orientation in space can be represented uniquely by two numbers. Several representations of surface orientation have been used in the vision literature. Ikeuchi and Horn used a representation based on stereographic projection, in which the two coordinates specifying surface orientation were labeled f and g. We briefly mentioned another representation that is often used in perceptual studies, referred to as the slant-tilt representation.

Suppose an observer is viewing a surface whose depth is constant in the vertical direction. In the case of the (f,g) representation, g = 0 for every point on such a surface. In the slant-tilt representation, the tilt angle is 0° or 180° at every location. The diagram below shows a birds' eye view of an observer viewing a cylindrical surface, with a point p on the surface. The angle θ is the slant angle - intuitively, it captures how much the surface is turned away from the viewer. The diagram also shows the construction of the f value for the surface orientation at point p. Derive an expression that relates θ directly to f. Hint: α=θ/2.

Part b: Now generalize your expression in Part a to the case where f and g vary in the horizontal and vertical directions. In this case, the distance labeled fp in the above figure now generalizes to the distance from the origin (0,0) to the location (fp,gp) that represents the surface orientation for the point p on the surface. Also derive an expression for the tilt angle τ illustrated in the following diagram:

Part c: The showSP function described in the Lab 5 handout creates two matrices fmap and gmap that store the (f,g) representation of the surface orientations on a sphere. Write a function getSlantTilt that uses the expressions you derived in Part b to calculate the slant and tilt angles from the (f,g) representation. Your function should have two inputs that are matrices holding the f and g values (like fmap and gmap), and should have two outputs that are matrices of the same size, and store the corresponding slant and tilt angles at each location, given in degrees. Check your results by viewing the output matrces using imtool. Note that the range of values to display with imtool can be obtained by finding the minimum and maximum values in a matrix, for example:

   >> minval = min(min(slantmap));
   >> maxval = max(max(slantmap));
   >> imtool(slantmap, [minval maxval]);

Hints: There are two MATLAB functions for the inverse tangent function (i.e. "the angle whose tangent is ..."), atan and atan2, that you can read about with the MATLAB Help facility. For example, atan(1.0) and atan(0.8,0.8) both return 0.7854, which is 45° in radians. The deg function, defined in the ~cs332/download/shading folder, converts radians to degrees. Each step of the calculation of slant angle can be performed with a function that can be applied to an entire matrix of values all at once, so your getSlantTilt function can be very short!

Problem 2 (35 points): Image Formation and Shape from Shading

Part a: Assume again that an observer is viewing a surface whose depth is constant in the vertical direction. Now suppose that the surface has the horizontal cross-section shown below and has Lambertian reflectance characteristics. Let the surface be illuminated by a distant point source of light at an angle of 30° away from the viewer's direction, as shown in the picture. In this scenario, a point on the surface will project to the image with an intensity given by the following expression:

    I(x) = I0 ρ cos(i)

Where I(x) is the intensity at location x in the image, I0 is the intensity of the light source, ρ is the albedo (color) of the surface, and i is the incident angle between the light source and the local surface normal. For simplicity, let I0 and ρ be 1.0, so that the maximum intensity measured in the image is 1.0. On the empty graph below, plot a cross-section of the intensities that would appear in the image, for this surface and light source. Show how you derived your answer and be sure to show the observed intensities across the entire image. To help with your solution, the table on the right indicates the value of the cosine function for a set of angles.

Part b: Suppose that the surface from Part a has pure specular (mirror-like) reflectance characteristics. On the graph below, plot a cross-section of the new pattern of intensity that would be projected onto the image.

Part c: Suppose that we have an algorithm for recovering the direction of the light source from the visual image that does not perform very well. When applied to the image that you generated in Part a, suppose that this algorithm derived an incorrect light source direction of 45° from the line of sight. Given this new light source direction, and the pattern of intensity that you derived in Part a, construct a new surface that is consistent with both sources of information (note that multiple solutions are possible here). You can again assume a Lambertian surface with constant albedo, ρ = 1, and a distance point light source. Describe in words, how you generated this surface.

Part d (from Patrick Winston): Suppose that Martians generally have spherical heads and Lambertian skin with constant albedo. The really beautiful Martians have egg-shaped heads, with the long axis of the egg horizontal and pointing in the direction the Martian is looking. Describe where you would advise a Martian with a spherical head to place dark makeup, given that the Martian wishes to look like it has an egg-shaped head. Explain your answer, and try to be specific. You may assume that the light source is behind the viewer at all times.

Problem 3 (40 points): The Ikeuchi and Horn Shape from Shading Algorithm

In class, we summarized an algorithm for recovering 3-D shape from shading proposed by Ikeuchi and Horn. In lab, we will work with an implementation of a simplified version of the algorithm that assumes that the surface is constant in the vertical direction so that g = 0 everywhere on the surface. The questions in this problem relate directly to the work that we will do in lab.

Part a: For the case of a cylindrical surface illuminated by a light source that is at an angle of 20° from the viewer (Example 1 in shadingScript.m), the initial f values given as input to the algorithm include known f values at the rightmost boundary of the cylinder and at the location of the shadow boundary on the left side of the cylinder. All other f values are initially set to 0. After only one iteration of the algorithm, all of the f values between the two known points are changed. What caused these values to change from the initial zero values, during the first iteration? Hint: what are all the sources of constraint used by the algorithm?

Part b: In the shadingScript.m script, Example 2 is similar to Example 1, except that the light source direction is changed to 45°. Examine the results of running Example 2, describe any differences that you see from Example 1, and explain why these differences arise.

Part c: Example 3 in shadingScript.m uses the input image that was created using a light source direction of 45° away from the viewer, but specifies an incorrect light source direction of 20°. Carefully observe the final results obtained in this case. In particular, examine the true and computed f values and shape displayed overlaid in the lower right corner of the results window. How do the true and computed f values and shape differ? Explain why these differences arise.

Submission details: Hand in a hardcopy of your answers to all of the problems here, and a hardcopy of your final getSlantTilt.m code file. Drop off an electronic copy of your getSlantTilt.m code file by logging into puma, connecting to your shading folder and executing the following command:

submit cs332 assign5 *.*