Вы находитесь на странице: 1из 59

Image Enhancement – Introduction

1. Introduction

1.1 What is image enhancement?

--- Modify the intensities of pixels in an image so that it
can be more suitable for a specific application.

 Different enhancement process suits different

application.
 An enhancement method is good for an application
but maybe bad for another application.
Image Processing & Machine
Vision/Y. Gao 1
Image Enhancement – Introduction

 Spatial domain: process pixels in the image plane

directly.
 Frequency domain: modify the Fourier transform of
an image.

Image Processing & Machine

Vision/Y. Gao 2
Image Enhancement -- Introduction

Mathematically, the enhancement process in the spatial domain

can be described by the transform function
g(x,y) = T [f(x,y)]
f(x,y) --- input image,
g(x,y) --- output image,
T --- a transform

For a single pixel, we have s = T (r)

r --- grey-level value for an input pixel
s --- grey-level value for an output pixel

Image Processing & Machine

Vision/Y. Gao 3
Image Enhancement – Introduction

Grey-level value transform graph

We use a graph to denote the transform function s = T (r) .

s s s
T(r) T(r)
T(r)

r r r

Image Processing & Machine

Vision/Y. Gao 4
Image Enhancement – Introduction

Two simple examples for contrast enhancement

x
Image Processing & Machine
Vision/Y. Gao 5
Image Enhancement – Introduction

For the enhancement in the frequency domain, according to the

convolution theorem we have

f ( x, y ) h ( x, y ) g ( x, y )

F (u , v) H (u , v) G (u , v)

Image Processing & Machine

Vision/Y. Gao 6
Image Enhancement – Introduction

g ( x, y ) = h ( x, y ) ∗ f ( x, y )
G (u , v) = H (u , v) F (u , v)
-1
g ( x, y ) = F [ H (u, v) F (u, v)]
F (u , v) = F [ f ( x, y )]
H (u , v) = F [h( x, y )]
G (u , v) = F [ g ( x, y )]

Image Processing & Machine

Vision/Y. Gao 7
Image Enhancement -- outline
1. Introduction
2. Transforms
3. Histogram processing
4. Arithmetic/logic operations
5. Filtering
1) Spatial filters
i. Smoothing
ii. Sharpening
2) Frequency-domain filters
i. Smoothing
ii. Sharpening
Image Processing & Machine
Vision/Y. Gao 8
Image Enhancement -- Transformations

2. Transformations
2.1. Image negatives
L-1

T(r) s = T (r ) = L − 1 − r
s

0 r L-1

Image Processing & Machine

Vision/Y. Gao 9
Image Enhancement -- Transformations

Image Processing & Machine

Vision/Y. Gao 10
Image Enhancement -- Transformations

2.2. Contrast
stretching

For a low-contrast
image, we feel it
uncomfortable and
sometimes can not
see details clearly.

Image Processing & Machine

Vision/Y. Gao 11
Image Enhancement -- Transformations

Mathematically, We have following transform for stretching

contrast.
s ⋅r1

