98
Chapter 5 Digital Image Processing Fundamentals

Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Embed Size (px)

Citation preview

Page 1: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Chapter 5

Digital Image Processing Fundamentals

Page 2: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Learning Goals

• The human visual system

• Digitizing images

• Display of Images

Page 3: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Trading an eye for an ear

opticalaxiscornea

lensopticdisk

opticnerveretina

foveacentralis

iris

Page 4: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Response curves

• Eye has Gaussian response to light.

• Gives rise to biologically motivated image processing

Page 7: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Quantization of an Image

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

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

Page 8: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Delta-function

⎩⎨⎧ =

=⋅ else 0

0 )0()()(

nxnnx δ

Page 9: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Sampling an Image

f s

f (x) Anti-aliasingFilter

Page 10: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Quantization Error is visible

Page 12: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Displays

• Color Monitors are made for people

Page 13: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Chapter 6-7

• Opening and Saving Images

Page 14: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Convolution

1D and 2D signal processing

Page 16: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Consider the delta function

⎩⎨⎧ =

=⋅ else 0

0 )0()()(

nxnnx δ

δ(t)− ε

ε

∫ dt = 1

Page 17: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Time-shift delta

)( knk −=δδ

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

Page 18: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

What does sampling do to spectrum?

Page 20: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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

Page 21: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Fourier Coefficients

a0 ,a1,b1, a2 ,b2K

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

Page 22: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Euler’s identity

e iθ =cosθ + i sinθ

Page 24: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Convolution=time-shift&multi

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

Page 27: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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

multiplication in the time domain =convolution in the frequency domain

Page 28: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Spectrum reproduced

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

spectrum to be reproduced at intervalsf s

Page 30: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Example of 1D convoln

Page 32: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

What is wrong with avoiding the mod op?

• How do I find the center of the kernel?

Page 38: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Cyclic Convolution

Page 39: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

What happens to the image if you ignore the wrap?

Page 41: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Cyclic Convolution keeps the edges

Page 42: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Convolution is slow, how can I speed it up?

• JAI!

• FFT!?

• Other ideas?

Page 44: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Chapter 9

• Spatial Filters

• Blurring

• Median Filtering

• Hi-pass filtering

• SpatialFilterFrame and JAI

Page 45: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Blurring=Low-pass Filters

Page 46: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Why Blur an Image?

• Remove Noise

• Other ideas?

Page 47: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Want Unity Gain

G = kijj=0

H−1

∑i=0

W−1

Page 49: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Why use Gaussian Blur?

• How the eye works

• Symmetric

• Differentiable

• Smooth

Page 52: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Classic bell curve

Page 53: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Larger Kernels=more blur

Page 54: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Median Filtering

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

• Sort samples, return n/2

Page 55: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Median 3x3

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

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

}

Page 59: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Median result

Page 61: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

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 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Median Octagon results

Page 63: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Median Filtering is not FREE!

• Image degradation

• Selective median filtering.

• How do you know when to apply it?

Page 64: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Use Sample Variance

σ 2 =1

n(ai − a )2

i= 0

n-1

a =mean

ai = ith sample

σ 2 = sample variance and

n= number of samples

Page 65: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Coefficient of variationˆ C = σ / a

public static boolean outlierHere(int a[]) {return ( coefficientOfVariation(a) > .4);

}

Page 66: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Before and After 3x3 Median Filtering with Outlier Detection

Page 67: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

High-pass Filters

Page 68: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Defining HP Kernels

public void hp1() { float k[][] = {

{ 0, -1, 0},{-1, 10, -1},{ 0, -1, 0}};Mat.normalize(k);

convolve(k); }

Page 69: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Lower Center Number, GREATER edge enhancement!

510

Page 70: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Project ideasAdd an interface that allows the user to outline a rectangular region of interest. Then perform processing only in that region.

Page 71: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

10. Convolution-based Edge Detection

Why do edge detection?What is an edge?What is a good edge?How do you find an edge?

Page 72: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Laplacian

∇2 f (x, y) =∂ 2 f

∂x2 +∂ 2 f

∂y2

Page 73: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Why Laplacian?

because it is zero when the rate of intensity change in the image plane is zero or linear.

Page 74: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Log filters=prefilter+laplacian

−∇2 1

2πσ 2 ex 2 + y 2

2σ2

=1

πσ 4 1 −x2 + y2

2σ 2

⎣ ⎢ ⎤

⎦ ⎥e−

x 2 + y 2

2σ2

∇2 f (x, y) =∂ 2 f

∂x2 +∂ 2 f

∂y2

Page 75: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Mexican Hat (LoG Kernel)

Page 76: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

The Log kernel

Page 77: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Oriented Filters are steerable

Page 78: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Changing Scale at 0 Degrees

Page 79: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Changing Phase at 0 degrees

Page 80: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Interactive Heuristic Edge Detection

Douglas A. Lyon, Ph.D.Chair, Computer Engineering Dept. Fairfield

University, CT, USA

[email protected], http://www.DocJava.com

CGIM, 2002

Copyright 2002 © DocJava, Inc.

Page 81: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Background

• It is easy to find a bad edge!• We know a good edge when we see it!

Page 82: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

The Problem

• Given an expert + an image.

• The expert places markers on a good edge.

• Find a way to connect the markers.

Page 83: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Motivation

• Experts find/define good edges

• Knowledge is hard to encode.

Page 84: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Approach

• Mark an important edge

• Pixels=graph nodes

• Search in pixel space using a heuristic

• A* is faster than DP

Page 85: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Assumptions

• User is a domain expert

• Knowledge rep=heuristics+markers

Page 86: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Applications

• Photo interpretation

• Path planning (source+destination)

• Medical imaging

Page 87: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Photo Interpretation

Page 88: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Echocardiogram

•3D-multi-scale analysis

Page 89: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Path Plans, the idea

Page 90: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Path Planning-pre proc.•hist+thresh

•Dil+Skel

Page 91: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Path Planning - Search

Page 92: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

The Idea

• The mind selects from filter banks

• The mind tunes the filters

Page 93: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Gabor filter w/threshold

• The Strong edge is the wrong edge!

Page 94: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Sub bands for 3x3 Robinson

Page 95: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Sub Bands 7x7 Gabor

Page 96: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Gabor-biologically motivated

Page 97: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

Summary

• Heuristics+markers= knowledge• Low-level image processing still needed• Global optimization is not appropriate for

all applications• Sometimes we only want a single, good

edge

Page 98: Chapter 5 Digital Image Processing Fundamentals. Learning Goals The human visual system Digitizing images Display of Images

http://www.DocJava.com