last time

30
09/19/2002 (C) University of Wisconsin 2 002, CS 559 Last Time Color Quantization • Dithering

Upload: lynn-vang

Post on 03-Jan-2016

14 views

Category:

Documents


0 download

DESCRIPTION

Last Time. Color Quantization Dithering. Today. Signal processing for graphics Homework 2 is available Project 2 is almost available. Enlarging an Image. To enlarge an image, you have to add pixels between the old pixels What values do you choose for those pixels?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Last Time

• Color Quantization

• Dithering

Page 2: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Today

• Signal processing for graphics

• Homework 2 is available

• Project 2 is almost available

Page 3: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Enlarging an Image

• To enlarge an image, you have to add pixels between the old pixels

• What values do you choose for those pixels?

Page 4: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Images as Samples of Functions

• We can view an image as a set of samples from an ideal function– This is particularly true if we are plotting a function, but it is also

the case that a digital photograph is a sample of some function

• If we knew what the function was, we could enlarge the image by resampling the function

• Failing that, we can reconstruct the function and then resample it

Page 5: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Why Signal Processing?

• Signal processing provides the tools for understanding sampling and reconstruction

• Sampling:– How do we know how many pixels are required, and where to place

them?

• Reconstruction:– What happens when a monitor converts a set of points into a

continuous picture?– How do we enlarge, reduce, rotate, smooth or enhance images?

• Jaggies, Aliasing– How do we avoid jagged, pixelated lines

Page 6: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

A Striking Example

samplingdifferent domain, same )sin( 22 ,yx

Page 7: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Periodic Functions

• Fact: Any periodic signal can be represented as a sum of sine and cosine waves with harmonic frequencies– If one function has frequency f, then its harmonics are function with

frequency nf for integer n

• Sequence of boxes is:

xxx

k

xkxS

k

kboxes

5cos5

13cos

3

1cos

2

2

1

12

)12cos()1(

2

2

1)(

1

1

Page 8: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Boxes as Sum of Cosines

-0.25

-0.05

0.15

0.35

0.55

0.75

0.95

1.15

-0.25

-0.05

0.15

0.35

0.55

0.75

0.95

1.15

-0.25

-0.05

0.15

0.35

0.55

0.75

0.95

1.15

-0. 25

-0. 05

0. 15

0. 35

0. 55

0. 75

0. 95

1. 15

-0. 25

-0. 05

0. 15

0. 35

0. 55

0. 75

0. 95

1. 15

Page 9: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

General Functions

• A non-periodic function can be represented as a sum of sin’s and cos’s of (possibly) all frequencies:

• F() is the spectrum of the function f(x)– The spectrum is how much of each frequency is present in the

function

– We’re talking about functions, not colors, but the idea is the same

deFxf xi)(

2

1)(

xixe xi sincos

Page 10: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Fourier Transform

• F() is computed from f(x) by the Fourier Transform:

dxexfF xi )()(

Page 11: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Example: Box Function

21 02

1 1)(

x

xxf

f

ff

fF

sinc2

sin

)(

Page 12: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Box Function and Its Transform

-0.5

-0.3

-0.1

0.1

0.3

0.5

0.7

0.9

1.1

1.3

1.5

-0.5

-0.3

-0.1

0.1

0.3

0.5

0.7

0.9

1.1

1.3

1.5

Page 13: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Cosine and Its Transform

-1.5

-1

-0.5

0

0.5

1

1.5

1-1

If f(x) is even, so is F()

Page 14: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Sine and Its Transform

-1. 5

-1

-0. 5

0

0. 5

1

1. 5

1

-1

-

If f(x) is odd, so is F()

Page 15: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Constant Function and Its Transform

The constant function only contains the 0th frequency – it has no wiggles

Page 16: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Delta Function and Its Transform

Fourier transform and inverse Fourier transform arequalitatively the same, so knowing one direction gives you the other

Page 17: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Shah (Spikes) and Its Transform

Page 18: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Gaussian and Its Transform (the same)

-0. 02

0. 03

0. 08

0. 13

0. 18

-0. 02

0. 03

0. 08

0. 13

0. 182

2

2

1 x

e

Page 19: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

• The spectrum of a functions tells us the relative amounts of high and low frequencies– Sharp edges give high frequencies

– Smooth variations give low frequencies

• A function is bandlimited if its spectrum has no frequencies above a maximum limit– sin, cos are band limited

– Box, Gaussian, etc are not

Qualitative Properties

Page 20: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Functions to Images

• Images are 2D, discrete functions

• 2D Fourier transform uses product of sin’s and cos’s (things carry over naturally)

• Fourier transform of a discrete, quantized function will only contain discrete frequencies in quantized amounts– In particular, we can store the Fourier transform of a discrete image

in the same amount of space as we can store the image

• Numerical algorithm: Fast Fourier Transform (FFT) computes discrete Fourier transforms

Page 21: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Filters

• A filter is something that attenuates or enhances particular frequencies

• Easiest to visualize in the frequency domain, where filtering is defined as multiplication:

• Here, F is the spectrum of the function, G is the spectrum of the filter, and H is the filtered function. Multiplication is point-wise

)()()( GFH

Page 22: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Qualitative Filters

F G

=

=

=

H

Low-pass

High-pass

Band-pass

Page 23: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Low-Pass Filtered Image

Page 24: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

High-Pass Filtered Image

Page 25: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Filtering in the Spatial Domain

• Filtering the spatial domain is achieved by convolution

• Qualitatively: Slide the filter to each position, x, then sum up the function multiplied by the filter at that position

duuxgufgfxh )()()(

Page 26: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Convolution Example

Page 27: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Convolution Theorem

• Convolution in the spatial domain is the same as multiplication in the frequency domain– Take a function, f, and compute its Fourier transform, F– Take a filter, g, and compute its Fourier transform, G– Compute H=FG– Take the inverse Fourier transform of H, to get h– Then h=fg

• Multiplication in the spatial domain is the same as convolution in the frequency domain

Page 28: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Filtering Images

• Work in the discrete spatial domain

• Convert the filter into a matrix, the filter mask

• Move the matrix over each point in the image, multiply the entries by the pixels below, then sum– eg 3x3 box filter

– averages

111

111

111

9

1

Page 29: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Box Filter

• Box filters smooth by averaging neighbors• In frequency domain, keeps low frequencies and attenuates (reduces)

high frequencies, so clearly a low-pass filter

111

111

111

9

1

Spatial: Box Frequency: sinc

Page 30: Last Time

09/19/2002 (C) University of Wisconsin 2002, CS 559

Filtering Algorithm

• If Iinput is the input image, and Ioutput is the output image, M is the filter mask and k is the mask size:

• Care must taken at the boundary– Make the output image smaller

– Extend the input image in some way

2/

2/

2/

2/

]2/][2/[]][[]][[k

ki

k

kjinputoutput kjkiMjyixIyxI