<<

Linear Image Processing and Filtering

n Math of 2-d linear systems n Separability n Shift-invariant linear systems, 2-d n Integral image for fast box-filtering n 2-d

n Blurring and sharpening

n Zoneplate 1 0.8 n Image sampling/aliasing 0.6 0.4

0.2 n Wiener filtering 0

2 3 2 0 1 n 0 Nonlinear noise reduction/sharpening ω -1 y -2 -2 ω -3 x

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 1 Linear image processing

n Image processing system S(.) is linear, iff holds: S α ⋅ f #x, y% + β ⋅ g #x, y% = α ⋅ S f #x, y% + β ⋅ S g #x, y% for all α, β ∈! ( $ & $ &) ( $ &) ( $ &) n Any linear image processing system can be written as   g = Hf Note: matrix H need not be square. by sorting pixels into a column vector  T f = f ⎣⎡0,0⎦⎤ f ⎣⎡1,0⎦⎤  f ⎣⎡N −1,0⎦⎤ f ⎣⎡0,1⎦⎤  f ⎣⎡N −1,1⎦⎤   f ⎣⎡0, L −1⎦⎤  f ⎣⎡N −1, L −1⎦⎤ ( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 2 Impulse response

n Another way to represent any linear image processing scheme

N−1 L−1 g[α,β ] = ∑∑ f [x, y]⋅h[x,α, y,β ] x=0 y=0 impulse response n Input: unit impulse at pixel [a,b]

&$ 1 x = a ∧ y = b f [x, y] = δ [x − a, y − b] = % 0 else n Output: impulse response '&

N−1 L−1 g[α,β ] = ∑∑δ [x − a, y − b]⋅h[x,α, y,β ] = h[a,α,b,β ] x=0 y=0

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 3 Interpretation #1: superposition of impulse responses

δ [x − a, y − b] f [a,b] g[α,β] = h[a,α,b,β] f [a,b] a x + α

b x

y β a + x α

b x y β +

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 4 Interpretation #2: linear combination of input values

N −1 L−1 f [x, y]⋅h[x,α, y,β] g[α,β] = ∑∑ f [x, y]⋅h[x,α, y,β] x=0 y=0 x α

∑ x

y β x α

∑ x

y β

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 5 Relationship of H and h[x,α,y,β ] y → x → x → x → •• • ↓ α ↓ α ↓α x → x → x → •• • ↓ α ↓ α ↓ α • • • β ↓ • • • • • • x → x → x → •• • ↓ α ↓ α ↓ α

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 6 Separable linear image processing

n Impulse response is separable in [x,α] and [y,β], i.e., can be written as N−1 L−1 g[α,β ] = ∑∑ f [x, y]⋅hx [x,α ]hy [y,β ] x=0 y=0 n Processing can be carried out l row by row, then column by column L−1 N−1 g[α,β ] = ∑hy [y,β ]∑ f [x, y]⋅hx [x,α ] y=0 x=0

l column by column, then row by row

N−1 L−1 g[α,β ] = ∑hx [x,α ]∑ f [x, y]⋅hy [y,β ] x=0 y=0

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 7 Separable linear image processing (cont.)

n If the digital input and output images are written as a matrices f and g, we can conveniently write T g = Hy ⋅ f ⋅Hx

⎡ h 0,0 h 0,1  h ⎡0, L −1⎤ ⎤ ⎡ h 0,0 h 0,1  h ⎡0, N −1⎤ ⎤ ⎢ y [ ] y [ ] y ⎣ g ⎦ ⎥ ⎢ x [ ] x [ ] x ⎣ g ⎦ ⎥ ⎢ ⎥ ⎢ ⎥ h 1,0 h 1,1  h ⎡1, N −1⎤ hy [1,0] hy [1,1]  hy ⎡1, Lg −1⎤ ⎢ x [ ] x [ ] x ⎣ g ⎦ ⎥ H = ⎢ ⎣ ⎦ ⎥ Hx = y ⎢ ⎥ ⎢    ⎥    ⎢ ⎥ ⎢ ⎥ h L 1,0 h L 1,1 h ⎡L 1, L 1⎤ ⎢ hx [N −1,0] hx [N −1,1]  hx ⎡N −1, Ng −1⎤ ⎥ ⎢ y [ − ] y [ − ]  y ⎣ − g − ⎦ ⎥ ⎣ ⎣ ⎦ ⎦ ⎣ ⎦

