Matlab Image Warping

Here is some simple Matlab image warping code that I wrote a while ago that others continue to find useful. The code requires that you have Matlab and the Image Processing Toolkit installed.

Results from using this code to fill in holes in images of faces can be found here .

How to use the code

Warping an image using the code requires two steps. To illustrate these steps, suppose I have an image called man11.jpg and I would like to warp the image to fit man12.jpg's features. The first step requires running the captureWarpPoints.m file two times to create a set of points for both images. To begin run
 >> captureWarpPoints('man11.jpg');
This will bring two windows. The window on the left is the reference which shows which point to click on next indicated by the red dot. The window on the right is the capture window you click the mouse to capture the corresponding points. After you click the mouse to capture a point, the recorded point will appear as a red dot in the capture window and the reference window will show the next point to captured.
Press the spacebar to undo any points that are not captured in the correct place. Once you have captured all the points (the default is 25 points) click the mouse again and the points will be saved in a file named "filename".pts.mat (in this example the output file name will be "man11.jpg.pts.mat"). Repeat this process with the image second image (man12.jpg in our example).

Once the two points files are captured run the warpRunner.m file to warp the image. Since in our example man11.jpg is the image we want to warp to man12.jpg we enter

 >> warpRunner('man11.jpg', 'man11.jpg.pts.mat', 'man12.jpg.pts.mat');
The warped image will be saved as warpman11.jpg.jpg. The default output file is jpg, however if one specifies another file format the file will be saved as that type. For example if we wanted to save the file as a bitmap we could enter
 >> warpRunner('man11.jpg', 'man11.jpg.pts.mat', 'man12.jpg.pts.mat', 'bmp');

As far as warping faces is concerned, that's all there is to it. If you would like to warp objects other than faces, you can manually create the corresponding "points" files (which consists of cell arrays of 1 x 2 matracies containing the x, y coordinates) or modify captureWarpPoints.m.