34
Sun-Jeong Kim Image Processing 5 th ~6 th Weeks, 2008 Computer Graphics 2 Contents Quantization Classical halftoning Random dither Ordered dither Error diffusion dither Pixel operations Adding random noise Adding luminance Adding contrast Adding saturation Filtering Blurring Edge-detection Warping Scaling Rotation Warping Combining Compositing Morphing

Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Sun-Jeong Kim

Image Processing

5th~6th Weeks, 2008

Computer Graphics2

Contents

QuantizationClassical halftoningRandom ditherOrdered ditherError diffusion dither

Pixel operationsAdding random noiseAdding luminanceAdding contrastAdding saturation

FilteringBlurringEdge-detection

WarpingScalingRotationWarping

CombiningCompositingMorphing

Page 2: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics3

What is an Image?

An image is a 2D rectilinear array of pixels

Continuous image Digital image

Computer Graphics4

Quantization

Artifact due to limited intensity resolutionFrame buffers have limited number of bits per pixel

Physical devices have limited dynamic range

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

255 150 75 0

Blue channel

Green channel

Red channel

Page 3: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics5

Uniform Quantization

( ) ( )( )5.0,trunc, += yxIyxP

I(x, y)

P(x, y)2 bits per pixel

Computer Graphics6

Uniform Quantization

Image with decreasing bits per pixel:

8 bits 4 bits 2 bits 1 bit

Notice contouring

Page 4: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics7

Reducing Effects of Quantization

Halftoning and DitheringTrading spatial resolution for intensity resolution

Reducing visual artifacts due to quantization

HalftoningClassical halftoning

DitheringRandom dither

Ordered dither

Error diffusion dither

Computer Graphics8

Classical Halftoning (1)

Using dots of varying size to representation intensities

Area of dots proportional to intensity in image

I(x, y) P(x, y)

Page 5: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics9

Classical Halftoning (2)

Newspaper image

From New York Times 9/21/99

Computer Graphics10

Halftone Patterns (1)

Using cluster of pixels to represent intensityTrade spatial resolution for intensity resolution

Page 6: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics11

Halftone Patterns (2)

How many intensities in a n x n cluster?

Computer Graphics12

Dithering

Distributing errors among pixelsExploiting spatial integration in our eye

Displaying greater range of perceptible intensities

Original(8 bits)

UniformQuantization

(1 bit)

Floyd-SteinbergDither(1 bit)

Page 7: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics13

Random Dither (1)

Randomizing quantization errorsErrors appear as noise

( ) ( ) ( )( )5.0,noise,trunc, ++= yxyxIyxP

Computer Graphics14

Random Dither (2)

Original(8 bits)

UniformQuantization

(1 bit)

RandomDither(1 bit)

Page 8: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics15

Ordered Dither (1)

Pseudo-random quantization errorsMatrix stores pattern of thresholds

⎥⎦

⎤⎢⎣

⎡=

20

132D

j = (x mod n) + 1i = (y mod n) + 1e = I(x, y) – Dn(i, j)if( e > 0 )

P(x, y) = ceil(I(x, y)) turn on the pixelelse

P(x, y) = floor(I(x, y)) turn off the pixel

Computer Graphics16

Ordered Dither (2)

Original(8 bits)

UniformQuantization

(1 bit)

OrderedDither(1 bit)

Page 9: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics17

Error Diffusion Dither (1)

Spread quantization error over neighbor pixelsError dispersed to pixels right and below

α

α + β + γ + δ = 1.0

δγ

β

Computer Graphics18

Error Diffusion Dither (2)

Original(8 bits)

OrderedDither(1 bit)

RandomDither(1 bit)

Floyd-SteinbergDither(1 bit)

Page 10: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics19

Contents

QuantizationClassical halftoningRandom ditherOrdered ditherError diffusion dither

Pixel operationsAdding random noiseAdding luminanceAdding contrastAdding saturation

FilteringBlurringEdge-detection

WarpingScalingRotationWarping

CombiningCompositingMorphing

Computer Graphics20

Adjusting Brightness

Simplifying scale pixel componentsMust clamp to range (e.g., 0 to 255)

Original Brighter

Page 11: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics21

Adjusting Contrast

Computing mean luminance L for all pixelsLuminance = 0.30*r + 0.59*g + 0.11*b

Scaling deviation from L for each pixel componentMust clamp to range (e.g. 0 to 255)

Original More contrast

L

Computer Graphics22

Contents

QuantizationClassical halftoningRandom ditherOrdered ditherError diffusion dither

Pixel operationsAdding random noiseAdding luminanceAdding contrastAdding saturation

FilteringBlurringEdge-detection

WarpingScalingRotationWarping

CombiningCompositingMorphing

Page 12: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics23

Adjusting Blurriness

Convolving with a filter whose entries sum to oneEach pixel becomes a weighted average of its neighbors

Original Blur

