Image Enhancement – Introduction Processing & Machine Vision/Y. Gao 3 Image Enhancement --...

Preview:

Citation preview

Image Processing & Machine Vision/Y. Gao 1

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 2

Image Enhancement – Introduction

1.2 Categories of methods for enhancement process.

Spatial domain: process pixels in the image plane directly.

Frequency domain: modify the Fourier transform of an image.

Image Processing & Machine Vision/Y. Gao 3

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 4

Image Enhancement – Introduction

Grey-level value transform graph

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

r

sT(r)

r

sT(r)

r

s

T(r)

No change image brighter image darker

Image Processing & Machine Vision/Y. Gao 5

Image Enhancement – Introduction

Two simple examples for contrast enhancement

x

Image Processing & Machine Vision/Y. Gao 6

Image Enhancement – Introduction

For the enhancement in the frequency domain, according to the convolution theorem we have

),( yxh ),( yxg),( yxf

),( vuH),( vuF ),( vuG

Image Processing & Machine Vision/Y. Gao 7

Image Enhancement – Introduction

)],(),([ ),(

),(),(),(),(),(),(

1- vuFvuHyxg

vuFvuHvuGyxfyxhyxg

=

=∗=

F

)],([ ),()],([ ),()],([ ),(

yxgvuGyxhvuHyxfvuF

=== F

FF

Image Processing & Machine Vision/Y. Gao 8

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 9

Image Enhancement -- Transformations

2. Transformations

2.1. Image negatives

0

T(r)s

r

L-1

rLrTs −−== 1)(

L-1

Image Processing & Machine Vision/Y. Gao 10

Image Enhancement -- Transformations

Image Processing & Machine Vision/Y. Gao 11

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 12

Image Enhancement -- Transformations

Mathematically, We have following transform for stretching contrast.

srrs

srrrss

rs

rLL

r

r

222

2

1112

12

1

1

)()1()1(

)()()(

+−⋅−−−−

+−⋅−−

{)( == rTs12

1

0

2

1

−<≤<≤<≤

Lrrrrrrr

Image Processing & Machine Vision/Y. Gao 13

Image Enhancement -- Transformations

Special cases:

When

ssrr

ssrrsrsr

L

2121

2121

2211

and

1 and 0,

and

≤≤

−===

== ----------------- No change

--- Thresholding, which produces a binary image

--- General, adjusting contrast

Image Processing & Machine Vision/Y. Gao 14

Image Enhancement -- Transformations

2.3. Compression of dynamic range

When the dynamic range of the grey-level in an image far exceedsthe capability of the display device, it needs to be compressed to display it better.

A good transform function (Log transform) is as follow,

)1log( rcs +⋅= c is a scaling constant

Image Processing & Machine Vision/Y. Gao 15

Image Enhancement -- Transformations

T(r)

s

r

Image Processing & Machine Vision/Y. Gao 16

Image Enhancement -- Transformations

For example, an image with dynamic range

So

[ ]105.2,0[],0 6×=R

4.6)1log( 105.2 6 ≈+ ×When the dynamic range of the display device is [0,255], we have

404.6

255 ≈=c

The transform result is shown as follows

Image Processing & Machine Vision/Y. Gao 17

Image Enhancement -- Transformations

Image Processing & Machine Vision/Y. Gao 18

Image Enhancement -- Transformations

2.4. Gray-level slicingSometimes 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 19

Image Enhancement -- Transformations

Image Processing & Machine Vision/Y. Gao 20

Image Enhancement -- Transformations

2.5. Bit-plane slicingSuppose we use one byte ( 8 bits ) to store the gray level valuefor each pixel, as follows

bbbbbbbb 01234567

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 21

Image Enhancement -- Transformations

Usually higher order bit-plane contains much more visual data, Bit-plane is the most significant for the image but Bit-plane is the least significant

b7

b0

Image Processing & Machine Vision/Y. Gao 22

Image Enhancement -- Transformations

Image Processing & Machine Vision/Y. Gao 23

Image Enhancement -- Transformations

Image Processing & Machine Vision/Y. Gao 24

Image Enhancement -- Histogram

3. Histogram Processing

3.1. What is the histogram of an image?

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 anuniform 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 25

Image Enhancement -- Histogram

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

rnr kk

k np )( =

is the number of the pixels with the gray levelnk rkis the total number of pixels in the image.

We call the histogram of a digital image.

Four special histograms are as follows.

)(rkp

n

is the kth gray level.

Image Processing & Machine Vision/Y. Gao 26

Image Enhancement -- Histogram

)(r kp

r k

Dark image

)(r kp

r k

Bright image

)(r kp

r k

High-contrast image

)(r kp

r k

Low-contrast image

Image Processing & Machine Vision/Y. Gao 27

Image Enhancement -- Histogram

Image Processing & Machine Vision/Y. Gao 28

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 29

Image Enhancement -- Histogram

3.2. Histogram equalization

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 30

Image Enhancement -- Histogram

We also suppose that T( r ) satisfy the following two conditions,

(1) T( r ) is a single-valued and monotonically increasing for rbetween [0,1];

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

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 31

Image Enhancement -- Histogram

An example satisfying above conditions is as follow,

And the inverse transform can be denoted r 1 s 0 )(1 ≤≤= − sT

Image Processing & Machine Vision/Y. Gao 32

Image Enhancement -- Histogram

Assume the probability density functions of the gray level for theoriginal image and transformed image are respectively

Set

So,

)( and )( sr pp sr

1r0 )()(0

≤≤== ∫ dwwrTs r

rp

)(rdrds pr=

−=

=dsdrrpp r

T sr

ss )(

)(1

)( Q

10 1)( )(

1)()(1

≤≤==∴

−=

ssrp

rppr

rT sr

s

Image Processing & Machine Vision/Y. Gao 33

Image Enhancement -- Histogram

It means that the probability density of the gray level for thetransformed image is uniform

For the digital image, we have

So,

1r0 )()(0

≤≤== ∫ dwwrTs r

rp

1,...1,0 and 1 0 )( −=≤≤= Lkn rnrp kk

kr

1,.......,1,0 and 10

)()(00

−=≤≤

=== ∑∑==

Lkrn

T rpnrs j

k

jr

k

j

jkk

Image Processing & Machine Vision/Y. Gao 34

Image Enhancement -- Histogram

rk

17

67

57

47

37

27

10

7

6

5

4

3

2

1

0

=

=

=

=

=

=

=

=

rr

r

r

r

r

rr

nk

811222453296568501023790

02.003.006.008.016.021.025.019.0

nnrp k

kr=)( sk

00.198.095.089.081.065.044.019.0

1

1000

nk

500

rk

1000

nk

500

sk1

Image Processing & Machine Vision/Y. Gao 35

Image Processing & Machine Vision/Y. Gao 36

Image Enhancement -- Histogram

3.3. Histogram Matching (specification)

Sometimes we need to convert an image into another image with a specific gray level distribution.

Let and be the original and desired probabilitydensity functions respectively.

Firstly, we do the equalization transform for both of them.

)(rpr )(zpz

Image Processing & Machine Vision/Y. Gao 37

Image Enhancement -- Histogram

)()(0

dwwrTs r

rp∫==

We think s and v are the same. So,

substitute s with v,

)()(0

dwwzGv z

zp∫==

))(()(z )(

11

1

rTsvz

GGG

−−

==∴=Q

Image Processing & Machine Vision/Y. Gao 38

Image Enhancement -- Histogram

The procedure can be summarized as follows,(1) Equalize the original image using

(2) Equalize the desired image using

(3) Apply the inverse transformation functionwe can get the value z.

)()(0

dwwrTs r

rp∫==

)()(0

dwwzGv z

zp∫== )(1 sz G−=

Image Processing & Machine Vision/Y. Gao 39

Image Enhancement -- Histogram

The procedure above is also described as the following graph,

Image Processing & Machine Vision/Y. Gao 40

Image Enhancement -- Histogram

3.4. Local enhancement

When histogram equalization and histogram matching are usedto all sub-images in an image, we call it local enhancement.

Take the neighborhood of a point, for example 5x5, do theenhancement for all points.

An example is as follow.

Image Processing & Machine Vision/Y. Gao 41

Image Enhancement -- Histogram

Image Processing & Machine Vision/Y. Gao 42

Image Enhancement – Arithmetic/Logic

4.1. Image Subtraction

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 specificbody area of the patient.

We can do it by injecting some dye into the parts to be tested to let them differ from others.

),(),(),( yxhyxfyxg −=

Image Processing & Machine Vision/Y. Gao 43

Image Enhancement – Arithmetic/Logic

Image Processing & Machine Vision/Y. Gao 44

Image Enhancement – Arithmetic/Logic

4.2. Image Averaging

Assume a noisy image can be expressed as the following

is an original image

is the noise

And the noise is uncorrelated and has zero average value.

),),(),( yxyxfyxg (+= η

),(),(yxyxf

η

Image Processing & Machine Vision/Y. Gao 45

Image Enhancement – Arithmetic/Logic

When we acquire a set of noisy images , we compute)},({ yxgithe average value

When

),(1),(

y)](x,),([1),(1),(

1

11

yxM

yxf

yxfM

yxM

yxg

M

ii

M

ii

M

iig

∑∑

=

==

+=

+==

η

η

),(),( 0),(1 ,1

yxfyxgyxM

MM

i→∴→∞→ ∑

=ηι

Image Processing & Machine Vision/Y. Gao 46

Image Processing & Machine Vision/Y. Gao 47

Image Enhancement – Filtering

5. Filtering

Removing or intensifying some components in an image by usingenhancement processing is called filtering.

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

Image Processing & Machine Vision/Y. Gao 48

Image Enhancement – Filtering

5.1. Spatial Filtering

We need to know that

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 digitalimage become blurring.

3) Intensifying the high frequency components in an image willlet a digital image have obvious contours.

Image Processing & Machine Vision/Y. Gao 49

Image Enhancement – Filtering

An example

High frequency components

Low frequency components

Image Processing & Machine Vision/Y. Gao 50

Image Enhancement – Filtering

5.1.1. Mask

Applying a mask to an image is a basic concept in image processing – convolution.

(1) What is a mask: A mask is a set of pixel positions with values called weights. A 3x3 mask is as follows.

1 w2 w3

w4 w5 w6

w7 w8 w9

21 1

242

1 2 1

1 w2 w3

w4 w5 w6

w7 w8 w9

11 1

111

1 1 1

w1 w2 w3

w4 w5 w6

w7 w8 w9

Image Processing & Machine Vision/Y. Gao 51

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

w1 w2 w3

w4 w5 w6

w7 w8 w9

z1 z 2 z3

z 4 z5 z6

z7 z8 z9

zwyxf ii

inew ∑==

9

1),(

(x,y)

Image Processing & Machine Vision/Y. Gao 52

Image Enhancement – Filtering

5.1.2. Smoothing filters

For low-pass filtering --- called smooth processing

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1 1 11 1

1 1 1

1 1 1

1 1 1

×251

×91

1 1 11 1

Image Processing & Machine Vision/Y. Gao 53

Effects of mask sizes

Image Enhancement – Filtering

Image Processing & Machine Vision/Y. Gao 54

Image Enhancement – Filtering

Image Processing & Machine Vision/Y. Gao 55

Image Enhancement – Filtering

Median filter – less blurring and effective in removing salt and pepper noise.

Image Processing & Machine Vision/Y. Gao 56

Image Enhancement – Filtering

5.1.3. Sharpening filters

For High-pass filtering

w

1− 1− 1− 1− 1−

1− 1− 1− 1−1− 1− 1− 1− 1−

1− 1− 1− 1−1−

1−

w1− 1−

1− 1− 1−

1− 1− ×251

×91

1− 1− 1− 1−1−

Image Processing & Machine Vision/Y. Gao 57

Image Enhancement – Filtering

Other forms of filters

Image Processing & Machine Vision/Y. Gao 58

Image Processing & Machine Vision/Y. Gao 59

Recommended