r 1
0 ≤ r < r1
(s − s )
s = T ( r ) = { ( − ) ⋅ (r − r ) + s r1≤ r < r
2 1

r r 2 1
1 1 2

(L − 1 − s )
⋅ (r − r ) + s
2 r2≤r < L − 1
(L − 1 − r ) 2
2 2

Image Processing & Machine

Vision/Y. Gao 12
Image Enhancement -- Transformations

Special cases:
When

r 1
= s and r = s
1 2 2
----------------- No change
--- Thresholding, which
r = r , s = 0 and s = L −1
1 2 1 2 produces a binary image

r 1
≤ r 2 and s ≤s
1 2 --- General, adjusting contrast

Image Processing & Machine

Vision/Y. Gao 13
Image Enhancement -- Transformations

When the dynamic range of the grey-level in an image far exceeds

the capability of the display device, it needs to be compressed to
display it better.

Image Processing & Machine

Vision/Y. Gao 14
Image Enhancement -- Transformations

T(r)

Image Processing & Machine

Vision/Y. Gao 15
Image Enhancement -- Transformations

6

6
So

When the dynamic range of the display device is [0,255], we have

255
c= ≈ 40
6.4
The transform result is shown as follows

Image Processing & Machine

Vision/Y. Gao 16
Image Enhancement -- Transformations

Image Processing & Machine

Vision/Y. Gao 17
Image Enhancement -- Transformations

2.4. Gray-level slicing

Sometimes need to highlight a specific range of gray
levels in an image.

Two approaches:
1. A high value for all gray levels in the range of
interest and a low value for all other gray levels.
2. Brighten the desired range of gray levels but
preserve all other parts including background.

Image Processing & Machine

Vision/Y. Gao 18
Image Enhancement -- Transformations

Image Processing & Machine

Vision/Y. Gao 19
Image Enhancement -- Transformations

2.5. Bit-plane slicing

Suppose we use one byte ( 8 bits ) to store the gray level value
for each pixel, as follows

bbbbbbbb
7 6 5 4 3 2 1 0

For all pixels in an image we take all bits in the same position,
which makes a bit-plane.

Image Processing & Machine

Vision/Y. Gao 20
Image Enhancement -- Transformations

Usually higher order bit-plane contains much more visual data,

Bit-plane b7 is the most significant for the image but
Bit-plane b0 is the least significant

Image Processing & Machine

Vision/Y. Gao 21
Image Enhancement -- Transformations

Image Processing & Machine

Vision/Y. Gao 22
Image Enhancement -- Transformations

Image Processing & Machine

Vision/Y. Gao 23
Image Enhancement -- Histogram

3. Histogram Processing

The distribution of the pixel grey level is very important

for an image display.

For a limited grey-level domain [0, L-1] we hope there is an

uniform distribution of the pixel grey level instead of non-
uniform distribution.

Based on the distribution of the pixel grey level we define

the image histogram.

Image Processing & Machine

Vision/Y. Gao 24
Image Enhancement -- Histogram

For a digital image with gray levels in the range [0, L-1], we
define a discrete function

n k

k k

n is the total number of pixels in the image.

We call p(r k ) the histogram of a digital image.

Image Processing & Machine

Vision/Y. Gao 25
Image Enhancement -- Histogram
p (r k) p (r k)

Bright image
Dark image

r k r k

p (r k ) p (r k )
Low-contrast image
High-contrast image

r k r k

Image Processing & Machine

Vision/Y. Gao 26
Image Enhancement -- Histogram

Image Processing & Machine

Vision/Y. Gao 27
Image Enhancement -- Histogram
Compute Histogram H of gray-level image I
procedure histogram (I,H) {
“Initialize all bins to zero”
for i:=0 to MaxVal
H[i]:=0;
“Compute values”
for L:=0 to MaxRow
for P:=0 to MaxCol {
grayval:= I[L,P];
H[grayval]:= H[grayval] + 1;
}
}
Image Processing & Machine
Vision/Y. Gao 28
Image Enhancement -- Histogram

Sometimes we need to convert a low-contrast image

into a high-contrast image for displaying it better.

We can do it by extending its histogram

---- histogram equalization

For our discussion, we suppose the gray level r is a

continuous quantity and normalized with the range [0,1].

And the enhancement transform function is s=T( r );

Image Processing & Machine
Vision/Y. Gao 29
Image Enhancement -- Histogram

(1) T( r ) is a single-valued and monotonically increasing for r

between [0,1];

(2) 0 ≤ T ( r ) ≤ 1 for 0 ≤ r ≤1

Condition (1) preserves the order in the gray scale;

Condition (2) guarantees a mapping with the range [0,1];

Image Processing & Machine

Vision/Y. Gao 30
Image Enhancement -- Histogram

−1

Image Processing & Machine

Vision/Y. Gao 31
Image Enhancement -- Histogram

Assume the probability density functions of the gray level for the
original image and transformed image are respectively
p (r ) and p ( s)
r s

r
Set s = T (r ) = ∫ p ( w)dw 0 ≤ r ≤ 1
0 r

ds  dr 
So, = pr (r ) Q p ( s ) = p r (r )
dr s
ds  T r=
−1
(s)

 1 
∴ p ( s ) =  p r (r )  =1 0 ≤ s ≤1
p r (r ) 
s

 T r=
−1
(s)

Image Processing & Machine

Vision/Y. Gao 32
Image Enhancement -- Histogram

It means that the probability density of the gray level for the
transformed image is uniform
r
s = T (r ) = ∫ p ( w)dw 0 ≤ r ≤ 1
0 r

For the digital image, we have

p (r ) = n 0 ≤ r ≤ 1 and k = 0,1,...L − 1
k
k
k
r
n
k
n k

sk = T (r k ) = ∑ = ∑ pr (r j )
j

j =0 n j =0
So,
0 ≤ r ≤ 1 and k = 0,1,......., L − 1
Image Processing & Machine
Vision/Y. Gao 33
Image Enhancement -- Histogram

n
p (r ) = n
k

r k n k r k
n
k
s k 1000

r =0
0 790 0.19 0.19
500
r = 17
1 1023 0.25 0.44
r = 27
2 850 0.21 0.65 r k
1
r = 37
3 656 0.16 0.81 n k
1000
r = 47
4 329 0.08 0.89
r = 57
5 245 0.06 0.95 500

r = 67
6
122 0.03 0.98
r =1
7 81 0.02 1.00 1
s k

Image Processing & Machine

Vision/Y. Gao 34
Image Processing & Machine
Vision/Y. Gao 35
Image Enhancement -- Histogram

Sometimes we need to convert an image into another image

with a specific gray level distribution.

Let pr (r ) and p z (z ) be the original and desired probability

density functions respectively.

Image Processing & Machine

Vision/Y. Gao 36
Image Enhancement -- Histogram

r
s = T (r ) = ∫ p ( w)dw
0 r

z
v = G( z) = ∫ p ( w)dw
0 z

We think s and v are the same. So,

z = G (v )
−1
Q substitute s with v,
∴ z = G ( s ) = G (T (r ))
−1 −1

Image Processing & Machine

Vision/Y. Gao 37
Image Enhancement -- Histogram

The procedure can be summarized as follows,

(1) Equalize the original image using
r
s = T (r ) = ∫ p ( w)dw
0 r

(2) Equalize the desired image using

z
v = G( z) = ∫ p ( w)dw
0 z

(3) Apply the inverse transformation function z =

−1
G (s)
we can get the value z.

Image Processing & Machine

Vision/Y. Gao 38
Image Enhancement -- Histogram

Image Processing & Machine

Vision/Y. Gao 39
Image Enhancement -- Histogram

When histogram equalization and histogram matching are used

to all sub-images in an image, we call it local enhancement.

Take the neighborhood of a point, for example 5x5, do the

enhancement for all points.

An example is as follow.

Image Processing & Machine

Vision/Y. Gao 40
Image Enhancement -- Histogram

Image Processing & Machine

Vision/Y. Gao 41
Image Enhancement – Arithmetic/Logic

4.1. Image Subtraction

g ( x, y ) = f ( x, y ) − h ( x, y )
The result is that the different parts between two image are kept
but the same parts between them are removed (become dark).

A typical application is the medical X-ray image test for a specific

body area of the patient.

We can do it by injecting some dye into the parts to be tested to

let them differ from others.

Image Processing & Machine

Vision/Y. Gao 42
Image Enhancement – Arithmetic/Logic

Image Processing & Machine

Vision/Y. Gao 43
Image Enhancement – Arithmetic/Logic

Assume a noisy image can be expressed as the following

g ( x, y ) = f ( x, y ) + η ( x, y )
f ( x, y ) is an original image

η ( x, y ) is the noise

Image Processing & Machine

Vision/Y. Gao 44
Image Enhancement – Arithmetic/Logic

When we acquire a set of noisy images {g ( x, y )} , we compute

i
the average value
1 M
1 M
g ( x, y ) = ∑ g i ( x, y ) = ∑ [ f ( x, y ) + η (x, y)]
M i =1 M i =1
i

1 M
= f ( x, y ) + ∑ η ( x, y )
M i =1 i

1 M
When M → ∞, ∑ η ι
( x, y ) → 0 ∴ g ( x, y ) → f ( x, y )
M i =1

Image Processing & Machine

Vision/Y. Gao 45
Image Processing & Machine
Vision/Y. Gao 46
Image Enhancement – Filtering

5. Filtering

Removing or intensifying some components in an image by using

enhancement processing is called filtering.

Using spatial masks to process an image is called spatial filtering

Using the Fourier transform to process an image is called
Frequency domain filtering.

Image Processing & Machine

Vision/Y. Gao 47
Image Enhancement – Filtering

1) A great change of gray level between the pixels usually stands

