+ All Categories
Home > Documents > Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e....

Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e....

Date post: 17-Jan-2018
Category:
Upload: gerald-quinn
View: 234 times
Download: 0 times
Share this document with a friend
Description:
Homogenious All the same. Homogenious point processing means that all the points are processed the same. Homogenious coordinate transforms means that all coordinates are transformed the same way.
45
Chapter 14 Image Warping
Transcript
Page 1: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Chapter 14

Image Warping

Page 2: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Why do image warping?

• Looks cool!• Can correct for optical distortion (i.e.

keystoning).• Remote Sensing (matching together

multiple images).• Entertainment value (morphing)• Special Effect• Looking for lost people.

Page 3: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Homogenious

• All the same.• Homogenious point processing means that

all the points are processed the same.• Homogenious coordinate transforms means

that all coordinates are transformed the same way.

Page 4: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

HCT’s

• homogenous transforms include scaling, translation, rotation and shear which, collectively are special cases of affine transforms.

Page 5: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Translation

11001001

1''

yx

tt

yx

y

x

x' x tx

y' y ty

Page 6: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

setting a translation matrix

• given:

222120

121110

020100

aaaaaaaaa

A

Page 7: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

setting up xlation

• public void setTranslation(double tx, double ty) {

• a[0][0] = 1;• a[1][1] = 1;• a[2][2] = 1;• a[0][2] = tx;• a[1][2] = ty;• }

Page 8: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

scaling

• setting up to scale:

11000000

1''

yx

ss

yx

y

x

x' sx xy'syy

Page 9: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Simple Imlementation

• public void setScaling(double sx, double sy) {

• a[0][0] = sx;• a[1][1] = sy;• a[2][2] = 1;• }

Page 10: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

To Scale about any point

x 'y '1

1 0 tx

0 1 ty

0 0 1

sx 0 00 sy 00 0 1

1 0 tx

0 1 ty

0 0 1

xy1

Page 11: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

How does this simplify?

x 'y '1

sx 0 tx sxtx

0 sy ty syty

0 0 1

xy1

Page 12: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

after working it out…

x 'sx x tx sxtx sx(x tx) tx

y 'sy y ty syty sy(y ty) ty

Page 13: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Concating the matrix• public static void main(String args[]) {• Mat3 tr1 = new Mat3();• Mat3 tr2 = new Mat3();• Mat3 sc = new Mat3();• Mat3 at ;• tr1.setTranslation(1,1);• sc.setScale(2,2);• tr2.setTranslation(-1,-1);• at = tr1.multiply(sc);• at = at.multiply(tr2);• at.print();• }

Page 14: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Rotation

x 'y '1

cos sin 0sin cos 0

0 0 1

xy1

Page 15: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Euler’s identity

