1 / 45

Chapter 14

Chapter 14. Image Warping. 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. Homogenious. All the same.

sunila
Download Presentation

Chapter 14

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • publicvoid 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 • publicvoid 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 • publicstaticvoid 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? SOHCAHTOA Y r X

  19. Euler Rotation

  20. Derivation of Rotation

  21. matrix form.

  22. 2x2*2x1

  23. Without Euler

  24. implementation of rotation in mat3 • publicvoid 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 thankEuler’s identity!

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

  32. shear

  33. setShear • publicvoid 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 < 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]; • } • }

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

More Related