Warping and Morphing
Warping
There are two ways to warp an image. The first, called forward mapping, scans through the source image pixel by pixel, and copies them to the appropriate place in the destination image. The second, reverse mapping, goes through the destination image pixel by pixel, and samples the correct pixel from the source image. The most important feature of inverse mapping is that every pixel in the destination image gets set to something appropriate. In the forward mapping case, some pixels in the destination might not get painted, and would have to be interpolated. We calculate the image deformation as a reverse mapping. The problem can be stated "Which pixel coordinate in the source image do we sample for each pixel in the destination image?"
Image Warping• Move pixels of image
– Mapping– Resampling
Mapping• Define transformation
– Describe the destination (x, y) for every location (u, v) in the source image(or vice-versa, if invertible)
Example Mappings• Scale by factor
x = factor * u
y = factor * v
Example Mappings• Rotate by degrees
x = ucos - vsiny = usin + vcos
Other Mappings• Any function of u and v
x = fx(u, v)
y = fy(u, v)
Forward Mapping •Traverse input pixels
•Miss/overlap output pixels
W
Forward Mapping
• Iterate over source image– Some destination pixels may not be covered– Many source pixels can map to the same
destination pixel
Inverse Mapping
•Traverse output pixels
•Does not waste work W-1
Reverse Mapping• Iterate over destination image
– Must resample source– May oversample, but much simpler!
Resampling
• Evaluate source image at arbitrary (u, v)– (u, v) does not usually have integer coordinates
• Some kinds of resampling– Point resampling– Triangle filter– Gaussian filter
Source Image Destination Image
Point Sampling
• Take value at closest pixel– int iu = trunc(u + 0.5);– int iv = trunc(v + 0.5);– dst(x, y) = src(iu, iv);
• Simple, but causes aliasing
Triangle Filter
• Convolve with triangle filter
Triangle Filter
• Bilinearly interpolate four closest pixelsa = linear interpolation of src(u1, v2) and src(u2, v2)
b = linear interpolation of src(u1, v1) and src(u2, v1)
dst(x, y) = linear interpolation of ‘a’ and ‘b’
Gaussian Filter
• Convolve with Gaussian filter
Width of Gaussian kernel affects bluriness
Filtering Method Comparison
• Trade-offs– Aliasing versus blurring– Computation speed
Image Warping Implementation• Reverse mapping
for (int x = 0; x < xmax; x++) {
for (int y = 0; y < ymax; y++) {
float u = fx-1(x, y);
float v = fy-1(x, y);
dst(x, y) = resample_src(u, v, w);
}
}
Source Image Destination Image
Polynomial Transformation
Geometric correction requires a spatial transformation to invert an unknown distortion function. The mapping functions, U and V , have been universally chosen to be global bivariate polynomial transformations of the form:
jiN
i
iN
jij yxau
0 0
jiN
iij
N
j
yxbv
0
1
0
where aij and bij are constant polynomial coefficients
A first degree ( N=1) bivariate polynomial defines those mapping functions that are exactly given by a general 3 x 3 affine transformation matrix .
210 ayaxau 210 bybxbv
(20)
Polynomial Warping
In the remote sensing, the polynomial coefficients are not given directly. Instead spatial information is supplied by means of control points, corresponding positions in the input and output images whose coordinates can be defined precisely. In these cases, the central task of the spatial transformation stage is to infer the coefficients of the polynomial that models the unknown distortion. Once these coefficients are known, Eq.20 is fully specified and it is used to map the observed (x,y) points onto the reference ( u,v) coordinate system. This is also called polynomial warping. It is practical to use polynomials up to the fifth order for the transformation function.
Least – Squares with Ordinary
Polynomials From Equation (20) with N=2, coefficients aij can be determined by minimizing
2
1
20211011000
2
11
2 ),(
M
kkkkkkk
M
kkk
M
k
k uyayxayaxaayxUE
This is achieved by determining the partial derivatives of E with respect to coefficients aij, and equating them to zero. For each coefficient aij, we have :
021
ij
kM
kk
ij da
d
da
dE
By considering the partial derivative of E with respect to all six coefficients, we obtain the system of linear equations.
Weighted Least Squares As you see the least-squares formulation is global error measure - distance between control points ( xk, yk) and approximation points ( x,y).
The least –squares method may be localized by introducing a weighting function Wk that represents the contribution of control point (xk,yk) on point (x,y)22 )()(
1
kk
kyyxx
W
where determines the influence of distant control points and approximating points
),(),(),(2
1
yxWuyxUyxE k
M
kkkk
Pseudoinverse SolutionLet a correspondence be established between M points in the observed and reference images. The spatial transformation that approximates this correspondence is chosen to be a polynomial of degree N. In two variables ( x and y) , such a polynomial has K coefficients where
2
)2)(1(1
0 0
NNK
N
i
N
j
For example, a second-degree approximation requires only six coefficients to be solved. In this case , N=2 and K=6.
02
20
11
01
10
00
22
3
2222
211
21111
2
1
1
....1
.....1
....1
..1
1
.
.
.
a
a
a
a
a
a
yxyxyx
x
yxyx
yxyxyx
u
u
u
MMMMMMM
In matrix form:
U=WA ; V=WB
WTU = WTWA A = (WTW)-1WTU ; B =(WTW)-1WTV
Warping Summary
• Reverse mapping is simpler to implement
• Different filters trade-off speed and aliasing/blurring
• Fun and creative warps are easy to implement
Image Morphing
• Animate transition between two images
Cross-Dissoving
• Blend imagesblend(i, j) = (1-t)src(i, j) + tdst(i, j)
(0 t 1)
Image Morphing
• Combines warping and cross-dissolving
Image Morphing• Warping step is the hard one
– Aim to align features in images
Image MorphingThere are two necessary components to morphing algorithms:
1. the user must have a mechanism to establish correspondence between the two images - perhaps as simple as silhouettes
2. from this correspondence, the algorithm must determine a dense pixel correspondence which is the warp algorithm
A common technique often used for facial morphing is named feature-based morphing. Important feature are chosen rather than a grid of points that must cover "unimportant" areas. Typical features might be ears, nose, and eyebrows. Lines are drawn in each image and are associated with each other. If there is only one pair of lines, the algorithm produces a purely local change. Therefore, a high spatial density is achieved in areas of interest.
Feature-based Morphing• Beier & Neeley use pairs of lines to specify
warp– Given p in dst image, where is p’ in source
image?
u is a fractionv is a length(in pixels)
Feature-based MorphingThe mapping function is simple. An inverse mapping function is used.
Feature-based MorphingIf more than one pair of lines is used, the transformations must be blended. Beier and Neeley of Pacific Data Images who developed the technique suggested the use of weight. (NOTE: Beier-92.pdf work).
Warping with One Line Pair
• What happens to the ‘F’?
Warping with Multiple Line Pairs
• Use weighted combination of points defined by each pair of corresponding lines
p’ is a weighted average
Weighting Effect of Each Line Pair
• To weight the contribution of each line pair
– where• Length[i] is the length of L[i]
• dist[i] is the distance from X to L[i]
• a, b, p are constants that control the warp
bp
idista
ilengthiweight
][
][][
Warping Pseudocode
WarpImage(Image, L’[], L[])begin foreach destination pixel p do psum = (0, 0) wsum = (0, 0) foreach line L[i] in destination do p’[i] = p transformed by (L[i], L’[i]) psum = psum + p’[i] * weight[i] wsum += weight[i] end p’ = psum / wsum Result(p) = Image(p’) endend
Morphing Pseudocode
GenerateAnimation(Image0, L0[], Image1, L1[])
begin
foreach intermediate frame time t do
for i = 1 to number of line pairs do
L[i] = line t-th of the way from L0[i] to L1[i]
end
Warp0 = WarpImage(Image0, L0, L)
Warp1 = WarpImage(Image1, L1, L)
foreach pixel p in FinalImage do
Result(p) = (1-t)Warp0 + tWarp1
end
end
Morphing Summary
• Specifying correspondences
• Warping
• Blending
Graphical Objects and Metamorphosis
MetamorphosisObject O1 Object O2
Geometry Alignment
Attribute Interpolation
Geometric
Data Set
Geometric
Data Set
Attributes Attributes
Warping Pipeline
Deform Adjust
Transformation of geometry Generation of attributes
Morphing Pipeline
Deform Adjust
Deform Adjust
Blend
Warping and Morphing
Warping•Single object
•Specification of original and deformed states
Morphing
•Two objects
•Specification of initial and final states
Warping and Morphing
http://www-2.cs.cmu.edu/~seitz/vmorph/vmorph.html
http://pen-web.com/rainyday/alexwarp/alexwarp.htm
http://www-graphics.stanford.edu/cgi-bin/alumni/tolis/personal/getpage.cgi?morph.html
http://www.css.tayloru.edu/~btoll/s99/424/res/model/morph/morph.html