⎥⎥⎥⎥

⎢⎢⎢⎢

=

161

162

161

162

164

162

161

162

161

Filter

Computer Graphics24

Edge Detection

Convolving with a filter that finds differences between neighbor pixels

Original Edge Detection

⎥⎥⎥

⎢⎢⎢

−−−−−−−−

=111

181

111

Filter

Page 13: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics25

Contents

QuantizationClassical halftoningRandom ditherOrdered ditherError diffusion dither

Pixel operationsAdding random noiseAdding luminanceAdding contrastAdding saturation

FilteringBlurringEdge-detection

WarpingScalingRotationWarping

CombiningCompositingMorphing

Computer Graphics26

Image Warping

Moving pixels of imageStep1: mapping

Step2: resampling

Warp

Source Image Destination Image

Page 14: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics27

Mapping

Defining transformationDescribing the destination (x, y) for every location (u, v) in the source (or vice-versa, if invertible)

u

v

x

y

Computer Graphics28

Example Mappings (1)

Scaling by factor :x = factor * u

y = factor * v

Scale0.8

u

v

x

y

Page 15: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics29

Example Mappings (2)

Rotating by θ degrees:x = u cosθ – v sinθy = u sinθ + v cosθ

u

v

Rotate30

x

y

Computer Graphics30

Example Mappings (3)

Shearing in X by factor :x = u + factor * v

y = v

Shearing in Y by factor :x = u

y = v + factor * u

Shear X1.3

u

v

x

y

Shear Y1.3

u

v

x

y

Page 16: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics31

Other Mappings

Any function of u and v :x = fx(u, v)

y = fy(u, v)

Fish-eye Swirl Rain

Computer Graphics32

Image Warping Implementation (1)

Forward mapping:for(int u=0; u<umax; u++) {

for(int v=0; v<vmax; v++) {float x = fx(u,v);float y = fy(u,v);dst(x,y) = src(u,v);

}}

Source Image Destination Image

(u, v)(x, y)f

Page 17: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics33

Forwarding Mapping

Iterating over source image

Rotate-30

u

v

x

y

Computer Graphics34

Forwarding Mapping – NOT

Iterating over source image

Rotate-30

u

v

x

y

Many source pixels can map to same destination pixel

Some destination pixels may not be covered

Page 18: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics35

Image Warping Implementation (2)

Reverse mapping:for(int x=0; x<xmax; x++) {

for(int y=0; y<ymax; y++) {float u = fx

-1(x,y);float v = fy

-1(x,y);dst(x,y) = src(u,v);

}}

Source Image Destination Image

(u, v)(x, y)f

Computer Graphics36

Reverse Mapping

Iterating over destination imageMust resample source

May oversample, but much simpler!

Rotate-30

u

v

x

y

Page 19: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics37

Resampling

Evaluating source image at arbitrary (u, v)

(u, v) does not usually have integer coordinates

Source Image Destination Image

(u, v)(x, y)

Computer Graphics38

Point Sampling

Taking value at closest pixelint iu = trunc(u+0.5);

int iv = trunc(v+0.5);

dst(x, y) = src(iu, iv);

This method is simple, but it causes aliasing

Rotate-30

Scale0.5

u

v

x

y

Page 20: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics39

Triangle Filtering

Bilinearly interpolating four closest pixelsa = linear interpolation of src(u1, v2) and src(u2, v2)

b = linear interpolation of src(u1, v1) and src(u2, v1)

dst(x, y) = linear interpolation of “a” and “b”

(u1, v2)

(u1, v1)

(u2, v2)

(u2, v1)

a

b

(u, v)

Computer Graphics40

Gaussian Filtering

Computing weighted sum of pixel neighborhoodWeights are normalized values of Gaussian function

(u, v)

Page 21: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics41

Filtering Methods Comparison

Trade-offsAliasing versus blurring

Computation speed

Point Bilinear Gaussian

Computer Graphics42

Image Warping Implementation (3)

Reverse mappingfor(int x=0; x<xmax; x++) {

for(int y=0; y<ymax; y++) {float u = fx

-1(x,y);float v = fy

-1(x,y);dst(x,y) = resample_src(u,v,w);

}}

Source Image Destination Image

(u, v)(x, y)f

w

Page 22: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics43

Example: Scaling

Scale (src, dst, sx, sy) :float w ≈ max(1/sx, 1/sy)for(int x=0; x<xmax; x++) {

for(int y=0; y<ymax; y++) {float u = x/sx ;float v = y/sy;dst(x,y) = resample_src(u,v,w);

}}

Scale0.5

u

v

x

y

(u, v)

(x, y)

Computer Graphics44

Example: Rotation

Rotate (src, dst, theta)for(int x=0; x<xmax; x++) {

for(int y=0; y<ymax; y++) {float u = x*cos(-θ)-y*sin(-θ)float v = x*sin(-θ)+y*cos(-θ)dst(x,y) = resample_src(u,v,w);

}}

