Inverse texture mapping in Matlab
 
Purpose:

Implement an "inverse" texture mapper. That is map a billboard image in 3-space through a camera onto the image plane by working from the image-plane coordinates to the texture (billboard) coodinates.
 
Table of contents

Inverse texture mapping
Texture mapping is the processes of mapping an image onto a surface. In this discussion, the surface is a rectangle. In the example below, the rectangle contains the original texture map. The skewed image is the resulting shape after the rectangular surface is rotated in space and projected into the image plane.


 

Inverse texture mapping is to map every point on the skewed image. The point on the texture map will be the color of the corresponding pixel in the skewed image. Inverse mapping allows the resulting image to be gap free. Lines at an angle, however, will be jaggy. The jaggies can be smooth for the human eye by applying bi-linear interpolation between neighboring points. 

For this particular assignment I was interested in using linear algebra solution to maping the skewed image points to the original texture map. This can be achieved by creating linear constraints to solve by Gaussian Elimination. I was intrigued by exploiting Matlab to perform the Gaussian Elimination. 
The linear constraints solve the equations of [x,y,z] = [ABC] * [u,v,1]', where (x,y,z) is the world coordinate. "Z" is one when the point is projected into the image plane. These coordinates are a result of rotating a camera around the rectangular surface and computing the resulting image in the image plane (as done in the last homework, expect that this time only the four corners of the rectangle are manipulated). The camera parameters have been manipulated to offer the most appeal. The (u,v) coordinates are those in the image plane. In the picture above the 8 corner points are numbered 1 to 4. 

These points construct the equations to solve for [ABC]. Once [ABC] is known, every point can be mapped from one shape to the next. Here is an overview of the equations to solve.

Mapping points can lead to decimal coordinates and the assigned color is ambigious. This is solved by interpolating the colors of the neighbouring points as follows where (u,v) are between 0 and 1. "c" is the color at the point(uv)

Here are examples of the filter without filter and with; the filter might be off:
 
 

Matlab can efficiently perform all required operations. Gaussian elimination is A\b, where A is and NxN matrix representing the linear equation coefficients and b is the equivalence of the equations; b is a row of zeros except for the scale factor. In addition, reshaping 2-dimensional matrcies into columns and rows allows for accessing a list of elements a search for the elements of a particular value.
 

Results
Rotating checker board -- Notice the fuzzy edges as a result of the bi-linear interpolation. 
 


Rotating Old Well -- Demonstrates that an arbitrary image can used. Color is achieved by considering each color separately.
 

Matlab Code

Here is the Matlab code to perform the inverse texture mapping:

  • mainTM -- Performs the texturemapping
  • texturemap -- Solve for the projection matrix
  • well2.jpg -- graphic to map
  • batch -- batch process to make Matlab movies
 top * home * academics * comp235
dorian miller, 11/9/2000