IMAGE PROCESSING: GEOMETRIC OPERATIONSreeves.csc.ncsu.edu/.../image-processing-geometric.pdf ·...

Post on 16-Oct-2020

5 views 0 download

transcript

IMAGE PROCESSING: GEOMETRIC OPERATIONS

N. C. State University

CSC557 ♦ Multimedia Computing and Networking

Fall 2001

Lecture # 12

2Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Geometric Operations

• Affine transformations

— rotation

— translation

— scaling

• Other transformations— mirroring

— perspective

— warping

3Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Forward Vs. Inverse Mapping

• Output pixels Q and input pixels P— with dimensions MQ x NQ and MP x NP

• Pixel (0,0) is the upper-left-hand corner

4Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Mapping (cont’d)

• Forward mapping: to what output pixel does an input pixel map?— problem: potential for "holes”

— ex: output pixel i,j may not have any input pixel mapped to it

• Inverse mapping: from what input pixel (P) does an output pixel (Q) map?— problem: non-integer input pixel boundaries (interpolation

needed)

— ex: output pixel i,j maps from input pixel at position 20.6,100.8

5Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Forward Vs. Inverse Pixel Mapping

(0,0)

(0,1)

(1,0)

(1,1)

(0,0)

(0,2)

(2,0)

(2,2)

(0,0)

(0,1)

(1,0)

(1,1)

(0,0)

(0,2)

(2,0)

(0,1)

(0,3)

(1,0) (3,0)

(2,1)(1,1) (3,1)

(2,2)(1,2) (3,2)

(2,3)(1,3) (3,3)

???

? ?

?

?

?

6Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)Pixel Interpolation (Dealing with Fractional Pixel Boundaries)

• Nearest-neighbor interpolation— e.g., just use the value from the nearest pixel

• Bi-linear interpolation (see next slide)

• Higher-order interpolation (not covering)

7Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Interpolation Example

ORIGINAL INPUTBi-linear Interpolation

Bi-cubic Interpolation Nearest Neighbor Interpolation

8Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Bilinear Interpolation Algorithm

1. Given nwpixel, nepixel, swpixel, sepixel, inx, iny; example: nwpixel=(2,5), nepixel=(3,5) swpixel=(2,6), sepixel=(3,6)

2. ewweight = inx - inx ; example: 2.7 – 2 = .7

3. nsweight = iny - iny ; example: 5.2 – 5 = .2

4. northval = nwpixel + ewweight*(nepixel-nwpixel)5. southval = swpixel + ewweight*(sepixel-swpixel)

6. Output pixel value = northval + nsweight*(southval-northval)

9Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Bilinear Interpolation Example

(northval)(southval)

(output pixel value)

10Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Translation (Move)

• Move a portion of the image to a new location— fill “vacated” region with solid color?

• q(x, y) = p(x - ∆x, y - ∆y)— use bilinear interpolation when ∆x,∆y are not integers

— ∆x > 0 means move to the right, ∆y >0 moves move down

11Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Translation (cont’d)

• If ∆x and ∆y are allowed to vary, results in a distortion effect— The set of ∆x and ∆y values are expressed in a translation map

(same size as image)

• When translation is combined with mixing, the result is a smearing effect

12Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Translation / Distortion Examples

Original

Windy Ripple

Frosted Glass

13Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Scaling (Resizing)

• Scale factors α and β— Mq = Mp*α, Nq = NP*β

— to preserve aspect ratio, make α = β

• q(x,y) = p(x/α, y/β)

14Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

RESIZING/SCALING EXAMPLE

15Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Rotation

• Given— rotation angle φ (measured as angle from dest source)

— center of rotation pixel (xcenter, ycenter)

• Notes— If outside the input range, fill with solid color

— May need to adjust image size also (MQ and NQ)

— If φ is a multiple of 90º, just transpose the pixel values instead

Xsource = xcenter + (x-xcenter)*cos(φ) + (y-ycenter)*sin(φ)Ysource = ycenter + (y-ycenter)*cos(φ) - (x-xcenter)*sin(φ)q(x,y) = p(xsource, ysource) ; interpolation may be needed

16Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Rotation Example

xcenter = 80, ycenter = 130, φ = 30°

pixel to be mapped is q(x,y) = q(50,170)

xsource = 80 + (50-80) * cos(30°) + (170-130) * sin(30°) = 80 – 26.0 + 20.0 = 74.0

ysource = 130 + (170-130) * cos(30°) – (50-80) * sin(30°) = 130 + 34.64 + 15 = 179.64

0,0

Center = (80,130)

Input p(xsource,ysource) = (74.0,179.64)

Output q(50,170) 30°

17Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Rotation Example

18Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Mirroring (Flipping)

• Simple exchange of pixels located symmetrically about X median value or Y median value

19Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Mirroring Example

20Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Warp Example

21Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Warping

22Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Warp (Distort) Example

23Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Morphing

• Movie showing transformation from one object or shape, into another

• Combination of warping and fading

• Fading may be non-linear, or applied selectively to objects

24Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Morphing Example

25Copyright 2001 Douglas S. Reeves (http://reeves.csc.ncsu.edu)

Sources Of Info

• [Crane97] A Simplified Approach to Image Processing— Chapter 4

— Part of Chapter 8

• [Watkins93] Modern Image Processing: Warping, Morphing, and Classical Techniques