Вы находитесь на странице: 1из 28

Geometric Image

Transformations
Part One

2D Transformations
Spatial Coordinates
(x,y) are mapped to new coords (u,v)
pixels of source image -> pixels of destination
image
Types of 2D Transformations
Affine
Scales
Translations
Rotations
Shears
Projective
Projections
Homographies or Collineations

1
Scale and Translation
Scale
u = s_x * x
v = s_y * y

Translation
u = x + t_x
v = y + t_y

Rotation and Shears


Rotation
u = x*cos - y * sin
v = x*sin + y * cos

Shear
u = x + Sh_x * y
v = y + Sh_y * x

2
Shear
Consider Sh_x only (Sh_y=0)
u = x + Sh_x*y;
v = y;

Homogenous Coords
Translation is just an addition
We can make it a function of
multiplication by using homogenous
coords
Homogenous coords are
equivalent up to a scale factor

p p p p

u 1 0 tx x wu 1 0 tx wx
v = 0 1 ty y wv = 0 1 ty wy
1 0 0 1 1 w 0 0 1 w

3
Homogenous Coordinates
Transform works on scale (w)

*w

w=1

Dividing by the scale w puts you in Cartesian coords

Matrix Notation

p Affine p

u a b c x
v d e f y
1 = 0 0 1 1

4
Matrix notation of transforms
Translation Scale
p p p p

u 1 0 tx x u Sx 0 0 x
v = 0 1 ty y v = 0 Sy 0 y
1 0 0 1 1 1 0 0 1 1

Rotation Shear
p p p p
u cos -sin 0 x u 1 Shx 0 x
v = sin cos 0 y v = Shy 1 0 y
1 0 0 1 1 1 0 0 1 1

Concatenation
You can concatenate several
transforms into one matrix

A = R S Sh T
rotate scale shear translate

5
Affine Transformations
Affine is a linear mapping plus a translation:
A function f(x) is linear iff
f(x+y) = f(x) + f(y)
a*f(x) = f(a*x)

A function T(x) is Affine if there exists


a linear mapping L(x)
and a constant c
Such that: T(X) = L(x) + c (for all x)

Affine Transforms Properties


Preserves parallel lines
Preserves equispaced points along lines
equally spaced points on a line in the source
space
will produce equally spaced points on a line in
the destination space
(although the scale may be different)
Preserves incident
Points of intersection hold

6
Preserves

Source Destination

Source Destination

6 degrees of freedom
u a b c X
v = d e f Y
1 0 0 1 1

We can define an affine transform by specifying 3 point


correspondences
3 (x,y) from the source space
that map to 3 (u,v) in the destination space
3
2
3 2

1 1

7
Equations to solve for
Affine Transform
u1 = a*x1 + b*y1 + c
u2 = a*x2 + b*y2 + c
u3 = a*x3 + b*y3 + c

v1 = d*x1 + e*y1 + f
v2 = d*x2 + e*y2 + f
v3 = d*x3 + e*y3 + f

More commonly
You can build an Affine transform by
concatenating several transforms together
translate to the origin
Rotate by 20 degrees
translate back from the origin
scale by 5

GUI Interface tool that allows you to rotate,


translate, scale, etc . .

8
Example

Affine Transform Limitation


Can map a triangle in source space
To a triangle in destination space
(or two parallelograms)

9
Affine Transform Limitation
Can map a triangle in source space
To a triangle in destination space
(or two parallelograms)

What about a rectangle to a general


quadrilateral?

Projective Transform
Projective transform can transform
general quadrilaterals between source
and destination space

Does not preserve parallel lines, or


lengths

Does not preserve equispaced points

10
Projective transform uses
homogenous coords

su a b c x
sv = d e f y
s g h 1 1

u = u/s Maps us back to Cartesian space


v = v/s

Projective Transforms
Very common in computer graphics
Texture mapping a 3D polygon
polygon has been projected onto a plane

3D polygon

Texture map
3D perspective
projection

2D polygon

11
Projective Transform
Does not preserve length, equispacing

Does
Map lines to lines
Preserve incidents
Preserve cross ratio

Cross Ratio
Given 4 points on a line in source space and
destination space

D
C
B
A B C D
A

Source Space Destination Space

|AC||AD| |AC||AD|
|BC||BD|
= |BC||BD|
Cross Ratio

where |XY| is the Euclidean distance between point X and Y

12
Solving for a Projective Transform

8 degrees of freedom
su a b c x
sv = d e f y We need 4 point correspondences
s g h 1 1 between source and destination image

source destination

su = ax + by + c
Remember, with projective transform
sv = dx + ey + f
destination points are:
s = gx + hy + 1
dest_u = su/s
dest_v = sv/s

Solving for a Projective Transform


su = ax + by + c
sv = dx + ey + f
s = gx + hy + 1

u =su = ax + by + c (gx+hy+1)u = ax + by + c (. . . )
s gx + hy +1 gx + hy +1

