63
Chapter 5 Digital Image Processing Fundamentals

Chapter 5

Embed Size (px)

DESCRIPTION

Chapter 5. Digital Image Processing Fundamentals. Learning Goals. The human visual system Digitizing images Display of Images. Trading an eye for an ear. An eye is a Multi-mega pixel camera. It has a lens (adjustable zoom) It has an automatic f-stop (iris 2-8 mm) - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 5

Chapter 5

Digital Image Processing Fundamentals

Page 2: Chapter 5

Learning Goals

• The human visual system

• Digitizing images

• Display of Images

Page 3: Chapter 5

Trading an eye for an ear

opticalaxiscornea

lensopticdisk

opticnerveretina

foveacentralis

iris

Page 4: Chapter 5

An eye is a Multi-mega pixel camera

• It has a lens (adjustable zoom)

• It has an automatic f-stop (iris 2-8 mm)

• It has a sensor plane (100 million pixels)

• The sensor has a transfer function senstive to mesopic range; 380 to about 700 nm

Page 5: Chapter 5

The eyes have a USB2 data rate!

• 250,000 neurons in the optic nerve

• variable voltage output on EACH nerve

• 17.5 million neural samples per second

• 12.8 bits per sample

• 224 Mbps, per eye (a 1/2 G bps system!).

• Compression using lateral inhibition between the retinal neurons

Page 6: Chapter 5

Response curves

• Eye has Gaussian response to light.

• Gives rise to biologically motivated image processing

Page 7: Chapter 5

Quantization of an Image

• Computers use digital cameras -> quantizationSNR≤6b+ 4.8

SNR =10 log3×22 b( ) =20blog2 +10log3

Page 8: Chapter 5

Delta-function

⎩⎨⎧ =

=⋅ else 0

