Programming Assignment 1
Assigned 28 January 2002
Due 11 February 2002
Using "the one true way" implement a model of a 35mm camera with a 15mm focal‑length lens. Use your camera to image points arranged at the corners and edge‑centers of a box about the size of a cereal box (20 points in all, about 12 inches tall, 8 inches wide, 3 inches thick). Anti-alias the images of the points. Make a short movie, animated GIF, or sequence of still pictures showing your camera viewing the points from a gradually changing position.
The one true way of doing view transforms
Many descriptions of view transformations are counterintuitive, because they try to synthesize the view transform directly. An easier to understand approach goes about it another way: a viewing transform is the inverse of a projection matrix.
A projection matrix can be written as follows: Pwi=[A B O], where A and B are unit vectors on the image plane, and O is a vector from the Center of Projection (COP) to the origin of the image plane. If we take the origin of the image plane in its center, O=[0 0 f], where f is the focal length of the camera. The camera view can be rotated by multiplying Piw by a rotation matrix.
The coordinates [u v] of the projection of a point [x y z] (specified in world coordinated) can then be computed as follows:
In my implementation, the computation consists of the following steps:
- set up the projection matrix
- multiply it by 3 rotation matrices (one for each axis) and invert the result
- multiply the COP by the same rotation matrices
- subtract the result from the coordinates of all the points
- project the points onto the image plane
- normalize the coordinates
- clamp the results to the domain defined by the image plane
- iterate through the coordinates and put a 3x3 Gaussian kernel at each location, with additive blending
- cap the values outside the color range
In my approach, the box "stays in place" at the origin of the world coordinates, and the camera moves around it. The computation is done in image plane units (i.e., in pixels). The image size is 400x300 pixels.
I also designed a crude interface for the program, allowing the user to manipulate the camera. The image is larger, so the anti-aliased points can be seen easier. There are three sliders on the left side that set the position of the COP in world coordinates, and three sliders on the right that set the rotation for each axis. A snapshot of the interface is shown in the figure below:
For the movie, I wrote a script that moves and rotates the camera.
- movie: CerealBox.avi
- function: cerealBox.m
- movie script: makeMovie.m
- point data (ASCII): ws
Last modified by on Feb. 11 2002.