gxu + hyu + u = ax + by + c
v =sv = dx + ey + f
s gx + hy +1
u = ax + by + c gxu hyu

13
8x8 System of Equations
x0 y0 1 0 0 0 -x0u0 -y0u0 a u0

x1 y1 1 0 0 0 -x1u1 -y1u1 b u1

x2 y2 1 0 0 0 -x2u2 -y2u2 c u2

d
= u3
x3 y3 1 0 0 0 -x3u3 -y3u3

0 0 0 x0 y0 1 -x0v0 -y0v0 e v0

0 0 0 x1 y1 1 -x1v1 -y1v1 f v1

0 0 x2 y2 1 -x2v2 -y2v2 g v2

0 0 0 x3 y3 1 -x3v3 -y3v3 h v3

Solve the system


Matrix is in form:
Ax = b
Solve for x
Gaussian elimination (LU decomposition)
QR decomposition
Entries of vector x are the
coefficients for the projective
transform

14
Properties of Transforms
euclidean similarity affine projective

Transformation

translation X X X X
rotation X X X X
uniform scale X X X
non-uniform scale X X
shear X X
projection X
combination (w/ projection) X

Properties of Transforms
euclidean similarity affine projective

Invariant

length X
angle X X
ratio of lengths X X
parallelism X X X
incident X X X X
cross ratio X X X X

15
Transforming an Image

Transforms and Images


Coordinates
origin
x

f(x,y)
Y

16
Image Coords vs. Cartesian Coords

Image Coords are generally defined


by raster alignment
Y [0,Height], X [0,Width]

Affine, projective transforms are


converted into Cartesian coords

Transforms and Images


Coordinates (-y value)

origin
x

f(x,y)
Y

17
Cartesian space to image space
From Cartesian space to Image Space
find (x_min, xmax)
find (y_min, ymax)

new size dimensions


w = x_max x_min
h = y_max y_min
create newImage size (w, h)

Translate transformed points, such that:


T * (x,y) = (u,v)
newImage( u + abs(x_min), v + abs(y_min) = I(x,y)

Converting to an Image

New Image Dimensions

origin
x

18
The transformed image

origin New Image Dimensions


x

Creating the new image


Forward Mapping
Inverse Mapping
Sampling

19
Mapping Pixels

(0,0) (0,N) Forward Mapping (0,0) (0,N)


1 2 2

4
1

3 4 3

(0,M) (M,N) (0,M) (M,N)

Source Destination
Image [u,v,s]T = A [x,y,1]T Image

Transform

Forward Mapping
Draw backs
Source pixels do not map directly to a
single pixel in the destination space

Possibility for holes in the destination


image

We can map the other direction

20
Reverse Mapping
Reverse Mapping

1 (0,0) (0,N)
1 2 2

1 2
4
3 2 1

3 4 3 3 4
(0,M) (M,N)
4
black

[x,y,s]T = A-1[u,v,1]T

Inverse Mapping
Advantages
We assign an intensity to each pixel in
the destination (no holes)
Affine/projective transforms have
inverses (not a problem)
just reverse direction of the point
correspondences
We still dont have pixel to pixel
mapping

21
Sampling the source

How do we sample the source to determine


the intensity for the destination?

Sampling the source

How do we sample the source to determine


the intensity for the destination?

22
Mapping
Source
2 x 2 pixels

Option 1 : Pick the pixel nearest to our center.

Mapping
Source
2 x 2 pixels Small change results in big difference

Option 1 : Pick the pixel nearest to our center.

23
Try different sampling
Source What if we assign an intensity
2 x 2 pixels to each vertex and then average?

1 2 Pick the intensity which the vertex


lies.

3 4

1 2 3 4

New Sample =

Sampling Example
Source Move the destination slightly.
2 x 2 pixels

1 Pick the intensity which the vertex


2
lies.

3 4
1 2 3 4

New Sample =

24
No Difference
Source Source
2 x 2 pixels 2 x 2 pixels
2
1 2
1 3

3 4
4

Try different Sampling


Source
2 x 2 pixels
What if we had more samples?
2
3
1

25
Try different Sampling
Source
2 x 2 pixels

1 2 What if we sampled
a larger area?

3
4

Try different Sampling


Source
2 x 2 pixels
How should we sample?

26
Common Sampling Approaches
Nearest Neighbor
1 Sample
Take closest pixel value

Bi-linear Interpolation
2x2 (4) Samples
Interpolate from these samples
Slower

Bi-Cubic
4x4 (8) samples
Construct a new sample using a non-linear interpolation
Slower

Common Sampling Approaches


Nearest Neighbor

Bi-linear Interpolation

Bi-Cubic

27
Common Sampling Approaches
What do these approaches mean?

How can evaluate what they are doing?

Nearest Neighbor

Bi-linear Interpolation

Bi-Cubic

Sampling and Signal Processing


Proper sampling is a classic reconstruction problem
Given a continuous signal f(x)
How do you take discrete samples such that you can properly
reconstruct the signal f(x) from the samples?

f(x)

28

Вам также может понравиться