lecture 25: affine transformations and barycentric coordinates€¦ · lecture 25: a ne...
TRANSCRIPT
![Page 1: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/1.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Lecture 25: Affine Transformations andBarycentric Coordinates
ECE 417: Multimedia Signal ProcessingMark Hasegawa-Johnson
University of Illinois
11/28/2017
![Page 2: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/2.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
1 Moving Points Around
2 Affine Transformations
3 Barycentric Coordinates
4 Conclusion
![Page 3: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/3.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Outline
1 Moving Points Around
2 Affine Transformations
3 Barycentric Coordinates
4 Conclusion
![Page 4: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/4.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Moving Points Around
First, let’s suppose that somebody has given you a bunch of points:
![Page 5: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/5.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
. . . and let’ssuppose youwant to movethem around,to create newimages. . .
![Page 6: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/6.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Moving One Point
Your goal is to synthesize an output image, I (x , y), whereI (x , y) might be intensity, or RGB vector, or whatever.
What you have available is:
An input image, I0(u, v)Knowledge that the input point at (u, v) has been moved tothe output point at (x , y).
Therefore:I (x , y) = I0(u, v)
![Page 7: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/7.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Non-Integer Input Points
Usually, we can’t make both (x , y) and (u, v) to be integers.
The easiest thing is to make (x , y) be integers. In otherwords, create the output image as “for x=1:M, for y=1:N,I(x,y) = I0(u,v);”
In that case, (u, v) are not integers. So what is I0(u, v)?
![Page 8: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/8.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Non-Integer Input Points
Suppose that p = int(u), and q = int(v). Then:
Piece-wise constant interpolation:
I (x , y) = I0(p, q)
Bilinear interpolation:
I (x , y) =0∑
m=−1
0∑n=−1
h[m, n]I0(p −m, q − n)
where∑
m
∑n w [m, n] = 1.
General interpolation (e.g., spline, sinc):
I (x , y) =∞∑
m=−∞
∞∑n=−∞
h[m, n]I0(p −m, q − n)
![Page 9: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/9.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Outline
1 Moving Points Around
2 Affine Transformations
3 Barycentric Coordinates
4 Conclusion
![Page 10: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/10.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
How do we find (u, v)?
Now the question: how do we find (u, v)?We’re going to assume that this is a piece-wise affinetransformation.[
uv
]=
[ak bkdk ek
] [xy
]+
[ckfk
]where ak etc. depend on which region (x , y) is in.
![Page 11: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/11.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
How do we find (u, v)?
Piece-wise affine means:[uv
]=
[ak bkdk ek
] [xy
]+
[ckfk
]A much easier to write this is by using extended-vector notation: u
v1
=
ak bk ckdk ek fk0 0 1
xy1
It’s convenient to define ~u = [u, v , 1]T , and ~x = [x , y , 1]T , so thatfor any ~x in the kth region of the image,
~u = Ak~x
![Page 12: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/12.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Affine Transforms
Affine transforms can do the following things:
Shift the input (to left, right, up, down)
Reflect the input (through any line of reflection)
Scale the input (separately in x and y directions)
Rotate the input
Skew the input
![Page 13: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/13.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Example: Reflection
uv1
=
−1 0 00 1 00 0 1
xy1
![Page 14: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/14.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Example: Scale
uv1
=
2 0 00 1 00 0 1
xy1
![Page 15: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/15.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Example: Rotation
uv1
=
cos θ sin θ 0− sin θ cos θ 0
0 0 1
xy1
![Page 16: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/16.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Example: Shear
uv1
=
1 0.5 00 1 00 0 1
xy1
![Page 17: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/17.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
![Page 18: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/18.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Outline
1 Moving Points Around
2 Affine Transformations
3 Barycentric Coordinates
4 Conclusion
![Page 19: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/19.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
How do we find the parameters?
OK, so somebody’s given us a lot of points, arranged like thisin little triangles.
We know that we want to scale, shift, rotate, and shear eachtriangle separately with its own 6-parameter affine transformmatrix Ak .
How do we find Ak for each of the triangles?
![Page 20: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/20.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Barycentric Coordinates
Barycentric coordinates turns theproblem on its head. Suppose ~x is in atriangle with corners at ~x1, ~x2, and ~x3.That means that
~x = λ1~x1 + λ2~x2 + λ3~x3
where0 ≤ λ1, λ2, λ3 ≤ 1
andλ1 + λ2 + λ3 = 1
![Page 21: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/21.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Barycentric Coordinates
Suppose that all three of the corners are transformed by someaffine transform A, thus
~u1 = A~x1, ~u2 = A~x2, ~u3 = A~x3
Then ifIf: ~x = λ1~x1 + λ2~x2 + λ3~x3
Then:
~u = A~x
= λ1A~x1 + λ2A~x2 + λ3A~x3
= λ1~u1 + λ2~u2 + λ3~u3
In other words, once we know the λ’s, we no longer need to find A.We only need to know where the corners of the triangle havemoved.
![Page 22: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/22.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
How to find Barycentric Coordinates
But how do you find λ1, λ2, and λ3?
~x = λ1~x1 + λ2~x2 + λ3~x3 = [~x1,~x2,~x3]
λ1
λ2
λ3
Write this as:
~x = X~λ
Therefore~λ = X−1~x
This always works: the matrix X is always invertible, unless allthree of the points ~x1, ~x2, and ~x3 are on a straight line.
![Page 23: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/23.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
How do you find out which triangle the point is in?
Suppose we have K different triangles, each of which ischaracterized by a 3 × 3 matrix of its corners
Xk = [~x1,k ,~x2,k ,~x3,k ]
where ~xm,k is the mth corner of the kth triangle.
Notice that, for any point ~x , for ANY triangle Xk , we can find
λ = X−1k ~x
However, the coefficients λ1, λ2, and λ3 will all be between 0and 1 if and only if the point ~x is inside the triangle Xk .Otherwise, some of the λ’s must be negative.
![Page 24: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/24.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Outline
1 Moving Points Around
2 Affine Transformations
3 Barycentric Coordinates
4 Conclusion
![Page 25: Lecture 25: Affine Transformations and Barycentric Coordinates€¦ · Lecture 25: A ne Transformations and Barycentric Coordinates ECE 417: Multimedia Signal Processing Mark Hasegawa-Johnson](https://reader033.vdocuments.site/reader033/viewer/2022042809/5f8d2813dcc99343f576f808/html5/thumbnails/25.jpg)
Moving Points Around Affine Transformations Barycentric Coordinates Conclusion
Conclusion: The Whole Method
To construct the animated output image frame I (x , y), we do thefollowing things:
First, for each of the reference triangles Uk in the input imageI0(u, v), decide where that triangle should move to. Call thenew triangle location Xk .
Second, for each output pixel I (x , y):
For each of the triangles, find ~λ = X−1k ~x .
Choose the triangle for which all of the λ coefficients are0 ≤ λ ≤ 1.Find ~u = Uk
~λ.Estimate I0(u, v) using piece-wise constant interpolation, orbilinear interpolation, or spline or sinc interpolation.Set I (x , y) = I0(u, v).