for some obvious contours in an image and it corresponds to the
high frequency components in an image.
2) Averaging the pixel grey levels in an image will let a digital
image become blurring.
3) Intensifying the high frequency components in an image will
let a digital image have obvious contours.

Image Processing & Machine

Vision/Y. Gao 48
Image Enhancement – Filtering

An example

Image Processing & Machine

Vision/Y. Gao 49
Image Enhancement – Filtering

– convolution.

(1) What is a mask: A mask is a set of pixel positions with values

called weights. A 3x3 mask is as follows.

w 1 w 2 w
3 11 w1 2 w13
11 w2 2 w1
3

w 4 w5 w 6 w1 4 w15 w1 6 w2
4 w4
5 w2 6

w 7 w8 w
9 w1 7 w18 w
1 9 w1
7 w2
8 w
19

Image Processing & Machine

Vision/Y. Gao 50
Image Enhancement – Filtering

(2) How to use a mask:

For any point (x,y) in the image, align the center of the mask to it.
We have 9
f new ( x, y ) = ∑ wi z i
i =1

z 1 z 2 z 3 w 1 w 2 w
3

z 4 z 5 z 6 w 4 w
5 w 6

z 7 z 8 z 9 w 7 w
8 w
9

(x,y)

Image Processing & Machine

Vision/Y. Gao 51
Image Enhancement – Filtering

For low-pass filtering --- called smooth processing

1 1 1 1 1
1 1 1 1 1 1 1 1
1 1
× 1 1 1 × 1 1 1 1 1
9 25
1 1 1 1 1 1 1 1
1 1 1 1 1

Image Processing & Machine

Vision/Y. Gao 52
Image Enhancement – Filtering

Image Processing & Machine

Vision/Y. Gao 53
Image Enhancement – Filtering

Image Processing & Machine

Vision/Y. Gao 54
Image Enhancement – Filtering

Median filter – less blurring and effective in removing salt

and pepper noise.

Image Processing & Machine

Vision/Y. Gao 55
Image Enhancement – Filtering

For High-pass filtering

− 1 − 1 − 1 − 1− 1
−1 −1 −1 − 1 − 1 − 1 − 1− 1
1 1
× −1 w −1 × − 1 − 1 w − 1− 1
9 25
− 1 − 1 − 1 − 1− 1
−1 −1 −1
− 1 − 1 − 1 − 1− 1

Image Processing & Machine

Vision/Y. Gao 56
Image Enhancement – Filtering

Image Processing & Machine

Vision/Y. Gao 57
Image Processing & Machine
Vision/Y. Gao 58
Image Processing & Machine
Vision/Y. Gao 59