Professional Documents
Culture Documents
Interpolation
Pixel relation
2
Outline
Spatial and Transform domain
Image Histogram/Processing
Histogram Equalization
Summary
3
3.1 Background
3.1.1 Spatial Domain vs Transform Domain
► Spatial domain (p127)
This method directly processes the intensity values or pixel values of
the image plane and its results can immediately be interpreted by
humans.
► Transform domain
This method transforms the input images into a transform domain,
processes some operation in the domain, and applies the inverse
transform to return to the spatial domain as shown in belows
diagram:Fourier Inverse Fourier
Transform Transform
4
3.1.1 Spatial Domain vs Transform Domain
g ( x, y ) T [ f ( x, y )]) (3.1-1)
f ( x, y ) : input image Spatial – Transform
g ( x, y ) : output image domain domain
5
Spatial Domain Process
6
Spatial Domain Process
- Contrast stretching, Thresholding
Intensity transformation
function
8
3.2.1 Image Negatives (p130)
Image negatives
intensity level s ( 0 ~ 255)
s L 1 r
Output image –
Input image –
intensity level r ( 0 ~ 255)
9
Image Negatives
Image negatives
s L 1 r
10
Example: Image Negatives
Ex:
w w=686
h
Ex:
h=790
Small
lesion
11
3.2.2 Log Transformations (p131)
Log Transformations
s c log(1 r )
12
Example: Log Transformations
13
3.2.3 Power-Law (Gamma) Transformations
s cr
14
Power-Law (Gamma) Transformations
void DibGammaCorrection(CDib& dib, float gamma)
{ register int i, j;
float invgamma = 1.f / gamma;
s cr
15
Example: Gamma Corrections - p134
s=r2.5
s=r0.5
s=r2.5
16
Example: Gamma Transformations
Cathode ray tube
(CRT) devices have an
s=r2.5 intensity-to-voltage
response that is a
power function, with
exponents varying
from approximately
s r1/2.5 1.8 to 2.5
s=r0.4
s=r2.5
17
Example: Gamma Transformations
s=r0.6
(a) original
18
s=r0.4 s=r0.3
Example: Gamma Transformations
s=r3.0
s=r4.0
s=r5.0
19
Piecewise-Linear Transformations
► Contrast Stretching
— Expands the range of intensity levels in an image so that it spans
the full intensity range of the recording medium or display device.
► Intensity-level Slicing
— Highlighting a specific range of intensities in an image often is of
interest.
20
pollen 꽃가루 , x700
21
Highlight the major
blood vessels and
study the shape of the
flow of the contrast
medium (to detect
blockages, etc.)
23
Bit-plane Slicing
24
Bit-plane Slicing
Bit 8, 7 Bit 8, 7, 6 Bit 8, t, 6, 5
25
► Experiment 3.1
image negative
Contrast stretching
26
3.3 Histogram Processing (p142)
► 3.3.1 Histogram Equalization
27
Histogram Processing
nk
Normalized histogram p( rk )
MN
nk : the number of pixels in the image of
size M N with intensity rk
28
Histogram Processing
31
32
3.3.1 Histogram Equalization
The intensity levels are assumed in the interval [0, L-1]. ex. [0, 255]
r : input variable – intensity level of input image, s: the output variable for output image
Relation between r and s is transformation function T. Then ..
s = T (r) 0<= r <= L -1 (3.3-1)
that produce an output intensity level s for every pixel in input image having intensity r. We
assume that:
(a) T( r) is a “monotonically increasing function” in 0 <= r <=L-1; and
(b) 0 <= T( r) <= L-1 for 0 <= r <=L-1
Then, We use the inverse
r = T-1 ( s) 0<= s <=L-1 (3.2-2)
In which case we change the condition (a) to (a’) :
(a’) T( r) is a “strictly monotonically increasing function” in 0 <= r <=L-1;
Condition (a’) guarantees that the mapping from s back to r will be one-to-on, preventing ambiguities.
(page 144)
T(r)
T(r)
r r
33
Histogram Equalization
3.3.1 histogram equalization
• Probability theory: (page 145)
If pr(r) and T(r) are known, and T(r) is continuous and differentiable
over the range of values of interest,
then the PDF of the transformed (mapped) variable s can be obtained
using: dr
p s ( s ) pr ( r ) (3.3 3)
ds
• The PDF of the output intensity variable s is determined by the PDF of input r and
the transformation function [ recall that r and s are related by T( r)].
r
s T (r ) ( L 1) pr ( w)dw (3.3 4)
0
The right side of this equation is CDF (Cumulative distribution function)
of random variable r.
1) Transformation function of e.q. 3.3-4 satisfies condtion (a)
because the area under the function cannot decrease as r increases
2) When the upper limit of this eq. is r=(L-1), the integral evaluates to 1,
this satisfies condition (b)
34
Histogram Equalization (page 146)
( L 1) pr ( r ) (3.3 5)
We see that as (eq. 3.3-6) shows, the resulting ps(s) always is uniform,
35
independently of the form of pr(r). Fig 3.18 ilustrates these concepts:
Histogram Equalization
Exercise 3.4: Illustration of eqs. (3.3-4) and (3.3-6)
• Suppose that the intensity values in an image have the PDF
2r
pr ( r ) ( L 1) 2 for 0 r L 1
0 otherwise r
• From eq. (3.3-4) 2
r
s T ( r ) ( L 1) pr ( w) dw
2 r 2 w r
2
L 1 0
w dw
L 1 L 1
2
0
ds
1
2r dr
( L 1) 2
ds
1
2r d r 2
( L 1) 2 dr L 1
2r L 1
( L 1) 2 2r
1
L 1 36
• As expected, the result ps (s) is a uniform PDF and independent of the form of pr(r)
Histogram Equalization
Exercise 3.4: Illustration of eqs. (3.3-4) and (3.3-6)
• Suppose that the intensity values in an image have the PDF
2r
pr ( r ) ( L 1) 2 for 0 r L 1
0 otherwise r
• From eq. (3.3-4) 2
r
s T ( r ) ( L 1) pr ( w) dw
2 r 2 w r
2
L 1 0
w dw
L 1 L 1
2
0
ds
1
2r dr
( L 1) 2
ds
1
2r d r 2
( L 1) 2 dr L 1
2r L 1
( L 1) 2 2r
1
L 1 37
• As expected, the result ps (s) is a uniform PDF and independent of the form of pr(r)
Histogram Equalization (page 148)
nk
Normalized histogram p( rk )
MN
nk : the number of pixels in the image of
size M N with intensity rk
Continuous case:
r
s T ( r ) ( L 1) pr ( w) dw Eq. (3.3-4)
0
The right side of the eq. is recognized as the cumulative distribution function
(CDF) of random variable r.
Discrete values:
k
sk T (rk ) ( L 1) pr (rj ) Eq. (3.3-8)
j 0
k nj L 1 k
( L 1) nj k=0,1,..., L-1
j 0 MN MN j 0 38
Example 3.5 : Histogram Equalization ★★★
(page 148)
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096) has
the intensity distribution shown in following table.
Get the histogram equalization transformation function and give the ps(sk)
for each sk.
39
Example: Histogram Equalization
• Use eq. 3.3-8 for sk :
Discrete values:
k
sk T (rk ) ( L 1) pr (rj ) Eq. (3.3-8)
j 0
Solution:
0
s0 T (r0 ) 7 pr (rj ) 7 0.19 1.33 1
j 0
3
1
s1 T ( r1 ) 7 pr ( rj ) 7 (0.19 0.25) 3.08
j 0
s2 4.55 5 s3 5.67 6
s4 6.23 6 s5 6.65 7
s6 6.86 7 s7 7.00 7
40
Example: Histogram Equalization
41
Histogram Equalization Ex3.5
“lenna.bmp” image
and histogram
“lenna.bmp” image
after histogram
equalization
45
Histogram Equalization
Input image vs Histogram equalized image
11.08
“camera man” image
and histogram
46
Histogram Equalization
Histogram equalization does not give us always better images.
47
48
49
Question
Is histogram equalization always good?
No
50
3.3.2 Histogram Matching (Specification)
Histogram matching (histogram specification)
— generate a processed image that has a specified histogram
1
z G (s) G 1
T (r ) (3.3-11)
52
Histogram Matching: Procedure
1) Obtain pr(r) from the input image and then obtain the values of s
r
s ( L 1) pr ( w)dw (3.3-13)
0
2) Use the specified PDF and obtain the transformation function G(z)
z
G ( z ) ( L 1) pz (t )dt s (3.3-14)
0
4) inverse transformation process : Obtain the output image by first equalizing the
input image using eq. (3.3-10); the pixel values in this image are the s values.
Perform the inverse mapping z = G-1(s) to obtain the corresponding pixel in
output image. The PDF of the output image will be the specified PDF.
z G 1 ( s ) (3.3-16) 53
Histogram Matching: Example 3.7 (page 153)
0, otherwise
Find the transformation function that will produce an image
whose intensity PDF is
3z 2
, for 0 z ( L -1)
pz ( z ) ( L 1) 3
0, otherwise
54
Histogram Matching: Example
1) Find the histogram equalization transformation for the input image
r
s T (r ) ( L 1) pr ( w)dw ( L 1)
r 2w r2
dw
0 0 ( L 1) 2
L 1
2) Find the histogram equalization transformation for the specified histogram
z z 3t 2 z3
G ( z ) ( L 1) pz (t )dt ( L 1) dt s
0 0 ( L 1) 3
( L 1) 2
55
Histogram Matching: Discrete Cases (page 154-
155)
1) Compute the histogram pr(ri) of the given image and use it to find the histogram
equalization transformation sk in eq. (3.3-13). Round the resulting values, sk, to the
range [0, L-1] (3.3-13)
k
( L 1)
k
sk T ( rk ) ( L 1) pr (rj ) n j k=0, 1, …, L-1
j 0 MN j 0
2) Use the specified PDF and compute the transformation function G(zq) for q = 0,
1, .., L-1 where pz(zi) are the values of the specified histogram. Round the values of G to the
integer range [0, L-1]. Store the values of qG in a table.
G ( zq ) ( L 1) pz ( zi ) sk (3.3-14)
i 0
3) Mapping from sk to zq : For every value of sk, k=0,1,2,…,L-1, use the stored value of G from
2) to find the corresponding value of zq so that G(zq) is closest to sk and store these mappings
from s to z. When more than one value of zq satisfies the given sk, choose the smallest value b
convention.
(3.3-15)
57
Example: Histogram Matching
Step 1) Find the histogram equalization transformation sk
- Obtain the scaled histogram-equalized values,
from Ex) 3-5.
s0 = 1, s1 = 3, s2 = 5, s3 = 6,
s4 = 6, s5 = 7, s6 = 7, s7 = 7
58
Example: Histogram Matching
Step 3) Mapping from sk to zq so that G(zq) is closest to sk
- from step 1: histogram-equalized values sk
s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 6, s5 = 7, s6 = 7, s7 = 7
- from step 2: the transformation function G(zq), zq G 1 ( sk )
zq G(zq) sk rk rk z q
--------------------------------------------------------------------------
z0 --- G(z0)= 0 s0=1 --- r0 0 3
z1 --- G(z1)= 0 s1=3 --- r1 1 4
z2 --- G(z2)= 0 s2=5 --- r2 2 5
z3 --- G(z3)= 1 s3=6 --- r3 3 6
z4 --- G(z4)= 2 s4=6 --- r4
4 6
z5 --- G(z5)= 5 s5=7 --- r5
5 7
z6 --- G(z6)= 6 s6=7 --- r6
6 7
z7 --- G(z7)= 7 s7=7 --- r7 59
7 7
Histogram Matching Ex3.8
sk
ed
rm
d
s fo
un
an
ro
Tr
sk ps(sk) rk zq pz(zq) G(zq) G(zq) sk ps(sk) pz(zq) zq
z0=0 0 0 → 0 z0=0
0 ← 0
z1=1 0 0 → 0 z1=1
1 ← 0.19 0
z2=2 0 0 → 0 z2=2
2 ← 0
z3=3 0.15 1.05 → 1 1 0.19 0.19 z3=3
3 ← 0.25 1
z4=4 0.2 2.45 → 2 3 0.25 0.25 z4=4
4 ← 0
z5=5 0.3 4.55 → 5 5 0.21 0.21 z5=5
5 ← 0.21 2
z6=6 0.2 5.95 → 6 6 0.24 0.24 z6=6
6 ← 0.24 3,4
z7=7 0.15 7 → 7 7 0.11 0.11 z7=7
7 ← 0.11 5,6,7 60
Example: Histogram Matching
61
Example: Histogram Matching
63
Example: Histogram Matching
Histogram matching
image
64
Example: Histogram Matching
65
► Summary
Spatial and Transform domain
Image Histogram/Processing
Histogram Equalization
66
► Thank you
67
3.3.3 Local Histogram Processing
11/15
Define a neighborhood and move its center from pixel to
pixel
68
3.3.3 Local Histogram Processing: Example
(P 161)
69
3.3.4 Using Histogram Statistics
for Image Enhancement
Average Intensity L 1 M 1 N 1
1
m ri p (ri )
MN
f ( x, y )
x 0 y 0
i 0
L 1
un (r ) (ri m) n p (ri )
i 0
Variance L 1 M 1 N 1
1
u2 (r ) (ri m) p (ri ) f ( x, y ) m
2 2 2
i 0
MN x 0 y 0
70
3.3.4 Using Histogram Statistics
for Image Enhancement
The nth moment of r about its mean: (from section 2.6.8)
L 1
un (r ) (ri m) n p (ri )
i 0
Average Intensity m:
L 1 M 1 N 1
1
m ri p (ri )
MN
f ( x, y )
x 0 y 0
i 0
Variance = the second moment:
L 1 M 1 N 1
1
u2 (r ) (ri m) p(ri ) f ( x, y ) m
2 2 2
MN x 0 y 0
i 0
71
Using Histogram Statistics for Image
Enhancement
Let S denote a neighborhood of any pixel (x,y):
example: S size can be 3x3
Local average intensity
L 1
msxy ri psxy (ri )
i 0
Local variance
L 1
s2xy (ri msxy ) 2 psxy (ri ) 72
i 0
Using Histogram Statistics for Image
Enhancement: Example
Spatial filter
mask
Image section
under filter 75
Spatial Correlation
a=(m-1)/2, b=(m-1)/2
Ex) an image of size MxN with a filter of size mxn
m=3, n=3 a=(3-1)/2= 2/2=1, b=1
76
Spatial Convolution
a b
w( x, y ) f ( x, y ) w(s, t ) f ( x s, y t )
s a t b
1, 0, w( 1, 0) f(x-1, y)
Correlation
Convolution
78
79
Smoothing Spatial Filters
80
Spatial Smoothing Linear Filters
w(s, t ) f ( x s, y t )
g ( x, y ) s a t b
a b
w(s, t )
s a t b
where m 2a 1, n 2b 1.
81
Two Smoothing Averaging Filter Masks
82
1 1 1 1 1
1 1 1
1 1 1 1 1
1 1 1
1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
83
Example: Gross Representation of Objects
84
Order-statistic (Nonlinear) Filters
— Nonlinear
85
Example: Use of Median Filtering for Noise Reduction
86
Sharpening Spatial Filters
► Foundation
► Laplacian Operator
87
Sharpening Spatial Filters: Foundation
f
f ( x 1) f ( x)
x
2 f
f ( x 1) f ( x 1) 2 f ( x)
x 2
88
89
Sharpening Spatial Filters: Laplace Operator
2
f 2
f
f 2 2
2
x y
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x 2
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y 2
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)
- 4 f ( x, y )
90
Sharpening Spatial Filters: Laplace Operator
91
Sharpening Spatial Filters: Laplace Operator
g ( x, y ) f ( x, y ) c 2 f ( x, y )
where,
f ( x, y ) is input image,
g ( x, y ) is sharpenend images,
c -1 if 2 f ( x, y ) corresponding to Fig. 3.37(a) or (b)
and c 1 if either of the other two filters is used.
92
93
Unsharp Masking and Highboost Filtering
► Unsharp masking
Sharpen images consists of subtracting an unsharp (smoothed)
version of an image from the original image
e.g., printing and publishing industry
► Steps
1. Blur the original image
94
Unsharp Masking and Highboost Filtering
95
Unsharp Masking: Demo
96
Unsharp Masking and Highboost Filtering: Example
97
Image Sharpening based on First-Order Derivatives
M ( x, y ) | g x | | g y |
z1 z2 z3
M ( x, y ) | z8 z5 | | z6 z5 |
z4 z5 z6
z7 z8 z9
99
Image Sharpening based on First-Order Derivatives
Sobel Operators
M ( x, y ) | ( z7 2 z8 z9 ) ( z1 2 z2 z3 ) |
z1 z2 z3 | ( z3 2 z6 z9 ) ( z1 2 z4 z7 ) |
z4 z5 z6
z7 z8 z9
100
Image Sharpening based on First-Order Derivatives
f’(x)=f(x+1)-f(x)
f’(y)=f(y+1)-f(y)
x 101
Example
102
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail
103
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by bringing
out more of the
skeletal detail
104