n Output image g has size Lg x Ng

n If the operator does not change image size, Hx and Hy are square matrices

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 8 Example: Separable Haar transform

Original Bike 256x256 256x256 Haar transform

Hx=Hy=Hr256

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 9 Haar transform

n Haar transform matrix for sizes N=2,4,8 ⎛ 1 1 2 0 2 0 0 0 ⎞ 1 ⎛ 1 1 ⎞ ⎜ ⎟ Hr2 = ⎜ ⎟ ⎜ 1 1 2 0 −2 0 0 0 ⎟ 2 ⎝ 1 −1 ⎠ ⎜ ⎟ ⎜ 1 1 − 2 0 0 2 0 0 ⎟ ⎛ ⎞ 1 ⎜ 1 1 − 2 0 0 −2 0 0 ⎟ 1 1 2 0 Hr8 = ⎜ ⎟ ⎜ ⎟ 8 ⎜ 1 −1 0 2 0 0 2 0 ⎟ 1 ⎜ 1 1 − 2 0 ⎟ ⎜ ⎟ Hr 1 −1 0 2 0 0 −2 0 4 = ⎜ ⎟ ⎜ ⎟ 4 1 −1 0 2 ⎜ 1 −1 0 − 2 0 0 0 2 ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ 1 1 0 2 0 0 0 2 ⎟ ⎝⎜ 1 −1 0 − 2 ⎠⎟ ⎝ − − − ⎠

n Can be computed by taking sums and differences

n Fast algorithms by recursively applying Hr2

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 10 Example: Subsampling

n Image subsampling 2:1 horizontally and vertically n Small input image of size 8x8, output image size 4x4

⎡ 1 0 0 0 ⎤ ⎢ ⎥ ⎢ 0 0 0 0 ⎥ ⎢ 0 1 0 0 ⎥ ⎢ 0 0 0 0 ⎥ Hx = Hy = ⎢ ⎥ ⎢ 0 0 1 0 ⎥ ⎢ 0 0 0 0 ⎥ ⎢ 0 0 0 1 ⎥ ⎢ ⎥ ⎣ 0 0 0 0 ⎦

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 11 Example: Subsampling (cont.)

n A somewhat better technique for 2:1 image size reduction

⎡ 0.5 0 0 0 ⎤ ⎢ ⎥ ⎢ 0.5 0 0 0 ⎥ ⎢ 0 0.5 0 0 ⎥ ⎢ 0 0.5 0 0 ⎥ Hx = Hy = ⎢ ⎥ ⎢ 0 0 0.5 0 ⎥ ⎢ 0 0 0.5 0 ⎥ ⎢ 0 0 0 0.5 ⎥ ⎢ ⎥ ⎣ 0 0 0 0.5 ⎦

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 12 Side by side comparison

Hx = Hy = Hx = Hy = ! 1 0 0 0 $ ! 0.5 0 0 0 $ # 0 0 0 0 & # & # & # 0.5 0 0 0 & # 0 1 0 0 & # 0 0.5 0 0 & # 0 0 0 0 & # 0 0.5 0 0 & # & # & # 0 0 1 0 & # 0 0 0.5 0 & # 0 0 0 0 & # 0 0 0.5 0 & # 0 0 0 1 & # 0 0 0 0.5 & # & # & " 0 0 0 0 % " 0 0 0 0.5 %

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 13 Another example: filtering

