Digital Image Processing - UGentsanja/ImageProcessingCourse/03b...Digital Image Processing Dr. ir....
Transcript of Digital Image Processing - UGentsanja/ImageProcessingCourse/03b...Digital Image Processing Dr. ir....
Digital Image Processing
Dr. ir. Aleksandra PizuricaProf. Dr. Ir. Wilfried Philips
30 November 2006
Aleksandra.Pizurica @telin.UGent.be Tel: 09/264.3415
Telecommunicatie en Informatieverwerking
UNIVERSITEIT GENT
Telecommunicatie en Informatieverwerking
UNIVERSITEIT GENT
Image Enhancement
03b.3
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Objectives of Image Enhacement
• Image enhancement means enhancement for visual interpretation
• This covers a wide variety of processing methods (e.g., making details better visible, improving contrast, making images sharper,…)
• The evaluation of the results is higly subjective (hence no general theory of image enhancement)
• The main objective of image enhancement is to process an image such that the result is more suitable for a specific application.
• Image enhancement trechniques are highly problem oriented (e.g., a method that enhances well an X-ray image may be unsuitable for a satellite image)
• A possible broad categorization:• Spatial domain enhancement techniques• Frequency domain enhancement techniques
03b.4
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Spatial Domain Enhancement
Spatial domain –- aggregation of image pixels
g(x,y) = T( f(x,y) )
f(x,y) – input image
f(x,y) – output image
T – operator on f defined over some neighborhood of (x,y) image f(x,y)
x
y
origin
(x,y)
3x3 neighborhood of (x,y)
Simplest case: neighborhoud of size 1x1 (a single pixel)In this case T is intensity transformation
s = T( r ) r and s – grey values of f and g, resp., at any position (x,y)
03b.5
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Intensity transformation
Contrast enhancementThe values of r below m are compressed into a narrow range of s towards black. The opposite efect for values above m.
Also: a narrow intensity range around m is transformed into a wider intensity range.
r s
80 180
255
r
s
s=T(r)
m
T(r)
rdark
dark
light
light
03b.6
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Contrast enhancement
r s
80 180
255
r
s
r s
110
255
r
slimiting case: thresholding
03b.7
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Basic gray-level transformations
negative
log
n-th root
n-th power
inverse log
Values of the transformation function are typically stored in a one dimensional array.
The mapping from r to s is implemented as a look-up-table
input intensity r
Out
put i
nten
sity
s = T
(r)
identity
Which transformation produces this enhancement?
03b.8
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Image negative
input intensity r
Out
put i
nten
sity
s = T(r)
© 2002 R. C. Gonzalez & R. E. Woods. Courtesy of GE Medical Systems
s = L-1-r r and s – grey values of input and output image, resp., at any position
Input (and output) gray levels are in the range [0, L-1]
Example: enhancement of digital mammograms
original negative
03b.9
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Log transformations
s = c log(1+r) r and s – grey values of input and output image, resp., at any position
Assuming r ≥0 (gray levels are in the range [0, L-1])
input intensity r
outp
ut in
tens
ity
s = T(r) A narow range of low gray-level values in the input image is mapped to a wider range of output values. The opposite is true for higher gray values.
Expands the values of dark pixels. Compresses the values of bright pixels.
Compresses the overall dynamic range. Allows visualisation of images with a large range of pixel values!
03b.10
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Visualisation by Log transform
Log transform is commonly used for visualisation of data that have a big dynamic range, such as
• Fourier spectra• Ultrasound data• Optical Coherence Tomography (OCT) data• Radar images• …
Fourier spectrum After log transform
03b.11
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
0.040.1
0.20.4
0.7
1.52.5
510
25
input intensity r
Out
put i
nten
sity
1
Power low transformations
s = c rγ r and s – grey values of input and output image, resp., at any position
c, γ - positive constants
γ>1 enhancement of details in bright regions
γ<1 enhancement of details in dark regions
03b.12
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
…Power low transformations…
s = rγγ=0.4 γ=4
s = rγ
03b.13
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
…Power low transformations
monitor
γ-correction
monitor
03b.14
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Histogram processing
kk nrh =)(
kr : k-th grey level in the image
kn : number of pixels having gray level kr
Normalized histogramnnrp kk /)( = , n: number of image pixels
p(rk) is an estimate of probability of occurence of gray level rk
• Histograms are simple to calculate in software and hardware
• Provide image statistics
• Useful in image compression, denoising, analysis
03b.15
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Histogram equalization
Conclusion: to flatten (equalize) the histogram, transform the image with its cumulative histogram!
input intensity r
equalized Image
histogram histogram
∑∑==
===k
j
jk
jjkk n
nrprTs
00)()(
This mapping is cumulative histogram
s = T(r)
03b.16
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
local histogramequalization
( 7x7windows)
global histogram
equalization
Local processing
original image
It is often useful to apply intensity transformations locally (within local windows)
In some cases such processing creates artifacts! (e.g., can create non-existing structures in an almost flat background)
03b.17
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
∑Ω∈
++=),(
),(),(),(ts
tysxftsmyxg
1,0,1,:),( −==Ω tstssupport of the mask
Basics of spatial filtering
image f(x,y)
x
y
origin
m(-1,1) m(-1,0) m(-1,1)
m(0,-1) m(0,0) m(0,1)
m(1,1) m(1,0) m(1,1)
filtear mask
)1,1()1,1(...)1,1()1,1(),( ++++−−−−= yxfmyxfmyxg
03b.18
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
7 3 2
0 9 1
1 2 3
Smoothing spatial filtersInput image output image
3 5
0 2
1 1
1 1 2 2 2
1 3 3 2 2
4 33
),( yxb ),( yxg
x
y
2#Ω−1 calculationsper pixel!∑
Ω∈++=
),(),(),(),(
tstsmytxsgyxgCorrelation!:
De index set Ω is the support of m
1,0,1,:),( −==Ω yxyx Ω includes usually (0,0) but not always!
Filter mask),( yxm
1 2 1
2 4 2
1 2 1
116
x
y
© W. Philips, Universiteit Gent, 1998-2006
03b.19
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Example: mean filterOriginal mean over 5x5 window
=
1111111111111111111111111
251M
This filter partly suppresses noise but blurs the edgesNote: this filter is separable
© W. Philips, Universiteit Gent, 1998-2006
03b.20
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Order statistics filters
Order statistics filters are nonlinear spatial filters.
Operation: (1) perform ordering (ranking) the pixels within a filter mask. (2) replace the value of the center pixel by the ranking result
Best known example in this class: median filter
03b.21
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
2
4 3 2
0 9 1
1 2 3
Input image Output image
3 5
0 2
1 1
1 1 2 2 2
1 3 3 2 2
),( yxb ),( yxg
x
y
sorteren 0 1 1 2 2 3 3 4 9
Order statistics filters: Median filter
Basic idea: remove “outliers”The median is a more robust statistical measure than mean
© W. Philips, Universiteit Gent, 1998-2006
03b.22
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
2 9 9 9
Properties of the median filter...2 2 22 9 22 2 2
+removes isolated pulses+preserves uniform areas
2 2 2 2 2 2 2 2 9
-removes thin vertical, horizontal, diagonal lines
2 9 22 9 22 9 2
2 2 2 2 2 2 9 9 9
+preserves “soft” horizontal and vertical edges
+preserves sharp horizontal and vertical edges
2 2 922 2 9
9 9 99
9 9 9
2 3 5 92 2 322 2 3
5 9 99
5 9 9
2 2 92 2 92 2 9
9 9 99 9 99 9 9
2 2 32 2 32 2 3
5 9 95 9 95 9 9
© W. Philips, Universiteit Gent, 1998-2006
03b.23
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
... Properties of the median filter...
+preserves sharp diagonal edges
2 9 92 2 92 2 2
9 9 99 9 99 9 9
2 2 2 2 9 9
2 92 2
9 99 9
-damages corners2 3 3
Some of these problems can be avoided by choosing not-rectangular windows
+preserves “soft” diagonal edges
2 3 52 2 32 2 2
9 9 95 9 93 5 9
2 2 2 2 3 5
2 32 2
5 93 5
2 2 22 2 22 2 3
2 2 22 2 23 3 3
2 2 3 3 3 322 2 2 2
2 3 3 3
© W. Philips, Universiteit Gent, 1998-2006
03b.24
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Removal of impuls noise
median over 3x3
Median filter removes isolated noise peaks,without blurring the image
Impuls noise
© W. Philips, Universiteit Gent, 1998-2006
03b.25
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
... Reduction of impuls noise …
median over 3x3
Median filter removes isolated noise peaks,without blurring the image
Noise-free original
03b.26
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
... Reduction of impulse noise
mean over 3x3 median over 3x3
Linear filters do not take into account impulsive (isolated ) character of the noise and blur the image
The median filter performs in this case much better than the linear filters
03b.27
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Median filter and reduction of white noise
median over 3x3
For not-isolated noise peaks (e.g., white Gaussian noise) median filter is not very efficient.
original
03b.28
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Repeated application of the median filter
Iterating median filter can remove noise better, but flat blobs appear in the image
median over 3x3 median over 3x3, 8x applied
03b.29
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Sharpening spatial filters
• Principal objective: highlight fine detail or enhance image detail
• Often based on the first-order and second-order derivatives
• The derivatives of digital functions are defined in terms of differences
)()1( xfxfxf −+≈∂∂
)(2)1()1(2
2xfxfxf
xf −−++≈
∂∂
• In most applications second-order derivative is better suited for image enhancement
• First-order derivatives are used for edge extraction but also have important use in image enhancement
03b.30
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
),(~yx ffH
Second order derivatives: Laplaciaan…
2
2
2
22
yf
xff
∂∂+
∂∂=∇
),(),(),(),(),(
11
141
++−+++−−≈
yxfyxfyxfyxyxf f
digital implementation
−
010141010
lineair filter with filter mask
Enhancement:),(),(),( 2 yxfyxfyxg ∇−=
03b.31
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Enhancement:),(),(),( 2 yxfyxfyxg ∇−=
… Second order derivatives: Laplaciaan
(b) Laplacian filtered
(c) Image (b) Scaled for
visualisation
difference (a)-(b)
(a) original
03b.32
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Unsharp masking
Subtract a blurred version of an image from image itself
A generalization: high-boost filtering),(),(),( yxfyxAfyxfhb −=
),(),(),( yxfyxfyxfs −=
blurred version of f(x,y)
This can be re-written as
),(),()1(),(),(),()1(),(
yxfyxfAyxfyxfyxfAyxf
s
hb
+−==−+−=
If we choose that the sharp image as:
),(),(),( 2 yxfyxAfyxfhb ∇−=
),(),( 2 yxfyxfs −∇=
03b.33
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
“Unsharp masking” – a usual formulationUnsharp masking : approximate inverse filter for Gaussian PSF with parameter σ :
),(2
),(),( 22
yxfyxfyxg ∇−=σ
This filter amplifies noise. The noise amplification increases when z0increases
2/20 σ=z with
Filter mask:
−−
010141010
000010000
0z
Note: if the noise amplification is a problem, choose z0<σ2/2⇒ blurring increases but not necessarily excessively⇒ less noise amplification
03b.34
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Unsharp masking: example
−−
⇒
010141010
000010000
0zUnsharp masking with z0=0.5
If z0 is bigger (e.g. z0=1) the resulting image is extra sharp
Gaussian filtered (z0=0.5)
Test image 1
Gaussian filtered (z0=0.5) +ruis
Test image 2
03b.35
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Unsharp masking and noise
Test image 1 test image 2
filtered; z0=1
originals
sharper
noisier
Homomorphic filtering
03b.37
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Homomorfische filteringGoal: local contrast enhancement: compensation of spatially varying illumination
log(1+b’(x,y )) high pass filter
0.50.250
0.25
0.5
0.75
fx
H(fx,0)
exp(bl(x,y )-1)bl(x,y )
Illumination model: b’(x,y )=b(x,y )I(x,y ) met b(x,y ) the ideal image and I(x,y ) the not-uniform lighting ⇒ log(b’(x,y ))=log(b(x,y ))+log(I(x,y ))
Assumption: log(I(x,y )) varies slowly w.r.t log(b(x,y ))⇒ remove log(I(x,y )) by high pass filtering log(b’(x,y ))
avoid log(0)
© W. Philips, Universiteit Gent, 1998-2006
03b.38
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Example: homomorphic filter
Remark: •Homomorphic filter is here applied to Y-component; U and V were not changed
original image after filtering
•Truncation of RGB-values <0 en >255
© W. Philips, Universiteit Gent, 1998-2006
03b.39
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Example: homomorphic filter
Homomorphic filter followed by an extra intensitytransform to improve global contrast
original image after filtering
homomor. filter contrast adjust g
g’
© W. Philips, Universiteit Gent, 1998-2006
03b.40
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Filtering in the Fourier domain
2D-DFTof the mask
2D-DFT of an image
2D-DFT of the filtered
image⊗
filtered image
inverseDFT
lkB ,
lkH ,~
© W. Philips, Universiteit Gent, 1998-2006
03b.41
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Vergelijking van het aantal berekeningen
Filteren van een N × N beeld met een n × n masker:•Via convolutie/correlatie:
• scheidbaar filter: 4n-2 bewerkingen/pixel• niet-scheidbaar filter: 2n2-1 bewerkingen/pixel
Voorwaartse en inverse DFT (via FFT)
Vermenigvuldiging in frequentiedomein
1log4log422
22
2+=
+ NN
NNN bewerkingen/pixel
•Via de DFT (als we de DFT van het masker al kennen):
De DFT-implementatie is voordeliger voor grote maskers•Break-even punt (niet-scheidbaar): (b.v. N=256 ⇒ n=4)Nn 2log2≈
© W. Philips, Universiteit Gent, 1998-2006
03b.42
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Voorbeelden: laagdoorlaatfilters
[ ]121121
161
121242121
161
=
Binomiaal-filter (3x3)
[ ]111111
91
111111111
91
=
Uitmiddeling over 3x3 omgeving
zorgt ervoor dat ⇒behoudt gemiddelde grijswaarde
fy=2l/Nfx =2k/M
geen zijlobes!gewenst als men hoge
frequenties wil onderdrukkenlk
yx
H
ffH
,~
),(~
=100 =),(~H
100 =),(~H
100 =),(~H
© W. Philips, Universiteit Gent, 1998-2006
03b.43
version: 30/11/2006 © A. Pizurica, Universiteit Gent, 2006
Filter in het fourierdomein: voorbeeldreconstructie met 25% van de coëfficiënten
reconstructie met 6.25% van de coëfficiënten
Invloed op het beeld: • “Ringing” (rimpels)• “Blurring” (wazig maken)
Filter: binnen het blauw vierkant en 0 erbuiten1~, =lkH
Dit komt erop neer de fouriercoëfficiënten bij hoge spatiale frequenties nul te maken ⇒laagdoorlaatfilter
© W. Philips, Universiteit Gent, 1998-2006