Various projects and musings by Mason Smith
Barycentric coordinates are a widely-used formulation to linearly interpolate data on a simplex. By extending this notion to arbitrary (simple) poylgons via complex coordintes, we can use barycentric coordinates in many kinds of applications requriring interpolation, such as 2D image morphing.
My program implements P2P and Cauchy-Green coordinates for use in image morphing.
You can download the
source here. Compiling the program
requires OpenGL, GLUT, Boost, Boost.ProgramOptions, BLAS, and LAPACK. A Makefile
is included, so building the program should be as simple as `make`.
You can download a Linux binary here. The program options are listed here:
Options:
-i [ --input-file ] arg Input file to load (required)
-g [ --grid-size ] arg (=60) Size of grid to use
- [ --use-cg ] Use Cauchy-Green coordinates rather than P2P
P2P Options:
-l [ --lambda ] arg (=0.01) Weight for position constraints
-s [ --samples-per-edge ] arg (=3) Number of samples per edge for
position constraints
When the image first appears, right-click to lay points to surrond the region of interest on the image. Left-click to drag points already in place.
In CG mode, after creating the cage, press space to compute the coordinates of interest. The rest of the image will be removed from view, leaving the region of interest. Use left-click + drag to move the cage points and morph the image.
In P2P mode, after creating the cage, press space to lay and move control points inside the cage region. Press Space again to calculate the coordinates and start morphing the image.
Other controls are as follows:
Examples from running the program are given here, with explanation.
Starting the program in P2P mode
Laying down the cage
Fine tuning the border
After the control points are put on
Now able to morph with control points
A new position for the froggy
Starting the program
Laying down the cage of points
Moving already-set points with click-drag
Finished point cage
Now in morphing mode...
Bad hair day, anyone?
Sonic leans over under the weight of his own fist
Morphing is awesome! Morphing with a 50-point cage with 16 control points and a 125x125 grid works at fully interactive speeds. Creating effects using the P2P systems is a lot more convenient than using the grid, but it is somewhat less precise. Using a lambda of 0.01 for the position constraint weights gives decent results.