Download presentation
Presentation is loading. Please wait.
Published byGerald Quinn Modified over 9 years ago
1
Chapter 14 Image Warping
2
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.
3
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.
4
HCT’s homogenous transforms include scaling, translation, rotation and shear which, collectively are special cases of affine transforms.
5
Translation
6
setting a translation matrix given:
7
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; }
8
scaling setting up to scale:
9
Simple Imlementation public void setScaling(double sx, double sy) { a[0][0] = sx; a[1][1] = sy; a[2][2] = 1; }
10
To Scale about any point
11
How does this simplify?
12
after working it out…
13
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(); }
14
Rotation
15
Euler’s identity
16
Where does rotation come from? Multiply a complex number, times another complex number…what do you get? Use Euler’s identity
17
Power Law of Exponents
18
How do we get Euler? X Y r SOHCAHTOA
19
Euler Rotation
20
Derivation of Rotation
21
matrix form.
22
2x2*2x1
23
Without Euler
24
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; }
25
Using Java2d AffineTransform atr = new AffineTransform(); atr.setToTranslation(x1, y1); atr.scale(sx, sy); atr.translate(-x1, -y1); Shape transformedShape = atr.createTransformedShape(gp);
26
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);
27
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 }
28
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)); }
29
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)); }
30
We can thank Euler’s identity!
31
Who was Euler? Leonhard Euler (April 15, 1707 - September 18, 1783) (pronounced "oiler"). Lived to be 76.April 151707September 181783 first to use the term "function" (defined by Leibniz - 1694) to describe an expression involving various arguments; ie: y = F(x).functionLeibniz1694expressionarguments A mathematical child prodigy.child prodigy professor of mathematics in Saint Petersburg, and Berlin,professorSaint PetersburgBerlin 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.blind
32
shear
33
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; }
34
The AffineFrame
35
rotation
36
scaling
37
shear
38
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 = 0) && (yp >= 0)) { rn[x][y] = r[xp][yp]; gn[x][y] = g[xp][yp]; bn[x][y] = b[xp][yp]; }
39
rotation
40
scale
41
shear in x
42
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);
43
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.
44
GUI Main Menu>AffineTransformMenu RunMenuItems: –Translate… –Rotate…, Scale…, Shear… –RotateAbout…, ScaleAbout…, ShearAbout… –RotateScaleShearAbout… –Use OK and Cancel RunButtons
45
fsdfsdsfd
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.