u

v

Rotate30

x

y

(u, v) (x, y)

Page 23: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics45

Example: Fun

Swirl (src, dst, theta)for(int x=0; x<xmax; x++) {

for(int y=0; y<ymax; y++) {float u = rot(dist(x,xcenter)*θ)float v = rot(dist(y,ycenter)*θ)dst(x,y) = resample_src(u,v,w);

}}

u

v

Swirl45

x

y(u, v) (x, y)

Computer Graphics46

Contents

QuantizationClassical halftoningRandom ditherOrdered ditherError diffusion dither

Pixel operationsAdding random noiseAdding luminanceAdding contrastAdding saturation

FilteringBlurringEdge-detection

WarpingScalingRotationWarping

CombiningCompositingMorphing

Page 24: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics47

Image Compositing

Separating an image into “elements”Rendering independently

Compositing together

ApplicationsCel animation

Chroma-keying

Blue-screen matting

Dobkin meets Elvis

Computer Graphics48

Blue-Screen Matting

Compositing foreground and background images

Creating background image

Creating foreground image with blue background

Inserting non-blue foreground pixels into background

Page 25: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics49

Alpha Channel

Encoding pixel coverage informationα = 0 : no coverage (or transparent)

α = 1 : full coverage (or opaque)

0 < α < 1 : partial coverage (or semi-transparent)

Example : α = 0.3

Partial coverage Semi-Transparent

or

Computer Graphics50

Compositing with Alpha

Controlling the linear interpolation of foreground and background pixels when elements are composited

α = 0

0< α < 1

α = 1

Page 26: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics51

Image Composition Example

Jurassic Park

Computer Graphics52

Image Morphing

Animating transition between two images

Page 27: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics53

Cross-Dissolving

Blending image with “over” operatorAlpha of bottom image is 1.0

Alpha of top image varies from 0.0 to 1.0

( ) ( ) ( ) ( ) ( )10 ,dst ,src1,blend ≤≤+−= tjitjitji

Computer Graphics54

Image Morphing

Combineing warping and cross-dissolving

Page 28: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics55

Image Morphing

The warping step is the hard oneAiming to align feature in images

How specify mapping for the

warp?

Computer Graphics56

Feature Based Warping

Beier & Neeley use pairs of lines to specify warpGiven p in destination image, where is p’ in source image?

Beier & NeeleySIGGRAPH 92

Page 29: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics57

Warping with One Line Pair (1)

What happens to the “F”?

Translation

Computer Graphics58

Warping with One Line Pair (2)

What happens to the “F”?

Scale

Page 30: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics59

Warping with One Line Pair (3)

What happens to the “F”?

Rotation

Computer Graphics60

Warping with One Line Pair (4)

What happens to the “F”?

In general, similarity transformations

Page 31: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics61

Warping with Multiple Line Pairs (1)

Using weighted combination of points defined by each pair of corresponding lines

Computer Graphics62

Warping with Multiple Line Pairs (2)

Using weighted combination of points defined by each pair of corresponding lines

P’ is a weighted average

Page 32: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics63

Weighting Effect of Each Line Pair

To weight the contribution of each line pair :

Wherelength[i] is the length of the i-th line

dist[i] is the distance from a point P to the i-th line

a, b, p are constants that control the wrap

[ ] [ ]( )[ ]

bp

idista

ilengthiweight ⎟⎟

⎞⎜⎜⎝

+=

Computer Graphics64

Warping Pseudocode

WarpImage(Image, L’[…], L[…])Begin

for each destination pixel p dopsum = (0, 0)wsum = 0for each line L[i] in destination do

p’[i] = p transformed by (L[i], L’[i])psum += p’[i] * weight[i]wsum += weight[i]

endp’ = psum / wsumResult(p) = Image(p’)

endend

Page 33: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics65

Morphing Pseudocode

GenerateAnimation(Image0, L0[…], Image1, L1[…])Begin

for each intermediate frame time t dofor i=1 to number of line pairs do

L[i] = line t-th of the way from L0[i] to L1[i]endWarp0 = WarpImage(Image0, L0, L)Warp1 = WarpImage(Image1, L1, L)for each pixel p in FinalImage do

Result(p) = (1-t)*Warp0 + t*Warp1end

endend

Computer Graphics66

Beier & Neeley Example (1)

Image 0Image 0

Image 1Image 1

Warp 0Warp 0

Warp 1Warp 1

ResultResult

Page 34: Image Processinggraphics.hallym.ac.kr/teach/2008/cg/src/08image.pdf · 2008-09-16 · 9 Computer Graphics Classical Halftoning (2) Newspaper image From New York Times 9/21/99 10 Computer

Computer Graphics67

Beier & Neeley Example (2)

Image 0Image 0

Image 1Image 1

Warp 0Warp 0

Warp 1Warp 1

ResultResult