part 2: image enhancement in the spatial...

72
2011-04-12 Digital Image Processing Achim J. Lilienthal AASS Learning Systems Lab, Dep. Teknik Room T1209 (Fr, 11-12 o'clock) [email protected] Course Book Chapter 3 Part 2: Image Enhancement in the Spatial Domain

Upload: others

Post on 10-Jan-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2011-04-12

Digital Image Processing

Achim J. Lilienthal

AASS Learning Systems Lab, Dep. Teknik

Room T1209 (Fr, 11-12 o'clock)

[email protected]

Course Book Chapter 3

Part 2: Image Enhancement

in the Spatial Domain

Page 2: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

1. Image Enhancement in the Spatial Domain

2. Grey Level Transformations

3. Histogram Processing

4. Operations Involving Multiple Images

5. Spatial Filtering

Contents

Page 3: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering

→ Contents

Page 4: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Neighbourhood Relations Between Pixels a pixel has 4 or 8 neighbours in 2D

depending on the neighbour definition: 4-neighborhood

each neighbor must sharean edge with the pixel

8- neighborhood each neighbor must share an edge or a corner with the pixel

Page 5: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Basics of Spatial Filtering the pixel value in the output image

is calculated from a local neighbourhood in the input image

the local neighbourhood is described by a mask with a typical size of 3x3, 5x5, 7x7, … pixels

filtering is performed by moving the mask over the image

the centre pixel in the output image is given a value that depends on the input image and the weights of the mask

Page 6: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Basics of Spatial Filtering filter subimage defines

coefficients w(s,t)

used to updatepixel at (x,y)

111

11

1

111

Page 7: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering filter subimage defines

coefficients w(s,t)

response of the filterat point (x,y) is givenby a sum of products

also called convolution(convolution kernel)

∑∑−= −=

++=a

as

b

bttysxftswyxg ),(),(),(

(1,1)(0,1)(-1,1)

(1,0)(0,0)(-1,0)

(1,-1)(0,-1)(-1,-1)

Page 8: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering – Implementation generic code:

How to Deal With the Border? limit excursion of the centre of the mask → smaller image

set outside pixel value zero → border effects

mirroring border pixel values → border effects

modify filter size along the border → slower

for P(x,y) in imagefor F(u,v) in filterQ(x,y) += F(u,v) × P(x-u,y-v)

endend

Page 9: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters (Averaging Filters) for blurring

removal of small (irrelevant) details, bridging small gaps

for noise reduction but: edges are also blurred

Page 10: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters (Averaging Filters) for blurring

removal of small (irrelevant) details, bridging small gaps

for noise reduction

Smoothing Spatial Filters – 3x3 Mean Filter / Box Filter need for normalization

to conserve the total “energy” of the image (sum of all greylevels)

can cause "ringing" no good model of blurring in a defocused camera

turns a single "point" into a "box"

111

111

111

x 1/9

Page 11: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Mean Filter

original Mean 5x5 Mean 11x11

Page 12: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering in Matlab

filter matrix w filtering modes

'corr' or 'conv' only important in the case of asymmetric filters 'corr' (no mirroring) is the default

f = imread('bubbles.tif');g = imfilter(f, w,

filtering_mode,boundary_options,size_options);

Page 13: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering in Matlab

boundary options P – padding with 0 (default) 'replicate' – replicate values at the outer border 'symmetric' – mirror reflecting across the outer border 'circular' – repeating the image like a periodic function

f = imread('bubbles.tif');g = imfilter(f, w,

filtering_mode,boundary_options,size_options);

Page 14: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering in Matlab

size options 'same' – same size as the input image (cropped padded image) 'full' – full size of the padded image default is 'same'

f = imread('bubbles.tif');g = imfilter(f, w,

filtering_mode,boundary_options,size_options);

Page 15: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering in Matlabf = imread('bubbles.tif');g = imfilter(f, ones(8)/64, 'replicate'); imshow(g);

720 px

Page 16: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Linear Spatial Filtering in Matlabf = imread('bubbles.tif');g = imfilter(f, fspecial('average',32), 'replicate'); imshow(g);

Page 17: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Mean Filter square box filter generates defects

axis aligned streaks

blocky results

input

output

example from "A Gentle Introduction to Bilateral Filtering and its Applications", Sylvain Paris, Pierre Kornprobst, Jack Tumblin, and Frédo Durand, SIGGRAPH 2008

Page 18: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

box profile

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

unrelated pixelsunrelated pixels related pixels

pixelposition

pixelweight

Page 19: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

strategy to solve problems with box filters use an isotropic (i.e. circular) window

use a window with a smooth falloff

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

box kernel Gaussian kernel

Page 20: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Gaussian Filter weighted average

2D Gaussian kernel

higher weight in the centre to decrease blurring

Why a Gaussian? simple model of blurring

in optical systems

smooth

also a Gaussian in the frequency domain

121

242

121

1/16 x

Page 21: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5 input

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

Page 22: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5 inputbox average

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

Page 23: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5 inputbox average

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

Gaussian blur

Page 24: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Gaussian profile

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

unrelated pixelsunrelated pixels uncertain pixelsuncertain pixels related pixels

pixelposition

pixel weight

Page 25: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Gaussian profile spatial parameter σ

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

small σ large σ

limited smoothing strong smoothing

input

Page 26: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Gaussian profile spatial parameter σ

how to set σ? depends on the application

common strategy: proportional to image size

• e.g. 2% of the image diagonal

• property: independent of image resolution

depends on image content

• smooth "object areas" ⇒ larger σ

• but don't smooth edges ⇒ smaller σ

from "A Gentle Introduction to Bilateral Filtering and its Applications", S. Paris, P. Kornprobst, J. Tumblin, and F. Durand, SIGGRAPH 2008

Page 27: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Median Filter take the values of the input image corresponding

to the desired sub-window (3x3, 5x5,…) sort them take the middle value (example: 3x3 → the 5th largest) forces pixels with distinct grey levels

to be more like their neighbours very good at reducing salt-and-pepper noise less blurring than linear filters of the same size

Page 28: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Median Filter take the median value over the sub-window

Average 3x3 Median 3x3X ray image of a circuit board

Page 29: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Median Filter in Matlab

original image median 8x8 median 32x32 median 32x2

f = imread('bubbles.tif');g = medfilt2(f, [32 32]); imshow(g);

Page 30: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Median Filter take the median value over a sub-window

original image median 3x3 median 5x5 median 11x11

Page 31: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Smoothing Spatial Filters – Median Filter take the values of the input image corresponding

to the desired sub-window (3x3, 5x5,…) sort them take the middle value (example: 3x3 → the 5th largest) forces pixels with distinct grey levels

to be more like their neighbours very good at reducing salt-and-pepper noise less blurring than linear filters of the same size nonlinear filter (order statistics filter) no equivalent in the frequency domain (order statistics filter)

Page 32: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Order Statistics Filters (Fractile Filters) median

min, max useful in mathematical morphology

percentile generalization of median, min, max

128

542

731

1 1 2 2 3 4 5 7 8

min (0%)

25% percentile

median (50%) max (100%)

Page 33: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Order Statistics Filters (Fractile Filters) median

min, max useful in mathematical morphology

percentile generalization of median, min, max

order statistics filters are nonlinear filters

order statistics filters do not have an equivalent in the frequency domain

Page 34: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters highlight fine detail (also noise)

enhance edges

use image differentiation (1st order)

( , ) ( , )limf f x y f x yx ε

εε→∞

∂ + −=

Page 35: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters highlight fine detail (also noise)

enhance edges

use image differentiation (1st order)

( , ) ( , )limf f x y f x yx ε

εε→∞

∂ + −=

∂ 1, ,i j i jf f fx +∂

≈ −∂

Page 36: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters highlight fine detail (also noise)

enhance edges

use image differentiation

Sharpening Spatial Filters – 1D approximation to 1st Order Derivation

equivalent to the 1D convolution mask

)()1( xfxfxf

−+≈∂∂

000

1-10

000

Page 37: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters highlight fine detail (also noise)

enhance edges

use image differentiation

Sharpening Spatial Filters – 1D approximation to 1st Order Derivation

equivalent to the 1D convolution mask

( 1) ( 1)f f x f xx∂

≈ + − −∂

000

10-1

000

Page 38: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Gradient and Magnitude of the Gradient

Sharpening Spatial Filters – Based on the Gradient Roberts

Prewitt

Sobel

yf

xf

yf

xff

∂∂

+∂∂

∂∂

+

∂∂

=∇22

∂∂

∂∂

=∇yf

xff ,

Page 39: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters Prewitt gradient edge detector

2 masks approximate | Gx | and | Gy | in yx GGyf

xff +=

∂∂

+∂∂

≈∇

10-1

10-1

10-1

1-1-1

000

111

Page 40: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters Sobel Operators

2 masks approximate | Gx | and | Gy | in

detects horizontal and vertical edges

10-1

20-2

10-1

-1-2-1

000

121

yx GGyf

xff +=

∂∂

+∂∂

≈∇

Page 41: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Sobel Operators weight 2 is supposed to smooth by emphasizing the centre

10-1

20-2

10-1

1-2-1

000

121

Page 42: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Sobel Operators detection of vertical dark-light edges

10-1

20-2

10-1

Page 43: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Sobel Operators combination of all the directional responses

Page 44: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters comparison between Sobel and Prewitt operator

Sobel (~ |Gx| + |Gy|) Prewitt (~ |Gx| + |Gy|)

Page 45: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters Roberts (cross gradient operators)

2 masks approximate | Gx | and | Gy | in

10

0-1

01

-10

yx GGyf

xff +=

∂∂

+∂∂

≈∇

Page 46: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters highlight fine detail (also noise)

enhance edges

uses image differentiation

Sharpening Spatial Filters – 1D approximation to 1st order derivation

approximation to 2nd order derivation

equivalent to the 1D convolution mask000

1-21

000)(2)1()1(2

2

xfxfxfx

f−−++=

∂∂

Page 47: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Laplace Filter Laplacian (second order derivative)

2

2

2

22

yf

xf

∂∂

+∂∂

=∇ )(2)1()1(2

2

xfxfxfx

f−−++=

∂∂

Page 48: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Laplace Filter Laplacian (second order derivative)

filter masks to implement the Laplacian add the "digital implementation"

of the two terms in the Laplacian(90° rotation symmetry)

2

2

2

22

yf

xf

∂∂

+∂∂

=∇

010

1-41

010

)(2)1()1(2

2

xfxfxfx

f−−++=

∂∂

Page 49: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Laplace Filter Laplacian (second order derivative)

filter masks to implement the Laplacian add the "digital implementation"

of the two terms in the Laplacian(90° rotation symmetry)

add also diagonal terms(45° rotation symmetry)

2

2

2

22

yf

xf

∂∂

+∂∂

=∇

010

1-41

010

111

1-81

111

)(2)1()1(2

2

xfxfxfx

f−−++=

∂∂

Page 50: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Laplace Filter Laplacian (second order derivative)

filter masks to implement the Laplacian add the "digital implementation"

of the two terms in the Laplacian(90° rotation symmetry)

add also diagonal terms(45° rotation symmetry)

negative values → re-scale

2

2

2

22

yf

xf

∂∂

+∂∂

=∇

010

1-41

010

111

1-81

111

)(2)1()1(2

2

xfxfxfx

f−−++=

∂∂

Page 51: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Laplace Filter detection of edges independent of direction

isotropic with respect to 90° rotations

0-10

-14-1

0-10

Page 52: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Laplace Filter Laplace filter + original image ⇒ sharpening

0-10

-15-1

0-10

Page 53: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters Laplace filter + original image ⇒ sharpening

Page 54: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – 2nd order vs. 1st order Laplacian (second order derivative)

thinner edges

not so strong response to a step

better response to fine details

double response to edges

rotation independent ⇒ one mask for all edges

2

2

2

22

yf

xf

∂∂

+∂∂

=∇ )(2)1()1(2

2

xfxfxfx

f−−++=

∂∂

Page 55: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters – Unsharp Masking analog equivalent used in publishing industry

basic idea: subtract blurred version of an image from original image to generate the edges

Page 56: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. Lilienthal

Spatial Filtering5

Sharpening Spatial Filters in Matlabf = imread('bubbles.tif');g1 = imfilter(f, fspecial('laplacian',0.5)); g2 = imfilter(f, fspecial('unsharp', 0.5));% ...

Page 57: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Achim J. LilienthalAASS Learning Systems Lab, Örebro University

Page 58: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Agenda

1. Image Smoothing Revisited

2. Bilateral Filtering

3. Applications of Bilateral Filtering

4. Efficient ImplementationHeavily based on: "A Gentle Introduction to Bilateral Filtering and its Applications", Sylvain Paris, Pierre Kornprobst, Jack Tumblin, and Frédo Durand, SIGGRAPH 2008, see http://people.csail.mit.edu/sparis/siggraph07_courseand "Bilateral Filtering for Gray and Color Images", C. Tomasi, R. Manduchi, Proc. Int. Conf. Computer Vision

Page 59: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Agenda

Image Smoothing Revisited

Page 60: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

1 Image Smoothing Revisited

General Strategy for Smoothing Images adjacent pixels tend to belong to the same object

images typically vary slowly over space

non-smoothness due to noise

noise values less correlated than the signal

smoothing = making adjacent pixels look more similar smoothing strategy: pixel average over its neighbors

however, basic assumption not true at edges

we are interested in edge preserving image smoothing

Page 61: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

1 Image Smoothing Revisited

Mean Filter Profile

unrelated pixelsunrelated pixels related pixels

pixelposition

pixelweight

Page 62: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

1 Image Smoothing Revisited

Gaussian Filter Profile

unrelated pixelsunrelated pixels uncertain pixelsuncertain pixels related pixels

pixelposition

pixel weight

Page 63: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

1 Image Smoothing Revisited

Gaussian Filter linear convolution

weights independent of spatial location

well-known operation

can be computed efficiently

does smooth images but … … smoothes too much: edges are blurred

… only spatial distance matters, no edge term

Page 64: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Agenda

Bilateral Filtering

Page 65: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2 Definition of the Bilateral Filter

Blur from Averaging Across Edges

*

*

*

input output

same Gaussian kernel everywhere

Page 66: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2 Definition of the Bilateral Filter

Bilateral Filter – Limits Averaging Across Edges

input output*

*

*kernel shape depends on image content

[Aurich 95, Smith 97, Tomasi 98]

Page 67: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2 Definition of the Bilateral Filter

Bilateral Filter – The Additional Edge Term again: weighted average of pixels.

space weight

not new

range weight

I

new

normalizationfactor

new

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

please note the different notation: I ↔ f

Page 68: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2 1D Illustration

Bilateral Filter – 1D Illustration 1D image = line of pixels

better visualized as a plot

pixelintensity

pixel position

Page 69: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2 1D Illustration

space

space rangenormalization

Gaussian blur

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Bilateral filter[Aurich 95, Smith 97, Tomasi 98]

space

spacerange

p

p

q

q

( )∑∈

−=S

IGIGBq

qp qp ||||][ σ

Page 70: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

Is This a Linear Filter?

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Bilateral Filtering2

Page 71: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

No! BF[I1]p + BF[I2]p ≠ BF[I1+I2]p

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

Bilateral Filtering2

Page 72: Part 2: Image Enhancement in the Spatial Domain130.243.105.49/Research/Learning/courses/dip/2011/lectures/DIP_2011_L04.pdffor blurring removal of small (irrelevant) details, bridging

2 2D Illustration

qp

output input

( ) ( )∑∈

−−=S

IIIGGW

IBFq

qqpp

p qp ||||||1][rs σσ

p

reproduced from [Durand 02]