*Readme

COMPUTER VISION
HOMEWORK 4

Name: Yuandi Jin
UNI: yj2246

I have worked out all of the assignments on my Ubuntu Linux.
The test on CUNIX is also successful.
My code is in C++.

Here are some key points of the programs I have written.

/*=====Makefile=====*/


/*=====p1=====*/
Note that my x is related to j, while y related to i.
Step 1. Compute the coordinates of centroid, area and radius.
Step 2. File output.


/*=====p2=====*/
Step 1. File input.
Step 2. Find the brightest point.
Step 3.a. Compute its normal vector.
Step 3.b. Scale it using its magnitude.
Step 4. File output.

The formula:
The 3 coordinates (x,y,z, with respect to the center) of any point on the surface of a sphere (whose radius equals r) satisfy
x^2 + y^2 +z^2 = r^2;
x = j - centroid_x;
y = i - centroid_y;
So we have z = -sqrt(r*r - x*x - y*y)
= -sqrt(r*r - (j - centroid_x)*(j - centroid_x) - (i - centroid_y)*(i - centroid_y));

Z-axis points into the plane. So we make it negative.
For any point on a sphere, the vector from the center to it can be its surface normal.
The surface of the sphere is Lambertian. So surface radiance (L) is independent of viewing direction. It only depends on the angle between the surface normal vector n(unit) and source vector s(unit) (given albedo and source radiance, and the influence of distance r can be not taken into consideration because of the assumption of orthographic projections). At the brightest point,since the angle between n and s is 0, we can safely assume n equals s.


/*=====p3=====*/
It is straightforward.


/*=====p4=====*/
Step 1. Compute surface normals.
For each point (masked), find the 3 images where it appears brightest:
im[b[0]],im[b[1]],im[b[2]]

Read Sx[b[0]],Sy[b[0]],Sz[b[0]]
Sx[b[1]],Sy[b[1]],Sz[b[1]]
Sx[b[2]],Sy[b[2]],Sz[b[2]] from file.

Compute M using I=SM.
n=M/|M|, albedo=|M|.

Store in a rgb image.

Step 2. Compute surface gradients(p,q).
At each pixel, compute its (p,q) using (p,q,1)~(nx,ny,nz), and save it in an array.

File output.

Step 3. Compute albedo.
Scale aobedo.
Draw the output image.


/*=====p5=====*/
I adopted the method introduced in homework description.
The chosen seeds are:
240 240
220 240
240 220
260 240
240 260
First compute the depths of pixels at the same row or col as the seed (thus build a "cross").
Then compute the depths of pixels in four regions (down-right, up-right, up-left, down-left).
The chosen seeds are around the center because EVERY ARM OF THE "CROSS" SHOULD ONLY CUT THE BOUNDARY ONCE to ensure good performance.
(If twice or more times, some pixels on the cross will be computed wrong)
I found that depths of pixels near the edge are not reliable enough, so I compute maximum depth and minimum depth only using depths of pixels on the cross, and CLAMP the depths of other pixels.

Since z-axis is pointing into the image plane, the pixels that are near the center (and have shorter distance to the light source) are darker than those far from the center.


