Feature Based Image Metamorphosis

 

Algorithm:

                   Morphing from one image to another is accomplished by calculating interpolated lines for each set of lines over a number of steps, morphing the initial image forward and the final image backwards to the interpolated lines, and creating frames by making weighted averages of the two morphed images.  At the first step the final image is completely mapped onto the initial image but does not appear because it has a weight of zero in the average.  Likewise, in the final step the initial image is completely mapped onto the final image and receives a zero weight in the average.  At the halfway point, each image is halfway mapped onto the other and they receive an equal weighting in the average.

Equations :

Pseudo Code for transformation using Multiple Line Algorithm :

for each Pixel X in the destination image

    DSUM = (0,0)

    weightsum = 0.0

    For each line Pi,Qi

            calculate u,v based on Pi,Qi

            calculate Xi' based on u,v and Pi', Qi'

            calculate displacement Di = Xi' - X for this line

            dist = shortest distance from X to (Pi,Qi)

            weight = pow( pow (length,p) / (a + dist ),b)

            DSUM += Di *weight

            weightsum += weight

   X' = X + DSUM / weightsum

    destination image (X) = source image (X')

 

where a,b,p are user controlled parameters .

If a is barely greater than zero and the distance from the line to the pixel is zero , then the pixel would go exactly where the user wants it to.

Variable b determines how the relative strength of different lines falls off with distance.

Variable p determines the relative weight for all lines. p = 0 implies all lines have the same weight &

p = 1 implies longer lines have greater relative weight than shorter lines.

Results :

 a = 0.5 , b= 1.5 , p = 0.3

Source  Image

Destination Image

 

Animated Gif of the frames obtained

 

 

a = 1.0, b = 1.5, p = 0.3

Source Image

Destination Image

Animated Gif

 

a = 0.5, b = 1.0 , p = 0.3

Source Image Destination Image
 
Animated Gif (delay = 20)  

Profile data