Lect 5
Lect 5
Lecture # 5
Image Enhancement
1
HISTOGRAM MATCHING
(SPECIFICATION)
• HISTOGRAM EQUALIZATION DOES NOT ALLOW
INTERACTIVE IMAGE ENHANCEMENT AND
GENERATES ONLY ONE RESULT: AN
APPROXIMATION TO A UNIFORM HISTOGRAM.
• SOMETIMES THOUGH, WE NEED TO BE ABLE TO
SPECIFY PARTICULAR HISTOGRAM SHAPES
CAPABLE OF HIGHLIGHTING CERTAIN GRAY-LEVEL
RANGES.
2
HISTOGRAM SPECIFICATION
• THE PROCEDURE FOR HISTOGRAM-SPECIFICATION BASED
ENHANCEMENT IS:
k nj
s T (rk )
j 0 n
k
vk G z k p z z i s k
i 0
4
HISTOGRAM SPECIFICATION
5
MAPPINGS
6
HISTOGRAM SPECIFICATION
7
HISTOGRAM SPECIFICATION
k nk pr(rk) sk pz(zk) vk nk
0 790 0.19 0.19 0 0 0
1 1023 0.25 0.44 0 0 0
2 850 0.21 0.65 0 0 0
3 656 0.16 0.81 0.15 0.15 790
4 329 0.08 0.89 0.2 0.35 1023
5 245 0.06 0.95 0.3 0.65 850
6 122 0.03 0.98 0.2 0.85 985
7 81 0.02 1.0 0.15 1.0 448
9
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN
10
11
GLOBAL/LOCAL HISTOGRAM EQUALIZATION
• IT MAY BE NECESSARY TO ENHANCE DETAILS OVER SMALL AREAS IN THE
IMAGE
• THE NUMBER OF PIXELS IN THESE AREAS MAY HAVE NEGLIGIBLE INFLUENCE
ON THE COMPUTATION OF A GLOBAL TRANSFORMATION WHOSE SHAPE
DOES NOT NECESSARILY GUARANTEE THE DESIRED LOCAL ENHANCEMENT
• DEVISE TRANSFORMATION FUNCTIONS BASED ON THE GRAY LEVEL
DISTRIBUTION IN THE NEIGHBORHOOD OF EVERY PIXEL IN THE IMAGE
• THE PROCEDURE IS:
– DEFINE A SQUARE (OR RECTANGULAR) NEIGHBORHOOD AND MOVE THE
CENTER OF THIS AREA FROM PIXEL TO PIXEL.
– AT EACH LOCATION, THE HISTOGRAM OF THE POINTS IN THE
NEIGHBORHOOD IS COMPUTED AND EITHER A HISTOGRAM
EQUALIZATION OR HISTOGRAM SPECIFICATION TRANSFORMATION
FUNCTION IS OBTAINED.
– THIS FUNCTION IS FINALLY USED TO MAP THE GRAY LEVEL OF THE PIXEL
CENTERED IN THE NEIGHBORHOOD.
– THE CENTER IS THEN MOVED TO AN ADJACENT PIXEL LOCATION AND THE
PROCEDURE IS REPEATED.
12
GLOBAL/LOCAL HISTOGRAM EQUALIZATION
13
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Global)
• LET r REPRESENT A GRAY LEVEL IN THE IMAGE [0, L-1], AND LET p(ri )
DENOTE THE NORMALIZED HISTOGRAM COMPONENT
CORRESPONDING TO THE ith VALUE OF r.
• THE nth MOMENT OF r ABOUT ITS MEAN IS DEFINED AS
L 1 n
n r ri m p ri
i 0
• WHERE m IS THE MEAN VALUE OF r (AVERAGE GRAY LEVEL)
m i 0 ri p ri
L 1
14
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Global)
• THE SECOND MOMENT IS GIVEN BY
L 1 2
2 r ri m p ri
i 0
15
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Local)
• LET (x,y) BE THE COORDINATES OF A PIXEL IN AN
IMAGE, AND LET SX,Y DENOTE A NEIGBORHOOD OF
SPECIFIED SIZE, CENTERED AT (x,y)
• THE MEAN VALUE mSXY OF THE PIXELS IN SX,Y IS
ms xy r s ,t p rs ,t
s ,t
S xy
r
ms xy p rs ,t
2 2
S xy s ,t
s ,t S xy
16
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT
• THE GLOBAL MEAN AND VARIANCE ARE MEASURED
OVER AN ENTIRE IMAGE AND ARE USEFUL FOR
GROSS ADJUSTMENTS OF OVERALL INTENSITY AND
CONTRAST.
• A USE OF THESE MEASURES IN LOCAL
ENHANCEMENT IS, WHERE THE LOCAL MEAN AND
VARIANCE ARE USED AS THE BASIS FOR MAKING
CHANGES THAT DEPEND ON IMAGE
CHARACTERISTICS IN A PREDEFINED REGION ABOUT
EACH PIXEL IN THE IMAGE.
17
TUNGSTEN FILAMENT IMAGE
18
USE OF HISTOGRAM STATISTICS FOR IMAGE ENHANCEMENT
19
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN
20
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN
21
Spatial Filtering
Spatial Filtering
23
Spatial Filtering
24
Spatial Filtering
25
Spatial Filtering
26
Spatial Filtering
Spatial Filtering: Basics
The output intensity value at (x,y) depends not only on the input
intensity value at (x,y) but also on the specified number of
neighboring intensity values around (x,y)
Spatial masks (also called window, filter, kernel, template) are used
and convolved over the entire image for local enhancement (spatial
filtering)
28
Spatial Filtering: Basics
aa bb
gg((xx,,yy)) ww((ss,,tt))ff((xxss,,yytt))
aat
t bb
ss
m 1 n 1
where a = , b=
2 2
x 0,1, 2,...., M 1, y 0,1, 2,..., N 1
29
Spatial Filtering: Basics
Given the 3×3 mask with coefficients: w1, w2,…, w9
The mask cover the pixels with gray levels: z1, z2,…, z9
w1 w2 w3 z1 z2 z3
w4 w5 w6 z4 z5 z6
w7 w8 w9 z7 z8 z9
99
zz
zz99ww99
zz11ww11zz22ww22 zz33ww33 zzi iwwi i
i
i 11
30
Spatial Filtering: Basics
Origin x
Neighbourhood
Neighbourhood
operations: Operate
operations: Operateon
onaa
largerneighbourhood
larger neighbourhoodof
of
pixelsthan
pixels thanpoint
point
operations
operations (x, y)
Neighbourhood
Neighbourhoods
Neighbourhoodsarearemostly
mostlyaa
rectangle
rectanglearound
aroundaacentral
central
pixel
pixel
y Image f (x, y)
33
Spatial Filtering: Basics
Origin x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
The
Theabove
aboveisisrepeated
repeatedfor
forevery
everypixel
pixelininthe
theoriginal
originalimage
imagetotogenerate
generatethe
thefiltered
filteredimage
image
34
Spatial Filtering: Basics
Original Image x Enhanced Image x
123 127 128 119 115 130
y y
35
Spatial Filtering: Basics
Original Image
36
Spatial Filtering: Basics
37
Spatial Filtering: Basics
38
Spatial Filtering: Basics
39
Spatial Filtering: Basics
40
Spatial Filtering: Basics
41
Spatial Filtering: Basics
Mask operation near the image border: Problem arises when
part of the mask is located outside the image plane
Discard
Discardthe theproblem
problempixels
pixels(e.g.
(e.g.
512x512
512x512 input 510x510 outputififmask
input 510x510 output mask Pixel
Pixelreplication:
replication:We We
size is 3x3)
size is 3x3) normally
normallyuse usethe
thegray
gray
Zero
Zeropadding:
padding:Expand
Expandthe theinput
input levels
levelsof ofborder
borderpixels
pixelsto
to
image
imageby bypadding
paddingzeros
zeros(512x512
(512x512 fill
fillup
upthe
theexpanded
expandedregion
region
original
originalimage,
image,514x514
514x514padded
padded (for
(for3x3
3x3mask).
mask).For
Forlarger
larger
image,
image, 512x512
512x512output)
output) masks
masksaaborder
borderregion
region
Zero
Zeropadding
paddingisisnot
not equal
equalto tohalf
halfof
ofthe
themask
mask
recommended
recommendedas asititcreates
creates size
sizeisismirrored
mirroredon onthe
the
artificial
artificiallines
linesor
oredges
edgeson onthe
the expanded
expandedregion.
region.
border
border
42
Spatial Filtering: Basics
Mask operation near the border: Pixel
replication
44
Smoothing Spatial Filters
Simplyaverage
Simply averageall
allof
ofthe
thepixels
pixelsininaaneighbourhood
neighbourhoodaround
around
aacentral
centralvalue
value
1
/9 1
/9 1
/9
Simple
1
/9 1
/9 1
/9 averaging
filter
1
/9 1
/9 1
/9
45
Smoothing Spatial Filters
For blurring/noise reduction
46
Smoothing Spatial Filters
Origin x
104 100 108 1
/9 1
/9 1
/9
* /9 /9 /9
1 1 1
99 106 98
95 90 85 1
/9 1
/9 1
/9
1
/9 100
104 1
/9 108
1
/9
Original Image Filter
Simple 3*3 /9 106
1
99 1
/9 198
/9
3*3 Smoothing Pixels
Neighbourhood /9 190
1
95 /9 185
/9 Filter
e = 1/9*106 +
1
/9*104 + 1/9*100 + 1/9*108 +
1
/9*99 + 1/9*98 +
y Image f (x, y) 1
/9*95 + 1/9*90 + 1/9*85
= 98.3333
The above is repeated for every pixel in the original image to generate the smoothed image
47
Smoothing Filter: Example
original
original 3x3 average
3x3 average
48
Smoothing Filter: Example
original
original 3x3 average
3x3 average
49
Smoothing Filter: Example
original
original 3x3 average
3x3 average
50
Smoothing Filter: Example
original
original 3x3 average
3x3 average
51
Original image
Smooth by 3x3
Size: 500x500 box filter
Smooth by
Smooth by
35x35 box filter
15x15 box filter
Noticehow
Notice howdetail
detailbegins
beginsto
todisappear
disappear
52
Smoothing Spatial Filters
Consider
Considerthe
the
output
outputpixel
pixelis
is
positioned
positionedatat
the
thecenter
center
53
Readings from Book (3 Edn.) rd
55