Transcript
Page 1: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Image Processing and Representations

Prepared by Behzad Sajadi

Borrowed from Frédo Durand’s Lectures at MIT

Page 2: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Image processing

• Filtering, Convolution, and our friend Joseph Fourier

Page 3: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

What is an image?• We can think of an image as a function, f,• from R2 to R:

– f( x, y ) gives the intensity at position ( x, y ) – Realistically, we expect the image only to be

defined over a rectangle, with a finite range:• f: [a,b]x[c,d] [0,1]

• A color image is just three functions pasted together. We can write this as a “vector-valued” function: ( , )

( , ) ( , )( , )

r x yf x y g x y

b x y

⎡ ⎤⎢ ⎥= ⎢ ⎥⎢ ⎥⎣ ⎦

Page 4: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Images as functions

x

yf(x,y)

Page 5: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Image Processing

• image filtering: change range of image• g(x) = h(f(x))f

xh

f

x

f

x

hf

x

• image warping: change domain of image• g(x) = f(h(x))

Page 6: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Image Processing

• image filtering: change range of image• g(x) = h(f(x))

h

h

• image warping: change domain of image• g(x) = f(h(x))

Page 7: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Point Processing

• The simplest kind of range transformations are those independent of position x,y:

• g = t(f)• This is called point processing.

• Important: every pixel for himself – spatial information completely lost!

Page 8: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Negative

Page 9: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Contrast Stretching

Page 10: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Image Histograms

Cumulative Histograms

s = T(r)

Page 11: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Histogram Equalization

Page 12: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 13: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Filtering

• So far we have looked at range-only and domain-only transformation

• But other transforms need to change the range according to the spatial neighborhood– Linear filtering in particular

Page 14: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering

• Replace each pixel by a linear combination of its neighbors.

• The prescription for the linear combination is called the “convolution kernel”.

5 141 71

5 310

0.50.5 0010

0 00

Local image data kernel

7

Modified image data(shown at one pixel)

Page 15: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

More formally: Convolution

∑ −−=⊗=lk

