image enhancement - kth · 2013-11-18 · image enhancement dd2423 image analysis and computer...

43
Image Enhancement DD2423 Image Analysis and Computer Vision arten Bj¨ orkman Computational Vision and Active Perception School of Computer Science and Communication November 15, 2013 arten Bj¨ orkman (CVAP) Image Enhancement November 15, 2013 1 / 43

Upload: others

Post on 31-May-2020

15 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Image EnhancementDD2423 Image Analysis and Computer Vision

Marten Bjorkman

Computational Vision and Active PerceptionSchool of Computer Science and Communication

November 15, 2013

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 1 / 43

Page 2: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Image enhancement by filtering

Primary goal: noise removalRequirement: preserve relevant informationIt may be difficult to define “relevant information”, since it dependson the task, environment, etc.

Approaches:Noise is identifiable

remove and interpolateNoise is not identifiable

image averaging, low-pass filteringmedian filteringmin/max filtering

Contrast augmentationhigh-pass filtering

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 2 / 43

Page 3: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Spatial filtering

Use of spatial masks for filtering is called spatial filtering.May be linear or nonlinear.Linear filters can be:

Lowpass: eliminate high frequency components such ascharacterized by egdes and sharp details in an image.⇒ Net effect is image blurring.Highpass: eliminate low frequency components such as slowlyvarying characteristics (shadings).⇒ Net effect is sharpening of edges and other details (also noise).Bandpass: eliminate outside a given frequency range.⇒ Combination of the above. Common in practice.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 3 / 43

Page 4: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Spatial filtering (examples)

Some filters in frequency domain and corresponding spatial filter masks.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 4 / 43

Page 5: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Exercise

Assume you have a filter kernel [1,0,−1]. How does this look likein the Fourier domain? Is it a lowpass, highpass or bandpassfilter?

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 5 / 43

Page 6: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Exercise

Assume you have a filter kernel [1,0,−1]. How does this look likein the Fourier domain? Is it a lowpass, highpass or bandpassfilter?Answer: To see this we have to express the filter in continuousdomain, which we can do with Dirac functions.

f (x) = δ(x)−δ(x−2)

To get the Fourier Transform we exploit the sifting property ofDirac functions.

f (u) =∫

xf (x)e−iuxdx = 1−e−2iu = e−iu(eiu−e−iu) = 2ie−iu sin(u)

‖f (u)‖= 2‖sin(u)‖

Since ‖f (0)‖= ‖f (π)‖= 0 and ‖f (π/2)‖= 2, it is a bandpass filter.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 6 / 43

Page 7: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Different kinds of noise

Noise is the result of errors in the image acquisition that result inpixel values that do not reflect the true intensities of the real scene(scanning devices, CCD detector, transmission)Signal independent additive noise (sampling noise)

g = f + ν

Signal dependent multiplicative noise (illumination variations)

g = f + νf = (1 + ν)f

Measurement noise (salt and pepper)

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 7 / 43

Page 8: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Linear smoothing - Averaging

Idea: Average over K data points and reduce variance ofuncorrelated noise by factor of K.Ensemble average:

F1, . . . ,FK → →G

F1, . . . ,Fk represents several almost identical images (severalimages of the same static scene).

G(x) =1K

K

∑k=1

Fk (x)

N(µ,σ2) {one image}N(K µ,K σ

2) {sum of K images}N(µ,σ2/K ) {average of K images}

+ Excellent method (e.g. with poor cameras)- Requires time (and static scenes) - not always possible

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 8 / 43

Page 9: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Image averaging

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 9 / 43

Page 10: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Local spatial averaging / Mean filtering

Let N(x) represent neighborhood of a point x and

G(x) = ∑η∈N(x)

CηF (x−η)

Often ∑Cη = 1, Example: N = N8,Cη = 19 gives

[ 19

19

19

19

19

19

19

19

19

]Two main problems with mean filtering:

A single pixel can significantly affect the mean value of all thepixels in its neighborhood (errors are spread).It blurs edges - a problem if we require sharp edges in the output.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 10 / 43

Page 11: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Local spatial averaging (continue)

Common requirements:Coefficients should sum up to 1.Symmetric up/down and left/right.Center pixel has most influence on output.Filter should be separable.

These result in:

Cη =

(∆t2

1−∆t∆t2

)( ∆t

2 1−∆t ∆t2 ) =

∆t24

∆t2 (1−∆t) ∆t2