n Each pixel is replaced by the average of two horizontally (vertically) neighboring pixels ⎡ 0.5 0  0 ⎤ ⎢ ⎥ ⎢ 0.5 0.5 ⎥ ⎢ 0 0.5 0.5 ⎥ ⎢ 0.5 0.5   ⎥ Hx = Hy = ⎢ ⎥ ⎢ 0.5 0.5 ⎥ ⎢   0.5 0.5 ⎥ ⎢ 0.5 0.5 0 ⎥ ⎢ ⎥ 0  0 0.5 0.5 ⎣ ⎦

n Shift-invariant operation (except for image boundary)

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 14 Shift-invariant systems and Toeplitz matrices

n For a separable, shift-invariant,

hx [x,α]= hsiv/x [α − x] and hy [y,β]= hsiv/y [β − y]

n Matrices Hx and Hy are square, and Toeplitz matrices, e.g.,

⎡ h 0 h 1  h N −1 ⎤ ⎢ siv/x [ ] siv/x [ ] siv/x [ ] ⎥ ⎢ hsiv/x [−1] hsiv/x [0]  hsiv/x [N − 2] ⎥ Hx = ⎢ ⎥ ⎢    ⎥ ⎢ hsiv/x [1− N ] hsiv/x [2 − N ]  hsiv/x [0] ⎥ ⎣ ⎦ n Operation is a 2-d separable convolution („filtering“)

N −1 L−1 g[α,β]= ∑∑ f [x, y]⋅hsiv/x [α − x]hsiv/y [β − y] x=0 y=0

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 15 Non-separable 2-d convolution

n Convolution kernel of linear shift-invariant system („filter“) can also be non-separable

N −1 L−1 g[α,β]= ∑∑ f [x, y]⋅hsiv [α − x,β − y] x=0 y=0

n Viewed as a matrix operation . . .   g = Hf . . . H is a block Toeplitz matrix

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 16 Structure of H for non-separable convolution y → x → x → x → •• • ↓ α ↓ α ↓ α x → x → x → •• • ↓ α ↓ α ↓ α • • • β ↓ • • • • • • x → x → x → •• • ↓ α ↓ α ↓ α

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 17 Convolution: superposition of impulse responses

f [a,b]δ [x − a, y − b] g[x, y] = hsiv [x − a, y − b] f [a,b] a + x x

b x 1 x 5 2 3 4

y + y a + x x

b x 1 x 5 + 2 3 4 y y +

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 18 Convolution: linear combination of neighboring pixel values N −1 L−1 g , f x, y h x, y f [x, y]⋅hsiv [α − x,β − y] [α β]= ∑∑ [ ]⋅ siv [α − β − ] x=0 y=0 α x x

4 3 2 5 x 1 ∑ xx β + y y x x

4 3 2 5 x 1 ∑ + x β y y α

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 19 Convolution examples

Original Bike blurred by convolution Bike Impulse response „box filter“

⎛ 1 1 1 1 1 ⎞ ⎜ 1 1 1 1 1 ⎟ 1 ⎜ ⎟ ⎜ 1 1 [1] 1 1 ⎟ 25 ⎜ 1 1 1 1 1 ⎟ ⎜ ⎟ ⎝ 1 1 1 1 1 ⎠

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 20 Convolution examples

Original Bike blurred horizontally Bike Filter impulse response

