Top Banner
1 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
28

Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

Apr 23, 2018

Download

Documents

dinhminh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

1

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

Page 2: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

2

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

Page 3: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

3

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

xy1

p

=uv1

p’

1 0 tx 0 1 ty 0 0 1

wxwyw

p

=wuwvw

p’

1 0 tx 0 1 ty 0 0 1

Homogenous coords are equivalent up to a scale factor

Page 4: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

4

Homogenous Coordinates• Transform works on scale (w)

* w

Dividing by the scale “w” puts you in Cartesian coords

w=1

Matrix Notation

a b c d e f 0 0 1

xy1

Affine p

=

uv1

p’

Page 5: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

5

Matrix notation of transforms

1 0 tx 0 1 ty 0 0 1

xy1

p

=uv1

p’

Sx 0 0 0 Sy 0 0 0 1

xy1

p

=uv1

p’

cosθ -sinθ 0 sinθ cosθ 0

0 0 1

xy1

p

=uv1

p’

1 Shx 0 Shy 1 00 0 1

xy1

p

=uv1

p’

Translation Scale

Rotation Shear

Concatenation

• You can concatenate several transforms into one matrix

A = R S Sh Trotate scale shear translate

Page 6: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

6

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

Page 7: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

7

Preserves

Source Destination

Source Destination

6 degrees of freedom

XY1

=uv1

a b cd e f 0 0 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”

1

23

1

23

Page 8: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

8

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 . .

Page 9: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

9

Example

Affine Transform Limitation

• Can map a triangle in source space• To a triangle in destination space

– (or two parallelograms)

Page 10: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

10

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

Page 11: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

11

Projective transform uses homogenous coords

xy1

=susvs

a b cd e f g h 1

u’ = u/sv’ = v/s

Maps us back to Cartesian space

Projective Transforms• Very common in computer graphics

– Texture mapping a 3D polygon – polygon has been projected onto a plane

Texture map3D perspectiveprojection

3D polygon

2D polygon

Page 12: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

12

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

A

B

CD

Source Space

A’ B’ C’ D’

Destination Space

|AC||AD||BC||BD|

|A’C’||A’D’||B’C’||B’D’|=

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

Cross Ratio

Page 13: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

13

Solving for a Projective Transform

xy1

=susvs

a b cd e f g h 1

8 degrees of freedom

We need 4 point correspondencesbetween source and destination image

su = ax + by + csv = dx + ey + fs = gx + hy + 1

source destination

Remember, with projective transform destination points are:

dest_u = su/sdest_v = sv/s

Solving for a Projective Transformsu = ax + by + csv = dx + ey + fs = gx + hy + 1

u =su = ax + by + cs gx + hy +1

v =sv = dx + ey + fs gx + hy +1

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

gxu + hyu + u = ax + by + c

u = ax + by + c – gxu – hyu

Page 14: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

14

8x8 System of Equations

v3h-y3v3-x3v31y3x3000

v2g-y2v2-x2v21y2x200

v1f-y1v1-x1v11y1x1000

u3d-y3u3-x3u30001y3x3

v0e-y0v0-x0v01y0x0000

u2c-y2u2-x2u20001y2x2

u1b-y1u1-x1u10001y1x1

u0a-y0u0-x0u00001y0x0

=

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

Page 15: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

15

Properties of Transforms

XXnon-uniform scale

Xcombination (w/ projection)

Xprojection

XXshear

XXXuniform scale

XXXXrotation

XXXXtranslation

Transformation

projectiveaffinesimilarityeuclidean

Properties of Transforms

XXXparallelism

XXXXcross ratio

XXXXincident

XXratio of lengths

XXangle

Xlength

Invariant

projectiveaffinesimilarityeuclidean

Page 16: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

16

Transforming an Image

Transforms and Images Coordinates

Y

xorigin

f(x,y)

Page 17: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

17

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

xorigin

f(x,y)

(-y value)

Page 18: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

18

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

Y

xorigin

New Image Dimensions

Page 19: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

19

The transformed image

Y

xorigin New Image Dimensions

Creating the “new” image

• Forward Mapping • Inverse Mapping• Sampling

Page 20: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

20

Mapping Pixels

(0,0) (0,N)

(0,M) (M,N)

Transform

(0,0) (0,N)

(0,M) (M,N)

1 2

3 4

1

2

3

4

DestinationImage

SourceImage

Forward Mapping

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

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

Page 21: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

21

black

Reverse Mapping

(0,0) (0,N)

(0,M) (M,N)

1 2

3 4

1

2

3

4

Reverse Mapping

1

23

4

1 2

3 4

[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 don’t have pixel to pixel

mapping

Page 22: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

22

Sampling the source

How do we sample the source to determinethe intensity for the destination?

How do we sample the source to determinethe intensity for the destination?

Sampling the source

Page 23: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

23

MappingSource

2 x 2 pixels

Option 1 : Pick the pixel nearest to our center.

MappingSource

2 x 2 pixels

Option 1 : Pick the pixel nearest to our center.

Small change results in big difference

Page 24: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

24

Try different samplingSource

2 x 2 pixelsWhat if we assign an intensityto each vertex and then average?

1 2

3 4

1 2 3 4

Pick the intensity which the vertexlies.

New Sample =

Sampling ExampleSource

2 x 2 pixelsMove the destination slightly.

1 2

3 4

1 2 3 4

Pick the intensity which the vertexlies.

New Sample =

Page 25: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

25

No DifferenceSource

2 x 2 pixels

1 2

3 4

Source2 x 2 pixels

1

2

3

4

Try different SamplingSource

2 x 2 pixels

1

23

4

What if we had more samples?

Page 26: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

26

Try different SamplingSource

2 x 2 pixels

1 2

34

What if we sampleda larger area?

Try different SamplingSource

2 x 2 pixelsHow should we sample?

Page 27: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

27

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

Bi-Cubic

Bi-linear Interpolation

Nearest Neighbor

Page 28: Geometric Image Transformations - Vis Centerryang/Teaching/cs635-2016spring/...Geometric Image Transformations Part One 2D Transformations • Spatial Coordinates – (x,y) are mapped

28

Common Sampling Approaches

Bi-Cubic

Bi-linear Interpolation

Nearest Neighbor

•What do these approaches mean?

•How can evaluate what they are doing?

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)

x