e i cos i sin

)21(12 iii eee

Page 16: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Where does rotation come from?

• Multiply a complex number, times another complex number…what do you get?

• Use

Euler’s identity

Page 17: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Power Law of Exponents

a b a be e e

Page 18: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

How do we get Euler?

cos sinire r ri

cosr X

Y

r sinr

SOHCAHTOA

Page 19: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Euler Rotation

2sin112cos2sin12cos1

'

2sin2cos22)2112(2121'

)22)(11('

)21(12

xyyx

p

iiyxyxyxiyyxxp

iyxiyxpeee iii

Page 20: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Derivation of Rotation

1 2 1 2( )1 1 2 2

1 2 1 2 1 2 1 2

1 2 1 2 1 2 1 2

2 2 1

2 2 1

cos sin

( )(cos sin )cos sin cos sincos sin ( sin cos )

' cos sin 0' sin cos 0

1 0 0 1 1

i

i i i

e i x iy

e e e x iy ix x i iy iy ix y i x y

x xy y

2 2

2 2

' cos sin' sin cos

x x yy x y

Page 21: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

matrix form.

x 'y '1

cos sin 0sin cos 0

0 0 1

xy1

Page 22: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

2x2*2x1

1 2 1 21 2

1 2 2 1

2 2 1

2 2 1

cos sinsin cos

cos sinsin cos

x yp p

x y

xy

Page 23: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Without Euler

1 1 1

2 2 2

1 2 1 21 2 1 1 2 2

1 2 2 1

2 2 2 2

1 2 1 21 2

1 2 2 1

(cos ,sin ) ( , )cos sinsin cos

p x iyp x iy

x x y yp p x iy x iy

x y x yby

x yx y

p px y

Page 24: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

implementation of rotation in mat3

• public void setRotation(double theta) {• theta = theta * Math.PI/180;• double cas = Math.cos(theta);• double sas = Math.sin(theta);• a[0][0] = cas;• a[1][1] = cas;• a[0][1] = -sas;• a[1][0] = sas;• }

Page 25: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Using Java2d

• AffineTransform atr = new AffineTransform();

• atr.setToTranslation(x1, y1);• atr.scale(sx, sy);• atr.translate(-x1, -y1);• Shape transformedShape =

atr.createTransformedShape(gp);

Page 26: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Using mat3 to scale and rotate• Mat3 tr1 = new Mat3();• Mat3 tr2 = new Mat3();• Mat3 rt = new Mat3();• Mat3 sc = new Mat3();

• tr1.setTranslation(getCentroidX(), getCentroidY());• sc.setScale(1, 1);• rt.setRotation(0);• tr2.setTranslation(-getCentroidX(), -getCentroidY());• at = tr1.multiply(rt);• at = at.multiply(sc);• at = at.multiply(tr2);

Page 27: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

J2d, lets rotation occur about any point

• public void drawRotateGraphics(Graphics g) {• final int xc = getCentroidX();• final int yc = getCentroidY();• Graphics2D g2d = (Graphics2D) g;• AffineTransform saveAt = g2d.getTransform();• for (float theta = 0; theta <= 360; theta += 10f) {• g2d.setTransform(AffineTransform.getRotateInstance(• theta * PI_ON_180,• xc, yc));• g2d.draw(p);• }• g2d.setTransform(saveAt);• // This leaves the g2d back on 0 degrees of rotation• }

Page 28: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Rotate with a new shape• public void drawTransformedShape(Graphics g) {• final int xc = getCentroidX();• final int yc = getCentroidY();• Graphics2D g2d = (Graphics2D) g;• for (float theta = 0; theta <= 360; theta += 10f) {• final AffineTransform at =

AffineTransform.getRotateInstance(theta *• PI_ON_180,• xc, yc);• g2d.draw(at.createTransformedShape(p));• }

Page 29: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Or use Mat3 to Draw• public void drawMat3(Graphics g) {• final int xc = getCentroidX();• final int yc = getCentroidY();• tr1.setTranslation(xc, yc);• tr2.setTranslation(-xc, -getCentroidY());• for (float theta = 0; theta < 360; theta += 10f) {

• rt.setRotation(theta);• at = tr1.multiply(rt);• at = at.multiply(tr2);• drawPolygon(g, at.transform(p));• }• }

Page 30: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

We can thankEuler’s identity!

e i cos i sin

)21(12 iii eee

Page 31: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Who was Euler?

• Leonhard Euler (April 15, 1707 - September 18, 1783) (pronounced "oiler"). Lived to be 76.

• first to use the term "function" (defined by Leibniz - 1694) to describe an expression involving various arguments; ie: y = F(x).

• A mathematical child prodigy. • professor of mathematics in Saint Petersburg, and Berlin, • Most prolific mathematician of all time, 75 volumes. • blind for the last seventeen years of his life, during which

time he produced almost half of his total output.

Page 32: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

shear

x 'y '1

1 shx 0shy 1 00 0 1

xy1

Page 33: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

setShear

• public void setShear(double shx, double shy) {• a[0][0] = 1;• a[1][1] = 1;• a[2][2] = 1;• a[0][1] = shx;• a[1][0] = shy;• }

Page 34: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

The AffineFrame

Page 35: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

rotation

Page 36: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

scaling

Page 37: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

shear

Page 38: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

destination scanning• transform = transform.invert();• for (int x = 0; x < w; x++)• for (int y=0; y < h; y++) {• p=transform.multiply(x,y);• xp = (int) p[0];• yp = (int) p[1];• if ((xp < w) && (yp < h) && (xp >= 0) && (yp >= 0)) {• rn[x][y] = r[xp][yp];• gn[x][y] = g[xp][yp];• bn[x][y] = b[xp][yp];• }• }

Page 39: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

rotation

Page 40: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

scale

Page 41: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

shear in x

Page 42: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

Create the combinations

– Image scaleAbout(image, tx, ty,sx,sy);– Image rotateAbout(image, tx, ty, theta);– Image shearAbout(image, tx, ty, shx, shy);– Image rotateShearScale(image, theta, shx,shy,

sx, sy);Image rotateShearScaleAbout(image, tx,ty,

theta, shx,shy, sx, sy);

Page 43: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

UseMatrix concatenation

• Use matrix concatenation for everything.• Only a single 3x3 matrix will result when

we are done.• Use the AffineTransform Class, as

described on pp. 135 of the handout.

Page 44: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

GUI

• Main Menu>AffineTransformMenu• RunMenuItems:

– Translate…– Rotate…, Scale…, Shear…– RotateAbout…, ScaleAbout…, ShearAbout…– RotateScaleShearAbout…– Use OK and Cancel RunButtons

Page 45: Chapter 14 Image Warping. Why do image warping? Looks cool! Can correct for optical distortion (i.e. keystoning). Remote Sensing (matching together multiple.

fsdfsdsfd


Recommended