4∆t2 (1−∆t) (1−∆t)2 ∆t

2 (1−∆t)∆t2

4∆t2 (1−∆t) ∆t2

4

Special case: ∆t = 12 gives

116

18

116

18

14

18

116

18

116

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 11 / 43

Page 12: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Basic idea

Most information in images is concentrated at low frequencies.Noise is uniformly distributed over all frequencies (white noise).⇒ Suppress high frequency.Different filters have different qualities in Fourier space.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 12 / 43

Page 13: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Ideal low pass filter

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 13 / 43

Page 14: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Ideal low pass filter

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 14 / 43

Page 15: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Butterworth low pass filter

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 15 / 43

Page 16: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Butterworth low pass filter (continue)

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 16 / 43

Page 17: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Butterworth low pass filter (continue)

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 17 / 43

Page 18: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Good compromise: Gaussian low-pass filter

g(x ,y ;σ2) =

12πσ2 e−(x2+y2)/2σ2

g(u,v ;σ2) = e−σ2(u2+v2)/2

where (u2 + v2) = squared distance from the origin.The parameter measures spread of Gaussian curve. Smaller thevalue, the larger the cutoff frequency and milder the filtering.When (x2 + y2) = σ2, the filter is at 0.607 of its maximum value.

Note: Gaussian in spatial domain and Gaussian in frequency.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 18 / 43

Page 19: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Binomial kernels

The filter ( ∆t2 ,1−∆t , ∆t

2 ) can for ∆t = 12 be written

(14,12,14

) =14

(1,2,1) =12

(1,1)∗ 12

(1,1)

Repeated use of (1,1) kernels gives rise to Pascal’s triangle.1

1 11 2 1

1 3 3 11 4 6 4 1

1 5 10 10 5 11 6 15 20 15 6 1

11/21/41/81/161/321/64

coefficients normalizationfactors

Central limit theorem⇒ kernels approach Gaussian kernels.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 19 / 43

Page 20: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Image averaging: Average vs. Gaussian

Original Average Gaussian

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 20 / 43

Page 21: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Non-linear filtering

Nonlinear spatial filters also operate on neighborhoods.Operations are based directly on pixel values in neighborhood.They do not explicitly use coefficient values as in filter masks.Purpose: Incorporate prior knowledge to avoid destructivebehavior, typically at edges and corners.Basic methods:- median filtering- min/max filtering- selective averaging- weighted averaging

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 21 / 43

Page 22: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Anisotropic smoothing

Anisotropic smoothing: smooth differently in different directions,usually in order to preserve edges.Idea: smooth pixels based on similarity s(p,q) between pixels.

p′ = ∑q ·s(p,q)

∑s(p,q)

Similarity s(p,q) can be measured in colour, position, etc.Examples:

s(p,q) = e( p−qK )2

, s(p,q) =1

1− (p−qK )2

Problems: Different kernels at different positions⇒ Impossible toanalyse in frequency space.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 22 / 43

Page 23: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Anisotropic smoothing

Note: the image is smoother, but individual hairs are not blurred out.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 23 / 43

Page 24: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Median filtering

G(m) = mediank∈N(m) F (k)

Properties:+ Preserves the value in 1D monotonic structures (shading).+ Preserves the position of 1D step edges.+ Eliminates local extreme values (e.g. salt-and-pepper).- Creates painting-like images.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 24 / 43

Page 25: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Median filtering - example

Original med5x5 mean5x5

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 25 / 43

Page 26: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Min/max filtering

Suppress bright areas on dark background (or vice versa)

G(m) = mink∈Nm

F (k)

Properties:bright areas decreaseisolated bright points disappear

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 26 / 43

Page 27: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Sharpening

Purpose: Enhance local contrast, highlight fine details.Methods:- Unsharp masking- High-pass filtering (spectral)- Differentiation (first and second order derivatives)Common desirable property:- Isotropy (rotational invariance)Common problems:- Differentiation and high-pass filtering enhance noiseDifference compared to grey-level transformations:- Spatial variations are taken into account

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 27 / 43

Page 28: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Easiest way: unsharp masking

Idea: “subtract out the blur”Blur image→ subtract from original→ weight→ add to original

g(x ,y) = f (x ,y) + α(f (x ,y)− f (x ,y))

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 28 / 43

Page 29: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

High-pass filters

Sharpening with a high-pass filter:

G(u,v) = F (u,v) + α(Hhp(u,v)F (u,v))

Quite similar to unsharp masking, but in Fourier domain.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 29 / 43

Page 30: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

High-pass filters

Results with ideal (top), Butterworth (middle) and Gaussian (bottom) filters.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 30 / 43

Page 31: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Differentiation

Requirements for a first order derivative operator:1. zero in flat areas2. non-zero along ramp signals of constant slope3. non-zero in the onset and end of a gray-level step or rampRequirements for a second order derivative operator:1. zero in flat areas2. zero along ramp signals of constant slope3. non-zero at the onset and end of a gray-level step or ramp

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 31 / 43

Page 32: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

First and Second order derivative

Basic definition of a first order x-wise derivative operator:

fx = f (x + 1,y)− f (x ,y)

Similarly, a first order y-size derivative fy can be defined.More common in practice (derivative at x , not x + 0.5):

fx =12

(f (x + 1,y)− f (x−1,y))

Second order x-wise derivative operator:

fxx = f (x + 1,y) + f (x−1,y)−2f (x ,y)

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 32 / 43

Page 33: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Derivatives

f 5 5 4 3 2 1 0 0 0 6 0 ... 0 0 7 7 7 7fx -1 -1 -1 -1 -1 0 0 6 -6 0 ... 0 7 0 0 0

fxx -1 0 0 0 0 1 0 6 -12 6 ... 0 7 -7 0 0

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 33 / 43

Page 34: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Derivatives

Along a ramp fx is non-zero, while fxx is zero.fxx enhances final details than fx (but also enhances noise).Magnitude of fx can be used to detect edges.fxx produces two values for every edge (positive and negative).Sign of fxx tells whether a pixel near an edge is dark or white.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 34 / 43

Page 35: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Examples of differentiation operators

We are interested in filters whose response is independent of thedirection of discontinuities in the image.Isotropic filters are rotationally invariant: rotating the image andthen applying the filter is the same as applying the filter first andthen rotating the image.Gradient: ∇f = (fx , fy )

First order, linear, non-isotropic

Gradient magnitude: | ∇f |=√

f 2x + f 2

y

First order, non-linear, isotropicLaplacian: ∇2f = fxx + fyy

2nd order, linear, isotropic

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 35 / 43

Page 36: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Laplacian operator

Isotropic: depends only on the distance from origin, not on the angle.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 36 / 43

Page 37: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Laplacian operator

Laplacian in frequency (upper) and spatial (lower) domain.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 37 / 43

Page 38: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Laplacian in action

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 38 / 43

Page 39: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Application of the Laplacian operator

Original image (left), application of Laplacian operator (middle), andsubtraction of the Laplacian from the original image (right).

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 39 / 43

Page 40: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Image restoration

Image degradation model:

originaldegradation

imageavailable

restorationrestoredimage

oib

Task: Use the image degradation model to restore the originalimage as well as possible.Common degradation mechanisms:

smoothing, imaging defectsdefocusing, motion blurnoise (sensor noise, quantization)

Model: linear shift invariant filter; uncorrelated and additive noise.Reality: non-linear shift dependent degradation; correlated andnon-additive noise.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 40 / 43

Page 41: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Inverse filtering

f → ∗h → g = h ∗ f

f → h → g = h f

How to recreate f from g ?Formally simple. Let

h′ =1h⇒ gh′ =

hfh

= f (inverse filtering)

Problems:h′ undefined when h(ω) = 0.Inverse Fourier transform of h′ not necessarily convergent.Noise enhanced at frequencies where | h(ω) | is small.

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 41 / 43

Page 42: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Summary of good questions

What are the differences between lowpass, bandpass andhighpass filters?What kind of noise can you have?Why does image averaging work?Why are ideal lowpass filter rarely used in practice?What characteristics does a Gaussian filter have?What is the difference between mean and median filters?How can you do sharpening?How can you approximate a first order derivative?What is a Laplacian?Why is inverse filtering hard?

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 42 / 43

Page 43: Image Enhancement - KTH · 2013-11-18 · Image Enhancement DD2423 Image Analysis and Computer Vision ... Net effect is sharpening of edges and other details (also noise). Bandpass:

Readings

Gonzalez & Woods: Chapters 3.4 - 3.6, 4.7 - 4.10Szeliski Chapters 3.2 and 3.3.1

Marten Bjorkman (CVAP) Image Enhancement November 15, 2013 43 / 43