1 1 1 [1] 1 1 5 ( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 21 Convolution examples

Original Bike blurred vertically Bike Filter impulse response

⎛ 1 ⎞ ⎜ 1 ⎟ 1 ⎜ ⎟ ⎜ [1] ⎟ 5 ⎜ 1 ⎟ ⎜ ⎟ ⎝ 1 ⎠

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 22 Integral image

j[x, y]= j[x, y −1]+ f [x, y] i[x, y]= i[x −1, y]+ j[x, y]

x y f [x, y] i[x, y]= ∑∑ f [u,v] u=0 v=0

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 23 Box filtering with integral image

B D

C A

Sum = A + B – C – D

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 24 Gaussian filtering by repeated box filtering

N times

Variance σ2 σ 12 / N

n Approximate convolution with Gaussian kernel by convolution with box kernel, repeated N times n Convolution with box kernel can be computed efficiently using integral image

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 25 Gaussian filtering by repeated box filtering

Direct implementation: 6561 multiplications and 6560 additions per pixel

x-y separable filtering: 162 multiplications and 160 additions per pixel

Original image Gaussian filtered 500x500 σ = 20, 81x81 kernel 20 additions or subtractions per pixel

Box filtered Box filtered Box filtered Box filtered after N = 1 after N = 2 after N = 3 after N = 4

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 26 1-d discrete-time

n Given a 1-d sequence s k , k ∈Z = ,−1,0,1,2,3, [ ] {… …} n Fourier transform ∞ jω − jωk S (e ) = ∑ s⎣⎡k ⎦⎤e ω ∈ℜ k=−∞ n Fourier transform is periodic with 2π n Inverse Fourier transform

π 1 jω jωk s⎣⎡k ⎦⎤ = S (e ) e dω 2π ∫−π

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 27 2-d discrete-space Fourier transform

n Given a 2-d array of image samples s[m,n] , m,n ∈Z2 n Fourier transform ∞ ∞ j jω − jω m− jω n S e ω x ,e y = s⎡m,n⎤e x y ω ,ω ∈ℜ2 ( ) ∑ ∑ ⎣ ⎦ x y m=−∞ n=−∞ n Fourier transform is 2π-periodic both in ω x and ω y n Inverse Fourier transform

1 π π j jω jω m+ jω n s m,n S e ω x ,e y e x y d d ⎣⎡ ⎦⎤ = 2 ω x ω y 4π ∫−π ∫−π ( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 28 Fourier transform – interesting properties

n DFT matrix is orthonormal

n conceptually write as DFT-matrix vector multiplication O(N^2) but in practice use FFT O(NlogN)

n FT of symmetric function is always real; FT of real function is always symmetric

n convolution theorem is super useful:

x ∗ g = F −1 {F{x}⋅ F{g}}

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 29 Discrete Fourier Transform!

• What is this?! Filtering – Low-pass Filter!

• low-pass filter: convolution in primal domain! b = x ∗c x c b *

small! kernel! = Filtering – Low-pass Filter! F b = F x ⋅ F c • low-pass filter: multiplication in ! { } { } { }

.

big!

= Filtering – Low-pass Filter! F b = F x ⋅ F c • low-pass filter: hard cutoff! { } { } { }

.

= Filtering – Low-pass Filter!

• Bessel function of the first kind or “jinc”!

F −1 { }

imagemagick.org Filtering – Low-pass Filter!

• hard frequency filters often introduce ringing!

ß Filtering – High-pass Filter!

• sharpening (possibly with ringing, but don’t see any here)!

ß Filtering – Unsharp Masking!

• sharpening (without ringing): unsharp masking, e.g. in Photoshop!

b = x *(δ − clowpass _ gauss ) = x − x *clowpass _ gauss

or!

b = x *(δ + chighpass ) = x + x *chighpass Filtering – Band-pass Filter!

ß Filtering – Oriented Band-pass Filter!

• edges with specific orientation (e.g., hat) are gone!!

ß Optical Filtering with Fourier Optics!

• can do all of this optically (with coherent light)! ! • Fourier optics – not part of this course!

http://en.wikipedia.org/wiki/Fourier_optics! Image Downsampling (& Upsampling) !

• “anti-aliasing” à before re-sampling, apply appropriate filter!!

• how much filtering? Nyquist-Shannon sampling theorem: !

fs ≥ 2 fmax Other Forms of Aliasing!

• wagon wheel effect ! (temporal aliasing):! =jHS9JGkEOmA ! watch?v / youtube.com Other Forms of Aliasing!

• wagon wheel effect (temporal aliasing)!

• sampling frequency was lower than ! 2 fmax

wikipedia! Other Forms of Aliasing! • photography – optical AA filter removed (“hot rodding” camera)!

John Shafer! mosaicengineering.com! Other Forms of Aliasing! • photography – optical AA filter removed (“hot rodding” camera)!

without AA filter! with AA filter (standard)!

maxmax.com! Other Forms of Aliasing! • photography – optical AA filter removed (“hot rodding” camera)!

without AA filter! with AA filter (standard)!

maxmax.com! 5x5 box filter revisited

Original Bike blurred by convolution Bike Impulse response „box filter“

⎛ 1 1 1 1 1 ⎞ ⎜ 1 1 1 1 1 ⎟ 1 ⎜ ⎟ ⎜ 1 1 [1] 1 1 ⎟ 25 ⎜ 1 1 1 1 1 ⎟ ⎜ ⎟ ⎝ 1 1 1 1 1 ⎠

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 47 Frequency response of 5x5 lowpass filter

∞ ∞ j j m j n jω x ω y − ω x − ω y H (e ,e ) = ∑ ∑ h⎣⎡m,n⎦⎤e m−∞ n=−∞ 2 2 2 2 1 − jω m− jω n 1 j m − jω n = ∑ ∑ e x y = ∑ e− ω x ∑ e y 25 m=−2 n=−2 25 m=−2 n=−2 1 1 1 2cos 2cos(2 ) 1 2cos 2cos(2 ) = ( + ω x + ω x ) + ω y + ω y 0.8 25 ( )

0.6

0.4

0.2 Separable filter: 1-d frequency responses 0 are multiplied 2 3 2 0 1 0 ω -1 y -2 -2 ω -3 x

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 48 Horizontal lowpass filter

j jω 1 H e ω x ,e y 1 2cos 2cos(2 ) = ( + ω x + ω x ) ( ) 5

1

0.8

0.6

0.4

0.2

0

2 Bike blurred horizontally 3 2 0 1 Filter impulse response 0 ω y -2 -1 -2 ω x 1 -3 1 1 [1] 1 1 5 ( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 49 Vertical lowpass filter

j jω 1 H e ω x ,e y 1 2cos 2cos(2 ) = ( + ω y + ω y ) ( ) 5

1

0.8

0.6

0.4

0.2

0

2 Bike blurred vertically 3 2 0 1 Filter impulse response 0 ω y -2 -1 -2 ω x ⎛ 1 ⎞ -3 ⎜ 1 ⎟ 1⎜ ⎟ ⎜ ⎣⎡1⎦⎤ ⎟ 5⎜ ⎟ ⎜ 1 ⎟ ⎜ 1 ⎟ ⎝ ⎠ Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 50 Sharpening filter

Original Bike sharpened Bike Filter impulse response

⎛ 0 −1 0 ⎞ 1 ⎜ −1 [8] −1 ⎟ 4 ⎜ ⎟ ⎝⎜ 0 −1 0 ⎠⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 51 Frequency response of sharpening filter

∞ ∞ j j m j n jω x ω y − ω x − ω y 3 H (e ,e ) = ∑ ∑ h⎣⎡m,n⎦⎤e m−∞ n=−∞ 2.5 1 j j − jω jω = 8 − e− ω x − e ω x − e y − e y 2 4 ( )

1.5 1 1 = 2 − cosω x − cosω y 2 2 1 4 2 4 0 2 0 ω y -2 -2 -4 -4 ω x

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 52 More aggressive sharpening

j jω H e ω x ,e y = 5− 2cosω − 2cosω ( ) x y

10

8

6

4

2

0 Bike sharpened 4 2 4 Filter impulse response 0 2 0 ω -2 y -2 ω ⎛⎞010− -4 -4 x ⎜⎟15 1 ⎜⎟−−[ ] ⎜⎟ ⎝⎠010−

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 53 Zoneplate pattern to visualize frequency plane

Equation to generate pattern: 2 2 s(x, y) = sˆcos(ax x + ay y ) + s0 Local frequency at (x, y) ∂ a x2 + a y2 = 2a x ∂x ( x y ) x ∂ a x2 + a y2 = 2a y ∂y ( x y ) y x

interpolation s⎡x, y⎤ ⎯⎯⎯⎯→s(x, y) ⎣ ⎦←⎯sam⎯pling⎯⎯

y

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 54 Sampling interpretation of 2-d discrete-space Fourier transform

n How is the Fourier transform of s[m,n] related to the Fourier transform of the continuous signal ∞ ∞ s x, y s m,n x m, y n ( ) = ∑ ∑ "! $# δ 2 ( − − ) m=−∞ n=−∞

„continuous“ continuous delta function discrete

n Continuous-space 2-d Fourier transform

∞ ∞  j x j y S ω ,ω = s⎡m,n⎤ δ x − m, y − n e− ω x − ω y dx dy ( x y ) ∫ ∫ ∑ ∑ ⎣ ⎦ 2 ( ) x y m=−∞ n=−∞ ∞ ∞ j m j n j − ω x − ω y jω x ω y = ∑ ∑ s⎣⎡m,n⎦⎤e = S (e ,e ) m=−∞ n=−∞

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 55 Lowpass filtering

Original Zoneplate (512x512) Lowpass filtered with 5x5 box filter

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 56 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 57 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 58 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 59 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 60 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 61 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 62 Zoneplate demonstration: 1-d sampling of 2-d signals

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 63 Horizontal/vertical 2:1 subsampling without prefiltering

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 64 Horizontal/vertical 2:1 subsampling with prefiltering

2d impulse response Frequency response ⎛ 1 1 1 ⎞ 1 ⎜ 16 8 16 ⎟ ⎜ ⎟ ⎜ 1 1 1 ⎟ ⎜ ⎟ 0.5 8 4 8 |H| ⎜ ⎟ ⎜ 1 1 1 ⎟ ⎝⎜ 16 8 16 ⎠⎟ 0 2 0 2 0 -2 -2 ω y ωx

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 65 Image magnification (10%)

Nearest neighbor interpolation Bilinear interpolation

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 66 Lens as Optical Low-pass Filter!

• point source on focal plane maps to point!

focal plane! Lens as Optical Low-pass Filter!

• away from focal plane: out of focus blur! blurred point !

focal plane! Lens as Optical Low-pass Filter!

• shift-invariant convolution!

focal plane! Lens as Optical Low-pass Filter! diffraction-limited PSF of circular

aperture (aka “Airy” pattern):! c ! b = c∗ x

x b sharp image! measured, blurred image! point spread function (PSF): Deconvolution!

• given measurements b and convolution kernel c, what is x?! c x b * ? = Deconvolution with Inverse Filtering!

−1 −1 ⎧F{b}⎫ • naive solution: apply inverse kernel ! x! = c ∗b = F ⎨ ⎬ F c ⎩ { } ⎭ x x! Deconvolution with Inverse Filtering & Noise!

−1 −1 ⎧F{b}⎫ • naive solution: apply inverse kernel! x! = c ∗b = F ⎨ ⎬ F c ⎩ { } ⎭ x! • Gaussian noise,! σ = 0.05

! Image deconvolution

n Given an image f [x,y] that is a blurred version of original image s[x,y], recover the original image. jω jω n Assume linear shift-invariant blur, B e x ,e y ( )

j jω j jω B e ω x ,e y H e ω x ,e y s[x, y] ( ) f [x, y] ( ) g[x, y] blur recovery filter

n Naive solution: inverse filter

j jω 1 H e ω x ,e y = jω ( ) jω x y B(e ,e ) jω jω n Problem: B e x , e y might be zero, noise amplification ( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 74 Naïve deconvolution

jω jω j jω Original Blurred w/ B e x ,e y Deblurred w/ B−1 e ω x ,e y ( ) ( )

+ white noise rms = 2.5

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 75 Deconvolution with Inverse Filtering & Noise!

• results: terrible! !

• why? this is an ill-posed problem (division by (close to) zero in frequency domain) à noise is drastically amplified!!

• need to include prior(s) on images to make up for lost data! • for example: noise statistics (signal to noise ratio) ! Deconvolution with Wiener Filtering!

• apply inverse kernel and don’t divide by 0 !

⎧ 2 ⎫ −1 ⎪ F{c} F{b}⎪ x! = F ⋅ ⎨ 2 1 ⎬ ⎪ F{c} + F{c} ⎪ ⎩ SNR ⎭

amplitude-dependent ! mean signal ≈ 0.5 SNR = damping factor!! noise std = σ Deconvolution with Wiener Filtering!

naive! Wiener! x x! Deconvolution with Wiener Filtering!

σ = 0.01 σ = 0.05 σ = 0.1 Deconvolution with Wiener Filtering!

• results: not too bad, but noisy !

• this is a heuristic à dampen noise amplification!

• take EE 367 “Computational Imaging and Display” for more advanced deconvolution! Nonlinear noise reduction/sharpening

n Noise reduction: smooth the image, lowpass filtering n Deblurring: sharpen edges, highpass filtering n How can both be achieved simultaneously? n Key insight: large amplitude of highpass filtered image indicates presence of edge

α f "x, y$ ( h # %) HPF

jωx jωy

Ze, e f x, y ( ) - ⎡ ⎤ h ⎣ ⎦ f ⎡x, y⎤ h ⎣ ⎦ f [x, y] + g[x, y] ∑ ∑

n Can be extended to multiple HPFs

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 81 Nonlinear noise reduction/sharpening (cont.)

HPF Soft coring α fi "x, y$ jω jω ( # %)

Z e x ,e y (.) 1 f ⎡x, y⎤ ( ) - 1 ⎣ ⎦ f [x, y] + g[x, y] ∑ ∑ f ⎡x, y⎤ - i ⎣ ⎦ HPF Soft coring j jω ω x y f ⎡x, y⎤ Z e ,e 2 ⎣ ⎦ (.) 2 ( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 82 Nonlinear noise reduction/sharpening example

blurred, noisy image noise-reduced and sharpened

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 83 Highpass filtered images

log magnitude of log magnitude of log magnitude of log magnitude of image filtered with image filtered with image filtered with image filtered with ⎛ 0 0 0 ⎞ ⎛0 − 0.5 0⎞ ⎛− 0.5 0 0 ⎞ ⎛ 0 0 − 0.5⎞ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜− 0.5 [1] − 0.5⎟ ⎜0 [1] 0⎟ ⎜ 0 [1] 0 ⎟ ⎜ 0 [1] 0 ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎝ 0 0 0 ⎠ ⎝0 − 0.5 0⎠ ⎝ 0 0 − 0.5⎠ ⎝− 0.5 0 0 ⎠

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 84 Soft coring function

γ f ⎡x,y⎤ ⎛ − i ⎣ ⎦ ⎞ τ α f ⎡x, y⎤ = m⋅ f ⎡x, y⎤⋅⎜1− e ⎟ ( i ⎣ ⎦) i ⎣ ⎦ ⎜ ⎟ ⎝ ⎠ Example: m = 3 slope of linear part γ = 2 transition between suppression and linear τ = 10 width of suppressed area α f ⎡x, y⎤ ( i ⎣ ⎦)

f ⎡x, y⎤ i ⎣ ⎦ Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 85 Soft coring of highpass filtered images

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 86 Linear vs. nonlinear noise reduction/sharpening

Noise reduction by Sharpening by highpass Combined noise reduction and lowpass filter (linear) filter (linear) sharpening (nonlinear)

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Linear Image Processing and Filtering 87