lkglnkmIgInmf,

],[],[],[

I

Page 16: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering (warm-up slide)

original0

Pixel offset

coef

ficie

nt1.0 ?

Page 17: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering (warm-up slide)

original0

Pixel offset

coef

ficie

nt1.0

Filtered(no change)

Page 18: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering

0Pixel offset

coef

ficie

nt

original

1.0

?

Page 19: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

shift

0Pixel offset

coef

ficie

nt

original

1.0

shifted

Page 20: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering

0Pixel offset

coef

ficie

nt

original

0.3 ?

Page 21: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Blurring

0Pixel offset

coef

ficie

nt

original

0.3

Blurred (filterapplied in both dimensions).

Page 22: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Blur examples

0Pixel offset

coef

ficie

nt

0.3

original

8

filtered

2.4

impulse

Page 23: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Blur examples

0Pixel offset

coef

ficie

nt

0.3

original

8

filtered

48

4

impulse

edge

0Pixel offset

coef

ficie

nt

0.3

original

8

filtered

2.4

Page 24: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 25: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering (warm-up slide)

original

0

2.0

?0

1.0

Page 26: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering (no change)

original

0

2.0

0

1.0

Filtered(no change)

Page 27: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Linear filtering

original

0

2.0

0

0.33 ?

Page 28: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

(remember blurring)

0Pixel offset

coef

ficie

nt

original

0.3

Blurred (filterapplied in both dimensions).

Page 29: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sharpening

original

0

2.0

0

0.33

Sharpened original

Page 30: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sharpening example

coef

ficie

nt

-0.3original

8

Sharpened(differences are

accentuated; constantareas are left untouched).

11.21.7

-0.25

8

Page 31: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sharpening

before after

Page 32: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 33: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Studying convolutions

• Convolution is complicated– But at least it’s linear

(f+kg)- h = f-h +kg• We want to find a better expression

– Let’s study function whose behavior is simple under convolution

Page 34: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Blurring: convolution

Input KernelConvolution

sign

Same shape, just reduced contrast!!!

This is an eigenvector (output is the input multiplied by a constant)

Page 35: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Big Motivation for Fourier analysis

• Sine waves are eigenvectors of the convolution operator

Page 36: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Other motivation for Fourier analysis: sampling

• The sampling grid is a periodic structure– Fourier is pretty good at handling that– A sine wave can have serious problems with sampling

• Sampling is a linear process

Page 37: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sampling Density

• If we’re lucky, sampling density is enough

Input Reconstructed

Page 38: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sampling Density

• If we insufficiently sample the signal, it may be mistaken for something simpler during reconstruction (that's aliasing!)

Page 39: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Motivation for sine waves

• Blurring sine waves is simple– You get the same sine wave, just scaled down– The sine functions are the eigenvectors of the

convolution operator• Sampling sine waves is interesting

– Get another sine wave– Not necessarily the same one! (aliasing)

If we represent functions (or images) with a sum of sine waves, convolution and sampling are easy to study

Page 40: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 41: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Fourier as a change of basis

• Discrete Fourier Transform: just a big matrix

• But a smart matrix!

http://www.reindeergraphics.com

Page 42: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

To get some sense of what basis elements look like, we plot a basis element --- or rather, its real part ---as a function of x,y for some fixed u, v. We get a function that is constant when (ux+vy) is constant. The magnitude of the vector (u, v) gives a frequency, and its direction gives an orientation. The function is a sinusoid with this frequency along the direction, and constant perpendicular to the direction.

u

v( )vyuxie +−π

( )vyuxie +π

Page 43: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Here u and v are larger than in the previous slide.

u

v( )vyuxie +−π

( )vyuxie +π

Page 44: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

And larger still...

u

v( )vyuxie +−π

( )vyuxie +π

Page 45: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Motivations

• Computation bases– E.g. fast filtering

• Sampling rate and filtering bandwidth• Optics: wave nature of light & diffraction • Insights

Page 46: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 47: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Fourier Series

• Consider the family of complex exponentials

• Properties– Periodic with period– Orthogonal on any interval

• Hence, we can write a periodic signal x(t) with period T as

tjnn et ωψ =)( Zn ∈

ωπ /2=T],[][ 00 TttT +=

∑=k

kk tatx )()( ψ][

][

Tkk

Tkk

xa

ψψ

ψ=

where

where

Page 48: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

The Fourier Transform

• Defined for infinite, aperiodic signals• Derived from the Fourier series by “extending the period

of the signal to infinity”• The Fourier transform is defined as

• X(ω) is called the spectrum of x(t)• It contains the magnitude and phase of each complex

exponential of frequency ω in x(t)

∫ −= dtetxX tjω

πω )(

21)(

Page 49: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

The Fourier Transform

• The inverse Fourier transform is defined as

• Fourier transform pair

• x(t) is called the spatial domain representation• X(ω) is called the frequency domain

representation

∫= ωωπ

ω deXtx tj)(21)(

)()( ωXtx F⎯→←

Page 50: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Duality

Page 51: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Beware of differences

• Different definitions of Fourier transform• We use

• Other people might exclude normalization or include 2π in the frequency

• X might take ω or jω as argument• Physicist use j, mathematicians use i

∫ −= dtetxX tjω

πω )(

21)(

Page 52: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 53: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Phase• Don’t forget the phase! Fourier transform results

in complex numbers

• Can be seen as sum of sines and cosines

• Or modulus/phase

Page 54: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Phase is important!

Page 55: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Phase is important!

Page 56: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 57: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Convolution

• Sliding window

Page 58: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Convolution

Page 59: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y
Page 60: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y
Page 61: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Low pass http://www.reindeergraphics.com

Page 62: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

High pass http://www.reindeergraphics.com

Page 63: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Analysis of our simple filters

original0Pixel offset

coef

ficie

nt

1.0

Filtered(no change)

1

][][1

0

=

= ∑−

=

⎟⎠⎞

⎜⎝⎛−M

k

Mkmi

ekfmFπ

0

1.0 constant

Page 64: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Analysis of our simple filters

0Pixel offset

coef

ficie

nt

original

1.0

shifted

Mmi

M

k

Mkmi

e

ekfmF

δπ

π

=

⎟⎠⎞

⎜⎝⎛−

=

= ∑

][][1

0

0

1.0

Constant magnitude, linearly shifted phase

δ

Page 65: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Analysis of our simple filters

0Pixel offsetco

effic

ient

original

0.3

blurred

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+=

= ∑−

=

⎟⎠⎞

⎜⎝⎛−

Mm

ekfmFM

k

Mkmi

π

π

cos2131

][][1

0 Low-pass filter

0

1.0

Page 66: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Analysis of our simple filters

original0

2.0

0

0.33

sharpened

⎟⎟⎠

⎞⎜⎜⎝

⎛⎟⎠⎞

⎜⎝⎛+−=

= ∑−

=

⎟⎠⎞

⎜⎝⎛−

Mm

ekfmFM

k

Mkmi

π

π

cos21312

][][1

0 high-pass filter

0

1.0

2.3

Page 67: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Questions?

Page 68: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sampling and aliasing

Page 69: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

More on Samples• In signal processing, the process of mapping a

continuous function to a discrete one is called sampling• The process of mapping a continuous variable to a

discrete one is called quantization• To represent or render an image using a computer,

we must both sample and quantize – Now we focus on the effects of sampling and how to fight them

discrete position

discretevalue

Page 70: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sampling in the Frequency Domain

(convolution)(multiplication)

originalsignal

samplinggrid

sampledsignal

Fourier Transform

Fourier Transform

Fourier Transform

Page 71: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Reconstruction

• If we can extract a copy of the original signal from the frequency domain of the sampled signal, we can reconstruct the original signal!

• But there may be overlap between the copies.

Page 72: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Guaranteeing Proper Reconstruction

• Separate by removing high frequencies from the original signal (low pass pre-filtering)

• Separate by increasing the sampling density

• If we can't separate the copies, we will have overlapping frequency spectrum during reconstruction → aliasing.

Page 73: Image Processing and Representationsmajumder/PHOTO/ImageProcessingAndRepresentation.pdfWhat is an image? • We can think of an image as a function, f, •from R2 to R: – f( x, y

Sampling Theorem

• When sampling a signal at discrete intervals, the sampling frequency must be greater than twice the highest frequency of the input signal in order to be able to reconstruct the original perfectly from the sampled version (Shannon, Nyquist, Whittaker, Kotelnikov)


Top Related