Beruflich Dokumente
Kultur Dokumente
Image Enhancement
(Histogram Processing)
Grey Levels
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
12
Histogram Examples
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
13
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
14
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
15
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
16
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
17
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
18
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
19
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
20
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
21
Histogram Examples (cont…)
22
of
32
Histogram Examples (cont…)
A selection of images and
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
their histograms
Notice the relationships
between the images and
their histograms
Note that the high contrast
image has the most
evenly spaced histogram
23
of
32
Contrast Stretching
We can fix images that have poor contrast
by applying a pretty simple contrast
specification
The interesting part is how do we decide on
this transformation function?
24
of
32
Histogram Equalisation
Spreading out the frequencies in an image (or
equalising the image) is a simple way to
improve dark or washed out images
The formula for histogram
equalisation is given where sk = T (rk )
– rk: input intensity k
– sk: processed intensity = ∑ pr ( r j )
– k: the intensity range j =1
(e.g 0.0 – 1.0) k nj
– nj: the frequency of intensity j =∑
– n: the sum of all frequencies j =1 n
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
25
Equalisation Transformation Function
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
26
1
Equalisation Examples
27
of
32
Equalisation Transformation Functions
of
32
28
2
Equalisation Examples
29
of
32
Equalisation Transformation Functions
of
32
30
4
3
Equalisation Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
of
32
31
4
3
Equalisation Examples (cont…)
32
of
32
Equalisation Transformation Functions
Attila Kuba
University of Szeged
Contents
Histogram
Histogram transformation
Histogram equalization
Contrast streching
Applications
Histogram
The (intensity or brightness) histogram shows how many
times a particular grey level (intensity) appears in an image.
0 1 1 2 4 6
5
2 1 0 0 2 4
3
2
5 2 0 0 4 1
0
1 1 2 4 1 0 1 2 3 4 5 6
image histogram
Histogram II
An image has low contrast when the complete range of possible
values is not used. Inspection of the histogram shows this
lack of contrast.
Histogram of color images
RGB color can be converted to a gray scale
value by
Blue
Histogram of
color images III
R
R B
R G
Histogram of color images IV
or
a 3-D histogram can be produced, with
the three axes representing the red,
blue and green channels, and
brightness at each point representing
the pixel count
Histogram transformation
Point operation T(rk) =sk
rk sk grey values:
Properties of T:
keeps the original range of grey values
monoton increasing
Histogram equalization (HE)
·(L-1)
k = 0,1,2,...,L-1
L: number of grey levels in image (e.g., 255)
nj: number of times j-th grey level appears in
image
?
n: total number of pixels in the image
Histogram equalization III
Histogram equalization IV
Histogram equalization V
cumulative histogram
Histogram equalization VI
Histogram equalization VII
HE
Histogram equalization VIII
histogram can be taken also on a part of the
image
Histogram projection (HP)
assigns equal display space to
every occupied raw signal level,
regardless of how many pixels are
at that same level. In effect, the raw
signal histogram is "projected" into a
similar-looking display histogram.
Histogram projection II
IR image
HE HP
Histogram projection III
occupied (used) grey level: there is at least
one pixel with that grey level
HP transformation:
sk = 255 ·B(k).
Plateau equalization
By clipping the histogram count at a
saturation or plateau value, one can
produce display allocations
intermediate in character between
those of HP and HE.
Plateau equalization II
HE PE 50
Plateau equalization III
The PE algorithm computes the distribution not for the full image
histogram but for the histogram clipped at a plateau (or saturation) value
in the count.
When that plateau value is set at 1, we generate B(k) and so perform
HP;
When it is set above the histogram peak, we generate F(k) and so
perform HE.
At intermediate values, we generate an intermediate distribution which
we denote by P(k).
PE transformation:
sk = 255· P(k)
Histogram specification (HS)
an image's histogram is transformed
according to a desired function
Transforming the intensity values so that the
histogram of the output image
approximately matches a specified
histogram.
Histogram specification II
histogram1 histogram2
S-1 *T
T S
?
Contrast streching (CS)
By stretching the histogram we attempt to use
the available full grey level range.
?
HE
Contrast streching IV
CS
HE
Contrast streching V
CS
1% - 99%
Contrast streching VI
HE
CS
79, 136
CS
Cutoff fraction: 0.8
Contrast streching VIII
0, if rk < plow
sk = 255·(rk- plow )/(phigh - plow ), otherwise
255, if rk > phigh
Contrast streching IX
Contrast streching X
Contrast streching XI
Applications
CT lung studies
Thresholding
Normalization
Normalization of MRI images
Presentation of high dynamic images (IR, CT)
CT lung studies
R.Rienmuller
Thresholding
converting a greyscale image to a binary one
threshold: 120
Thresholding II
when the histogram is not bi-modal
L. G. Nyúl, J. K. Udupa
Normalization of MRI images III
A: Histograms of 10 FSE PD brain 6000
standardization.
2000
A
1000
0
0 500 1000 1500 2000 2500
6000 6000
5000 5000
4000 4000
3000 3000
2000
2000
1000
B 1000
C
0
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
0
0 500 1000 1500
L. G. Nyúl, J. K. Udupa
2000 2500 3000 3500 4000 4500 5000
Normalization of MRI images IV
unimodal bimodal
m1 p1 µ p2 m2 m1 p1 µ p2 m2
• The function p(rk) represents the fraction of the total number of pixels with
gray value rk.
• Histogram provides a global description of the appearance of
the image.
Pr( R = rk ) ≈ p (rk )
Some Typical Histograms
• The shape of a histogram provides useful information for
contrast enhancement.
Dark image
Bright image
dr
ps ( s ) = pr (r )
ds r =T −1 ( s )
• One way to enhance the image is to design a transformation
T(.) such that the gray values in the output is uniformly
distributed in [0, 1], i.e. ps (s) = 1, 0 ≤ s ≤ 1
This is the cumulative distribution function (CDF) of pr (r) and satisfies the
previous two conditions.
nk
pin (rk ) = 0 ≤ rk ≤ 1 0 ≤ k ≤ L −1
n
L: Total number of gray levels
k
sk = T (rk ) = ∑ pr (r j ) 0 ≤ k ≤ L −1
j =0
Example:
NB: The gray values in output are also (0, 1/7, 2/7, …, 1).
# pixels Fraction
of #
pixels
# pixels
Gray values
• Note that the histogram of output image is only approximately, and not exactly,
uniform. This should not be surprising, since there is no result that claims
uniformity in the discrete case.
Example Original image and its histogram
Histogram equalized image and its histogram
• Comments:
Histogram equalization may not always produce desirable
results, particularly if the given histogram is very narrow. It
can produce false edges and regions. It can also increase
image “graininess” and “patchiness.”
Histogram Specification
(Histogram Matching)
• Histogram equalization yields an image whose pixels are (in
theory) uniformly distributed among all gray levels.
• Goal
Derive a point operation, H(r), that maps the input image into an output
image that has the user-specified histogram.
z
V = G ( z ) = ∫ pout ( w)dw , 0 ≤ z ≤1 (**)
0
• From the gray values ν we can obtain the gray values z by
using the inverse transformation, z = G-1 (v)
k
sk = T (rk ) = ∑ pin (r j ) 0 ≤ k ≤ L −1
j =0
k
vk = G ( z k ) = ∑ pout ( z j ) = sk 0 ≤ k ≤ L −1
j =0
• In practice, this is not usually the case (i.e., ) zk → G(zk) is not one-to-one)
and we assign gray values to match the given histogram, as closely as
possible.
Algorithm for histogram specification:
(1) Equalize input image to get an image with uniform gray values,
using the discrete equation:
k
sk = T (rk ) = ∑ pin (r j ) 0 ≤ k ≤ L −1
j =0
k
vk = G ( z k ) = ∑ pout ( z j ) = sk 0 ≤ k ≤ L −1
j =0
−1 −1
(3)
= → =
z G (v=s) z G [T ( r )]
Example:
# pixels
Gray
value
• It is desired to transform this image into a new image, using a transformation
Z=H(r)= G-1 [T(r)], with histogram as specified below:
# pixels
Gray values
• The transformation T(r) was obtained earlier (reproduced
below):
G-1 (0) = ?
G-1 (3/7) = ?
G-1 (4/7) = ?
G-1 (1) = 1
• Combining the two transformation T and G-1 , compute z=H(r)= G-
1
[v=s=T(r)]
• Applying the transformation H to the original image yields an image with
histogram as below:
• Again, the actual histogram of the output image does not exactly but only
approximately matches with the specified histogram. This is because we are
dealing with discrete histograms.
Original image and its histogram
Image ENHANCEMENT
in the
SPATIAL DOMAIN
Part 2 Dr. Rolf Lakaemper
Most of these slides base on the
textbook
So far (part 1) :
• Histogram definition
• Histogram equalization
Now:
• Histogram statistics
Histograms
Remember:
The histogram shows the number of
pixels having a certain gray-value
number of pixels
grayvalue (0..1)
Histograms
M = Σ g h(g) g
1*0.3+2*0.1+3*0.2+4*0.1+5*0.2+6*0.1=
0.3 2.6
0.2
0.1
0.0
1 2 3 4 5 6
Histograms
2. The VARIANCE
V = Σ (g-M)2 h(g)
g
(with M = mean)
or similar:
0.3 0.3
0.2 0.2
0.1 0.1
0.0 0.0
V1 > V2
Histograms
0.3 0.3
0.2 0.2
0.1 0.1
0.0 0.0
D1 > D2
Histograms
Example:
Exercise:
The system should analyse an area in the middle of the picture and
automatically adjust the lens such that this area is sharp.
Spatial Filtering
End of histograms.
Spatial Filtering
Spatial Filtering
Spatial Filtering:
6 8 (Operator: sum)
12 200
6 8 2 0 226
12 200 20 10
Spatial Filtering
Example 1:
N(p) = {(x,y): |x-xP|=1, |y-yP| = 1}
Q
Spatial Filtering
P P P P
P P
Spatial Filtering
P P
Spatial Filtering
P
P
P
N8
N24
N48
Spatial Filtering
n1 n2 n3
n4 n5 n6
n7 n8 n9
Spatial Filtering
P = ∑ i ni
n1 n2 n3
n4 n5=P n6
n7 n8 n9
Spatial Filtering
P = ∑ i ai ni
• Blurring / Smoothing
• Sharpening
• Edge Detection
Blurring / Smoothing
(Sometimes also referred to as averaging or lowpass-filtering)
Purpose:
Blurring / Smoothing
1 1 1
1 1 1 * 1/9
1 1 1
Example 2:
Weighted average
1 2 1
2 4 2 * 1/16
1 2 1
Spatial Filtering
Basic idea:
Weigh the center point the highest,
decrease weight by distance to center.
P = ∑ i ai ni / ∑ i ai
EDGE DETECTION
Spatial Filtering
EDGE DETECTION
Purpose:
• Preprocessing
• Sharpening
Spatial Filtering
EDGE DETECTION
Purpose:
• Preprocessing
• Sharpening
Spatial Filtering
Motivation: Derivatives
Spatial Filtering
The 2nd order derivative is the derivative of the 1st order derivative…
Spatial Filtering
The 2nd order derivative is the derivative of the 1st order derivative…
derive
F(x+1)-F(x) – (F(x)-F(x-1))
1 -2 1
-2
1
Spatial Filtering
0 0 0 0 1 0 0 1 0
1 -2 1 + 0 -2 0 = 1 -4 1
0 0 0 0 1 0 0 1 0
im = im/max(im(:));
% create laplacian
L=[1 1 1;1 -8 1; 1 1 1];
% Filter !
im1=conv2(im,L);
+
Spatial Filtering
Spatial Filtering
0 -1 0 0 0 0 0 -1 0
-1 4 -1 + 0 1 0 = -1 5 -1
0 -1 0 0 0 0 0 -1 0
Sharpening in General:
Unsharp Masking
and
0 -1 0 0 0 0 0 1 0
-1 a-1 -1 = 0 a 0 - 1 1 1
0 -1 0 0 0 0 0 1 0
Spatial Filtering
0 -1 0
0 -1 0
a=6
-1 5 -1
0 -1 0 0 -1 0
a=1e7+1
-1 1e7 -1
Laplacian + Image ! 0 -1 0
Spatial Filtering
Spatial Filtering
MAGNITUDE of gradient:
-1 0 1 -1 -2 -1
-2 0 2 0 0 0
-1 0 1 1 2 1
“Sobel Operators”
Spatial Filtering
In practice, multiple
filters are combined to
enhance images
Spatial Filtering
…continued
Spatial Filtering
Spatial Filtering
Order-Statistics Filters
Median
Min
Max
Spatial Filtering
Median:
The median M of a set of values is such
that half the values in the set are less
than (or equal to) M, and half are
greater (or equal to) M.
1 2 3 3 4 5 6 6 6 7 8 9 9
Spatial Filtering
MIN
2 5 7 3
3 4 2 3
3 4 8 3 MAX
3 3 3 3
Spatial Filtering
189
Fourier Transform
M −1
1
F (u ) =
M
∑ f ( x) exp(− j 2πux / M )
x =0
u=0,1,2,…,M-1
and
M −1
f ( x) = ∑ F (u ) exp( j 2πux / M ) x=0,1,2,…,M-1
u =0
193
2-D Discrete Fourier Transform
F (u , v) = R (u , v) + j ⋅ I (u , v )
Polar coordinate
F (u , v) = F (u , v) exp( jφ (u , v))
Magnitude: F (u, v) = [ R 2 (u , v) + I 2 (u , v )]1/ 2
I (u , v)
Phase: φ (u, v) = tan −1
R(u, v)
195
Shifting the Origin to the Center
05/03/11 196
Shifting the Origin to the Center
05/03/11 197
Fourier Transform: shift
• It is common to multiply input image by (-1)x+y prior to
computing the FT. This shift the center of the FT to (M/2,N/2).
ℑ{ f ( x, y )} = F (u, v)
ℑ{ f ( x, y )( −1) x + y } = F (u − M / 2, v − N / 2)
Shift
198
Symmetry of FT
F (u , v) = F (−u , −v)
*
F (u , v) = F (−u , −v)
199
FT
IFT
200
IFT
IFT
201
The central part of FT, i.e. the low
frequency components are
responsible for the general gray-level
appearance of an image.
202
Image Frequency Domain
(log magnitude)
v Detail
General
appearance
203
5% 10 % 20 % 50 %
204
Frequency Domain Filtering
206
Frequency Domain Filtering
207
Convolution in Time Domain
g(x,y)=h(x,y)⊗f(x,y)
M −1 M −1
g( x , y ) = ∑ ∑ h( x' , y' ) f ( x − x' , y − y' )
x' = 0 y' = 0
≡ f ( x , y )* h( x , y )
– f(x,y) is the input image
– g(x,y) is the filtered
– h(x,y): impulse response
208
Convolution Theorem
Multiplication in Frequency
G(u,v)=F(u,v)⋅ H(u,v) Domain
Convolution in Time
g(x,y)=h(x,y)⊗f(x,y) Domain
209
Examples of Filters
Frequency
domain
210
Ideal low-pass filter (ILPF)
1 D(u , v) ≤ D0
H (u, v) =
0 D(u , v) > D0
D(u , v) = [(u − M / 2) + (v − N / 2) ]
2 2 1/ 2
211
Shape of ILPF
Frequency domain
h(x,y)
Spatial domain
212
FT
ringing and
blurring
Ideal in frequency
domain means
non-ideal in
spatial domain,
vice versa.
213
Butterworth Lowpass Filters (BLPF)
• Smooth transfer function, 1
no sharp discontinuity, H (u, v) = 2n
D(u , v)
no clear cutoff frequency. 1+
D0
1
2
214
No serious
ringing
artifacts
215
Gaussian Lowpass Filters (GLPF)
• Smooth transfer
function, smooth D 2 ( u ,v )
−
impulse response, no H (u , v) = e 2 D 20
ringing
216
GLPF
Frequency
domain
217
No ringing
artifacts
218
Examples of Lowpass Filtering
219
Examples of Lowpass Filtering
220
High-pass Filters
• Hhp (u,v)=1-Hlp (u,v)
1 D(u, v) > D0
• Ideal: H (u, v) =
0 D(u, v) ≤ D0
H (u, v) = 1
• Butterworth: D
2n
1+ 0
D(u, v)
− D 2 ( u ,v ) / 2 D02
• Gaussian: H (u , v) = 1 − e
221
222
Butterworth High-pass Filtering
223
Gaussian High-pass Filtering
224
Ideal High-pass Filtering
ringing artifacts
225
Gaussian High-pass Filtering
226
Example of Gaussian LPF and HPF
05/03/11 227
Homomorphic filters
• A simple image model: illumination–reflection model
– f(x,y) : the intensity is called gray level for monochrome image
– f(x,y)=i(x,y)*r(x,y)
– 0<i(x,y)<inf, the illumination
– 0<r(x,y)<1, the reflection
Image Enhancement - 3
Homomorphic filters (cont’)
− c ( D 2 ( u ,v ) / D02
H (u, v ) = (γ H − γ L )[1 − e )] + γ L
End of Lecture
234