0 )0()()(

nxnnx δ

Page 9: Chapter 5

Sampling an Image

f s

f (x) Anti-aliasingFilter

Page 10: Chapter 5

Sampling=convolution w pulse train

F(u) *P(u) ≡ F(γ)P(u−γ)dγ−∞

F(u) *P(u) = f(x) δ(x−n / fs)n=−∞

∑ e−j 2πux ⎡ ⎣ ⎢

⎤ ⎦ ⎥dx

−∞

Page 11: Chapter 5

Quantization Error is visible

Page 12: Chapter 5

Displays

• Color Monitors are made for people

Page 13: Chapter 5

Chapter 6-7

• Opening and Saving Images

Page 14: Chapter 5

Chapter 8 Convolutionwith a kernel, g(x)

h(x) = f(x) * g(x)= f(u)g(x−u)du−∞

h(x) = f(x) * g(x)= f (u)g(−∞

∑ x−u)

Page 15: Chapter 5

Convolution

1D and 2D signal processing

Page 16: Chapter 5

Consider the delta function

⎩⎨⎧ =

=⋅ else 0

0 )0()()(

nxnnx δ

δ(t)− ε

ε

∫ dt = 1

Page 17: Chapter 5

Time-shift delta

)( knk −=δδ

kk kxx δδ ⋅=⋅ )(δ( t − td )

Page 18: Chapter 5

Sample the input (it’s a convolution!)

][][][])[*( nxkxknnxk∑∞

−∞=

=−= δδ

s(t) = δ(t−n / fs)n=−∞

vs (t) =v(t)s(t) =v(t) δ(t−n/ fs)n=−∞

Page 19: Chapter 5

What does sampling do to spectrum?

Page 20: Chapter 5

What is the spectrum? v(t) =a0 + (a1 cost+b1sint) + (a2 cos2t+b2sin2t)+K

Page 21: Chapter 5

Fourier Coefficients

a0 ,a1,b1, a2 ,b2K

v(t) =a0 + (a1 cost+b1sint) + (a2 cos2t+b2sin2t)+K

Page 22: Chapter 5

CTFT

V( f ) =F [v(t)] = v(t)e−2 πiftdt−∞

v(t) =F−1 V( f )[ ] = V( f)e2πiftdt−∞

∫e iθ =cosθ + i sinθ

Page 23: Chapter 5

Euler’s identity

e iθ =cosθ + i sinθ

Page 24: Chapter 5

Sine-cos Rep

x(t) = an cos(2πnf0t) + bn sin(2πnf0t)n=1

∑n=0

v(t) =a0 + (a1 cost+b1sint) + (a2 cos2t+b2sin2t)+K

Page 25: Chapter 5

Harmonic Analysisa0 =1

Tx(t)dt

0

T

an =2T

x(t)cos(2πnf0t)dt0

T

bn =2T

x(t)sin(2πnf0t)dt0

T

Page 26: Chapter 5

Convolution=time-shift&multi

V *W( f ) ≡ V(λ )W( f −λ)dλ−∞

Page 27: Chapter 5

Convolution ThmV *W( f ) =F(v(t)w(t))

multiplication in the time domain =convolution in the frequency domain

Page 28: Chapter 5

Sample

vs (t) =v(t)s(t) =v(t) δ(t−n/ fs)n=−∞

Vs ( f ) =V(F) * fsδ( f −nfs )n=−∞

Vs ( f ) = fs V( f −nfs)n=−∞

Page 29: Chapter 5

Spectrum reproduced

Vs ( f ) = fs V( f −nfs)n=−∞

spectrum to be reproduced at intervalsf s

Page 30: Chapter 5

Summary

h(x) = f(x) * g(x)= f(u)g(x−u)du−∞

h(x) = f(x) * g(x)= f (u)g(−∞

∑ x−u)

Page 31: Chapter 5

Example of 1D convoln

Page 32: Chapter 5

2D Convolution

h(x, y) = f * g= f (u,v)g(x−u,y−v)dudv−∞

∫−∞

h(x,y) = f * g= f(u,v)g([x−u],[y−v])v=0

vmax−1

∑u=0

umax−1

Page 33: Chapter 5

Region of Support

• The region of support is defined as that area of the .kernel which is non-zero

• linear convolution:=signal has infinite extent but kernel has finite support

• If function has finite region of support we have compact support

Page 34: Chapter 5

Real images have finite region of support

• But we treat them as periodic and infinite!

• We repeat kernels so that they have the same period as the images.

• We call this cyclic convolution.

Page 35: Chapter 5

Convolution in 2D

h(x, y) = f * g= f (u,v)g(x−u,y−v)dudv−∞

∫−∞

h(x,y) = f * g= f(u,v)g([x−u],[y−v])v=0

vmax−1

∑u=0

umax−1

[x −u] =(x−u)modumax

[y−v] =(y−v)modvmax

Page 36: Chapter 5

Avoid the Mod op

h(x,y) = f * g= f (x−u,y−v)g(u+uc ,v+vc)v=−vc

vc

∑u=−uc

uc

Page 37: Chapter 5

What is wrong with avoiding the mod op?

• How do I find the center of the kernel?

Page 38: Chapter 5

Cyclic Convolution

Page 39: Chapter 5

Implementing Convolution for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { sum = 0.0; for(int v = -vc; v <= vc; v++) for(int u = -uc; u <= uc; u++) sum += f[cx(x-u) ][cy(y-v)] * k[ u+uc][v+vc]; if (sum < 0) sum = 0; if (sum > 255) sum = 255; h[x][y] = (short)sum; } }

Page 40: Chapter 5

What happens to the image if you ignore the wrap?

Page 41: Chapter 5

Cyclic Convolution keeps the edges

Page 42: Chapter 5

Can you think of a better way to implement convolution?

• Keep the edges!

• Don’t use the mod operation.

• How about growing the image by the size of the kernel*2?

Page 43: Chapter 5

Convolution is slow, how can I speed it up?

• JAI!

• FFT!?

• Other ideas?

Page 44: Chapter 5

Chapter 9

• Spatial Filters

• Blurring

• Median Filtering

• Hi-pass filtering

• SpatialFilterFrame and JAI

Page 45: Chapter 5

Blurring=Low-pass Filters

Page 46: Chapter 5

Why Blur an Image?

• Remove Noise

• Other ideas?

Page 47: Chapter 5

Average=low-pass

public void average() { float k[][] = { {1, 1, 1}, {1, 1, 1}, {1, 1, 1} }; Mat.scale(k,1/9.0); convolve(k); }

Page 48: Chapter 5

Want Unity Gain

G = kijj=0

H−1

∑i=0

W−1

Page 49: Chapter 5

Many variations on LP filters

public void lp3() { float k[][] = { {1, 1, 1}, {1, 12, 1}, {1, 1, 1} }; Mat.scale(k,1/20.0); convolve(k); }

Page 50: Chapter 5

Gaussian Blur

gaussian(x,y, xc, yc,σ ) =1

2πσ 2 e−

x−xc( )2− y−yc( )

2( )

2σ 2

gmax =1

2πσ 2

Page 51: Chapter 5

Why use Gaussian Blur?

• How the eye works

• Symmetric

• Differentiable

• Smooth

Page 52: Chapter 5

Classic bell curve

Page 53: Chapter 5

Larger Kernels=more blur

Page 54: Chapter 5

Median Filtering

• Middle of a list of samples listed in ascending order.

• Sort samples, return n/2

Page 55: Chapter 5

Why use median filtering?

• Discard outliers

• 0, 85, 90, 87 and 100. The mean is 72

• Median is 87.

• {0, 85, 87, 90, and 100}=87

Page 56: Chapter 5

How do I implement the median?

public static int median(int a[]) { quickSort(a); int mid = a.length/2-1; if ((a.length & 1) == 1) return a[mid]; return (int )((a[mid]+ a[mid+1]+0.5)/2); }

Page 57: Chapter 5

Salt and Pepperpublic void saltAndPepper(int n) { for (int i=0;i < n; i++) { int rx = rand(0,width-1); int ry = rand(0,height-1); r[rx][ry] = 255; g[rx][ry] = 255; b[rx][ry] = 255; rx = rand(0,width-1); ry = rand(0,height-1); r[rx][ry] = 0; g[rx][ry] = 0; b[rx][ry] = 0; } short2Image(); }

Page 58: Chapter 5

Median 3x3

public void medianCross3x3() { short k[][] = {

{0, 1, 0},{1, 1, 1},{0, 1, 0}};median(k);

}

Page 59: Chapter 5

Median on any kernel

public void median (short k[] []) { printMedian(k,"color median"); Timer t = new Timer(); t.start();

r = median(r,k);g = median(g,k);b = median(b,k);t.print("Median filter time");

short2Image();}

Page 60: Chapter 5

Median result

Page 61: Chapter 5

Median Octagon, less aggressive

public void medianOctagon5x5() {short k[][] = {{ 0, 1, 1, 1, 0},{ 1, 1, 1, 1, 1},{ 1, 1, 1, 1, 1},{ 1, 1, 1, 1, 1},{ 0, 1, 1, 1, 0}};median(k);

}

Page 62: Chapter 5

Median Octagon results

Page 63: Chapter 5

Median Filtering is not FREE!

• Image degradation

• Selective median filtering.

• How do you know when to apply it?