You are on page 1of 46

Intensity transformation and spatial filtering

Digital Image Processing Lecture 3 Intensity Transformation& Spatial Filtering


Lecturer: Ha Dai Duong Faculty of Information Technology

I. Introduction

Spatial Domain vs. Transform Domain


Spatial Domain

Image plane itself, directly process the intensity values of the image plane Process the transform coefficients, not directly process the intensity values of the image plane

Transform (Frequency) domain


Digital Image Processing

Intensity transformation and spatial filtering

I. Introduction

Spatial Domain Process

g ( x, y ) = T [ f ( x, y )]) f ( x, y ) : input image g ( x, y ) : output image T : an operator on f defined over a neighborhood of point ( x, y )
3

Digital Image Processing

I. Introduction

Spatial Domain Process

Digital Image Processing

Intensity transformation and spatial filtering

II. Intensity transformation function


Intensity transformation function s = T (r )

Digital Image Processing

II. Intensity transformation function


Some basic Functions

intensity

transformation

Digital Image Processing

Intensity transformation and spatial filtering

II.1. Negative
Image negatives s = L 1 r

Digital Image Processing

II.1. Negative

Small lesion

Digital Image Processing

Intensity transformation and spatial filtering

II.2. Log Transform


Log Transformations s = c log(1 + r )

Digital Image Processing

II.2. Log Transform

Digital Image Processing

10

Intensity transformation and spatial filtering

II.3. Power Law

s = cr

Digital Image Processing

11

II.3. Power Law

Digital Image Processing

12

Intensity transformation and spatial filtering

II.3. Power Law

Digital Image Processing

13

II.4. Piecewise-Linear Transform..



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

Digital Image Processing

14

Intensity transformation and spatial filtering

II.4. Piecewise-Linear Transform

Digital Image Processing

15

Digital Image Processing

16

Intensity transformation and spatial filtering

II.5. Bit Plane Slicing

Digital Image Processing

17

II.5. Bit Plane Slicing

Digital Image Processing

18

Intensity transformation and spatial filtering

III. Histogram processing


Histogram Equalization Histogram Matching Local Histogram Processing Using Histogram Statistics Enhancement

for

Image

Digital Image Processing

19

III. Histogram processing


Histogram h(rk ) = nk rk is the k th intensity value nk is the number of pixels in the image with intensity rk

nk MN nk : the number of pixels in the image of Normalized histogram p (rk ) = size M N with intensity rk
Digital Image Processing
20

10

Intensity transformation and spatial filtering

III. Histogram processing


No. of pixels
6

2 4 3 2

3 2 2 4

3 4 3 2

2 3 5 4

5 4 3 2 1

4x4 image Gray scale = [0,9]


Digital Image Processing

Gray level
0 1 2 3 4 5 6 7 8 9

histogram
21

III. Histogram processing

Digital Image Processing

22

11

Intensity transformation and spatial filtering

III.1. Histogram Equalization


As the low-contrast images histogram is narrow and centered toward the middle of the gray scale, if we distribute the histogram to a wider range the quality of the image will be improved. We can do it by adjusting the probability density function of the original histogram of the image so that the probability spread equally

Digital Image Processing

23

III.1. Histogram Equalization


Histogram transformation
s

s = T(r)
Where 0 r 1 T(r) satisfies

sk= T(rk) T(r)

(a). T(r) is single-valued and monotonically increasingly in the interval 0r1 (b). 0 T(r) 1 for 0r1

rk

r
24

Digital Image Processing

12

Intensity transformation and spatial filtering

III.1. Histogram Equalization


2 conditions of T(r)

Single-valued (one-to-one relationship) guarantees that the inverse transformation will exist Monotonicity condition preserves the increasing order from black to white in the output image thus it wont cause a negative image 0 T(r) 1 for 0 r 1 guarantees that the output gray levels will be in the same range as the input levels. The inverse transformation from s back to r is r = T -1(s) ; 0 s 1
Digital Image Processing
25

III.1. Histogram Equalization


Let

pr(r) denote the PDF of random variable r ps(s) denote the PDF of random variable s

If pr(r) and T(r) are known and T-1(s) satisfies condition (a) then ps(s) can be obtained using a formula :

ps(s) = pr(r)
Digital Image Processing

dr ds
26

13

Intensity transformation and spatial filtering

III.1. Histogram Equalization


A transformation function is a cumulative distribution function (CDF) of random variable r :

s = T ( r ) = pr ( w )dw
0

CDF is an integral of a probability function (always positive) is the area under the function Thus, CDF is always single valued and monotonically increasing Thus, CDF satisfies the condition (a) We can use CDF as a transformation function

Digital Image Processing

27

III.1. Histogram Equalization


ds dT ( r ) = dr dr r d p ( w ) dw = r dr 0 = pr ( r )

p s ( s ) = pr ( r ) = pr ( r )

dr ds 1 pr ( r )

Substitute and yield

= 1 where 0 s 1
28

Digital Image Processing

14

Intensity transformation and spatial filtering

III.1. Histogram Equalization


Ps(s):

As ps(s) is a probability function, it must be zero outside the interval [0,1] in this case because its integral over all values of s must equal 1. Called ps(s) as a uniform probability density function ps(s) is always a uniform, independent of the form of pr(r)

Digital Image Processing

29

III.1. Histogram Equalization


Discrete Transformation Function


The probability of occurrence of gray level in an image is approximated by n where k = 0 , 1 , ..., L- 1 p r ( rk ) = k n The discrete version of transformation
s k = T ( rk ) = =

j=0

pr ( rj ) = 0 , 1 , ..., L- 1
30

nj n

where k

j=0

Digital Image Processing

15

Intensity transformation and spatial filtering

III.1. Histogram Equalization


Thus, an output image is obtained by mapping each pixel with level rk in the input image into a corresponding pixel with level sk in the output image In discrete space, it cannot be proved in general that this discrete transformation will produce the discrete equivalent of a uniform probability density function, which would be a uniform histogram

Digital Image Processing

31

III.1. Histogram Equalization


Example

before

after

Histogram equalization

Digital Image Processing

32

16

Intensity transformation and spatial filtering

III.1. Histogram Equalization


Example
before after Histogram equalization

The quality is not improved much because the original image already has a broaden gray-level scale
Digital Image Processing
33

III. Histogram processing


No. of pixels
6

2 4 3 2

3 2 2 4

3 4 3 2

2 3 5 4

5 4 3 2 1

4x4 image Gray scale = [0,9]


Digital Image Processing

Gray level
0 1 2 3 4 5 6 7 8 9

histogram
34

17

Intensity transformation and spatial filtering

III.1. Histogram Equalization


Example
0
0 0 0 0

Gray Level No.of pixels

1
0 0 0 0

2
6 6
6/ 16

3
5 11

4
4 15

5
1 16

6
0 16

7
0 16

8
0 16

9
0 16

n
k

j=0

s=
j =0

nj n

11 / 15 / 16 / 16/ 16/ 16/ 16/ 16 16 16 16 16 16 16

sx9

3.3 3

6.1 6

8.4 8

9
35

Digital Image Processing

III.1. Histogram Equalization


Example
3 8 6 3 6 3 3 8 6 8 6 3 3 6 9 8

No. of pixels
6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9

Output image Gray scale = [0,9]


Digital Image Processing

Gray level Histogram equalization


36

18

Intensity transformation and spatial filtering

III.2. Histogram Matching


Generate a processed image that has a specified histogram


Let pr ( r ) and pz ( z ) denote the continous probability density functions of the variables r and z. pz ( z ) is the specified probability density function. Let s be the random variable with the probability s = T (r ) = ( L 1) pr ( w)dw
0 r

Define a random variable z with the probability G ( z ) = ( L 1) pz (t )dt = s


0 z

Digital Image Processing

37

III.2. Histogram Matching

s = T ( r ) = ( L 1) p r ( w ) dw
0

G ( z ) = ( L 1) p z ( t ) dt = s
0

z = G 1 ( s ) = G 1 [T (r ) ]
Digital Image Processing
38

19

Intensity transformation and spatial filtering

III.2. Histogram Matching


Procedure
1.

Obtain pr(r) from the input image and then obtain the values of s

s = ( L 1) pr ( w)dw
0

2.

Use the specified PDF and obtain the transformation function G(z)

G ( z ) = ( L 1) pz (t )dt = s
0

3.

Mapping from s to z

z = G 1 ( s )
Digital Image Processing
39

III.2. Histogram Matching


Example
Assume an image has a gray level probability density function pr(r) as shown. Pr(r) 2 1 0 1 2 r
40

2 r + 2 ;0 r 1 pr ( r ) = ; elsewhere 0

p r ( w ) dw = 1

Digital Image Processing

20

Intensity transformation and spatial filtering

III.2. Histogram Matching


Example
We would like to apply the histogram specification with the desired probability density function pz(z) as shown. Pz(z) 2 1 0
Digital Image Processing

2z pz ( z ) = 0

;0 z 1 ; elsewhere
z

p
0

( w )dw = 1

41

III.2. Histogram Matching


Example
s=T(r) 1

1. Obtain the transformation function T(r)

s = T ( r ) = pr ( w )dw
0

= ( 2 w + 2 )dw
0

= w 2 + 2w
0
Digital Image Processing

r 0

= r + 2r
2
42

21

Intensity transformation and spatial filtering

III.2. Histogram Matching


Example
2. Obtain the transformation function G(z)

G ( z ) = ( 2 w )dw
0

= z2

z 0

= z2

Digital Image Processing

43

III.2. Histogram Matching


Example

3. Obtain the inversed transformation function G-1

G ( z ) = T (r ) z 2 = r 2 + 2r z = 2r r 2
We can guarantee that 0 z 1 when 0 r 1
Digital Image Processing
44

22

Intensity transformation and spatial filtering

III.2. Histogram Matching


Procedure in discrete cases


1.

Obtain pr(rj) from the input image and then obtain the values of sk, round the value to the integer range [0, L-1]

sk = T (rk ) = ( L 1) pr (rj ) =
j =0

( L 1) k nj MN j =0

2.

Use the specified PDF and obtain the transformation function G(zq), round the value to the integer range [0, L-1].

G ( zq ) = ( L 1) pz ( zi ) = sk
i =0

3.

Mapping from sk to zq

zq = G 1 ( sk )
Digital Image Processing
45

III.2. Histogram Matching


Example

Suppose that a 3-bit image (L=8) of size 64 64 pixels (MN = 4096) has the intensity distribution shown in the following table (on the left). Get the histogram transformation function and make the output image with the specified histogram, listed in the table on the right.

Digital Image Processing

46

23

Intensity transformation and spatial filtering

III.2. Histogram Matching


Example
Obtain the scaled histogram-equalized values,

s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 7, s5 = 7, s6 = 7, s7 = 7.
Compute all the values of the transformation function G,

G ( z0 ) = 7 pz ( z j ) = 0.00
j =0

0
s0 s2

G ( z1 ) = 0.00 0 G ( z5 ) = 4.55 5

G ( z3 ) = 1.05 1 G ( z7 ) = 7.00 7
Digital Image Processing

0 G ( z4 ) = 2.45 2 s1
G ( z2 ) = 0.00 G ( z6 ) = 5.95
s7
47

6 s3

s4 s5 s6

III.2. Histogram Matching


Example
rk 0 1 2 3 4 5 6 7
Digital Image Processing

s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 7, s5 = 7, s6 = 7, s7 = 7.

rk zq 03 1 4 25 36 47 57 67 77
48

24

Intensity transformation and spatial filtering

III.2. Histogram Matching


Example

Digital Image Processing

49

III.2. Histogram Matching


Example

Digital Image Processing

50

25

Intensity transformation and spatial filtering

III.3. Local Histogram Processing


Define a neighborhood and move its center from pixel to pixel At each location, the histogram of the points in the neighborhood is computed. Either histogram equalization or histogram specification transformation function is obtained Map the intensity of the pixel centered in the neighborhood Move to the next location and repeat the procedure

Digital Image Processing

51

III.3. Local Histogram Processing

Digital Image Processing

52

26

Intensity transformation and spatial filtering

III.4. Using Histogram Statistics


Average Intensity

m = ri p (ri )
i =0
L 1 i =0

L 1

1 = MN

M 1 N 1 x =0 y =0

f ( x, y )

un (r ) = (ri m) n p (ri )
Variance
2 L 1 i =0

= u2 (r ) = (ri m) 2 p(ri )

1 MN

M 1 N 1 x =0 y =0

[ f ( x, y ) m ]

Digital Image Processing

53

III.4. Using Histogram Statistics


Local average intensity msxy = ri psxy (ri )
i =0 L 1

sxy denotes a neighborhood


Local variance
L 1 i =0

s2 = (ri ms )2 ps (ri )
xy xy xy

Digital Image Processing

54

27

Intensity transformation and spatial filtering

III.4. Using Histogram Statistics


E f ( x, y ), if msxy k0 mG and k1 G sxy k2 G g ( x, y ) = otherwise f ( x, y ), mG : global mean;

G : global standard deviation

k0 = 0.4; k1 = 0.02; k2 = 0.4; E = 4

Digital Image Processing

55

IV. Using Arithmetic/Logic Operators


Arithmetic/Logic operations perform on pixel by pixel basis between two or more images, except NOT operation which perform only on a single image Logic operation performs on gray-level images, the pixel values are processed as binary numbers:

Light represents a binary 1, and Dark represents a binary 0


56

Digital Image Processing

28

Intensity transformation and spatial filtering

IV.1. Logic Operators

Digital Image Processing

57

IV.2. Image Subtraction

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


Extraction of the differences between images

Digital Image Processing

58

29

Intensity transformation and spatial filtering

IV.3. Image Averaging


Consider a noisy image g(x,y) formed by the addition of noise (x,y) to an original image f(x,y)

g(x,y) = f(x,y) + (x,y)


If noise has zero mean and be uncorrelated then it can be shown that if

g ( x, y )

= image formed by averaging K different noisy images

1 g ( x, y ) = K
Digital Image Processing

g ( x, y )
i =1 i
59

IV.3. Image Averaging


Then

2 g ( x, y ) =
2 g ( x , y ) , 2 ( x , y )

1 2 ( x, y ) K
= variances of g and

if K increase, it indicates that the variability (noise) of the pixel at each location (x,y) decreases.
Digital Image Processing
60

30

Intensity transformation and spatial filtering

IV.3. Image Averaging


Thus

E{g ( x, y )} = f ( x, y )

E{ g ( x , y )}

= expected value of g (output after averaging) = original image f(x,y)

Digital Image Processing

61

V. Spatial Filtering
A spatial filter consists of (a) a neighborhood, and (b) a predefined operation Linear spatial filtering of an image of size MxN with a filter of size mxn is given by the expression

g ( x, y ) =

s = a t = b

w(s, t ) f ( x + s, y + t )

Digital Image Processing

62

31

Intensity transformation and spatial filtering

V. Spatial Filtering

Example

M=3, N=3 3x3 Or M=5, N=5 5x5

Digital Image Processing

63

V.1. Smoothing Filters


Smoothing filters are used for blurring and for noise reduction Blurring is used in removal of small details and bridging of small gaps in lines or curves Smoothing spatial filters include linear filters and nonlinear filters.

Digital Image Processing

64

32

Intensity transformation and spatial filtering

V.1. Smoothing Filters


Linear filters
The general implementation for filtering an M N image with a weighted averaging filter of size m n is given g ( x, y ) =
s = a t = b

w(s, t ) f ( x + s, y + t )
s = a t = b

w(s, t )
n = 2b + 1.

where m = 2a + 1,

Digital Image Processing

65

V.1. Smoothing Filters


Linear filters

Averaging Filter Masks

Digital Image Processing

66

33

Intensity transformation and spatial filtering


a c e b d f

V.1. Smoothing Filters



Example
Averaging Filter Masks a). original image 500x500 pixel b). - f). results of smoothing with square averaging filter masks of size n = 3, 5, 9, 15 and 35, respectively. Note:

Big mask is used to eliminate small objects from an image. The size of the mask establishes the relative size of the objects that will be blended with the background.
67

Digital Image Processing

V.1. Smoothing Filters


Example

original image

result after smoothing with 15x15 averaging mask

result of thresholding

we can see that the result after smoothing and thresholding, the remains are the largest and brightest objects in the image.
Digital Image Processing
68

34

Intensity transformation and spatial filtering

V.1. Smoothing Filters



Order-Statistics Filters (Nonlinear Filters)


The response is based on ordering (ranking) the pixels contained in the image area encompassed by the filter Example

Median filter : R = median{zk |k = 1,2,,n x n} Max filter : R = max{zk |k = 1,2,,n x n} Min filter : R = min{zk |k = 1,2,,n x n}

Note: n x n is the size of the mask

Digital Image Processing

69

V.1. Smoothing Filters



Median Filter
Median: X= {x1,x2,, x2b+1}, x is called the median of X if x greater than or equal b elements and less than or equal b other elements in X; For example: X={3,2,3,2,3,4,5,6,5} (b=4) -> Median is 3 Peplaces the value of a pixel by the median of the gray levels in the neighborhood of that pixel (the original value of the pixel is included in the computation of the median) Quite popular because for certain types of random noise (impulse impulse noise salt and pepper noise) , they provide excellent noisenoise noisereduction capabilities, capabilities with considering less blurring than linear smoothing filters of similar size

Digital Image Processing

70

35

Intensity transformation and spatial filtering

V.1. Smoothing Filters


Median Filter

Example

Digital Image Processing

71

V.2. Sharpening Spatial Filters


Foundation Laplacian Operator Unsharp Masking and Highboost Filtering Using First-Order Derivatives for Nonlinear Image Sharpening - The Gradient
Digital Image Processing
72

36

Intensity transformation and spatial filtering

V.2. Sharpening Spatial Filters

The first-order derivative of a one-dimensional function f(x) is the difference

f = f ( x + 1) f ( x) x

The second-order derivative of f(x) as the difference

2 f = f ( x + 1) + f ( x 1) 2 f ( x) x 2
73

Digital Image Processing

V.2. Sharpening Spatial Filters


Foundation

Digital Image Processing

74

37

Intensity transformation and spatial filtering

V.3. Method based on Laplace Operator


Laplace Operator
The second-order isotropic derivative operator is the Laplacian for a function (image) f(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 2 f f = 2 + 2 x y
2

2 f = f ( x + 1, y ) + f ( x 1, y ) + f ( x, y + 1) + f ( x, y 1) - 4 f ( x, y )
Digital Image Processing
75

V.3. Method based on Laplace Operator


Masks

Digital Image Processing

76

38

Intensity transformation and spatial filtering

V.3. Method based on Laplace Operator


Image sharpening in the way of using the Laplacian:

where g(x,y) sharpened image

Digital Image Processing

77

V.3. Method based on Laplace Operator


Example

Digital Image Processing

78

39

Intensity transformation and spatial filtering

V.4. Unsharp Masking and Highboost Filtering

Digital Image Processing

79

V.4. Unsharp Masking and Highboost Filtering

Digital Image Processing

80

40

Intensity transformation and spatial filtering

V.4. Unsharp Masking and Highboost Filtering

Digital Image Processing

81

V.4. Unsharp Masking and Highboost Filtering


Example

Digital Image Processing

82

41

Intensity transformation and spatial filtering

V.4. Unsharp Masking and Highboost Filtering


Example

Digital Image Processing

83

V.5. Method based Derivatives (Gradient)

on

First-Order

For function f ( x, y ), the gradient of f at coordinates ( x, y ) is defined as f g x x f grad( f ) = g y f y

The magnitude of vector f , denoted as M ( x, y ) M ( x, y ) = mag(f ) = g x 2 + g y 2


Digital Image Processing
84

42

Intensity transformation and spatial filtering

V.5. Method based Derivatives (Gradient)

on

First-Order

The magnitude of vector f , denoted as M ( x, y ) M ( x, y ) = mag(f ) = g x 2 + g y 2

M ( x, y ) | g x | + | g y |
z1 z4 z7 z2 z5 z8 z3 z6 z9
85

M ( x, y ) =| z8 z5 | + | z6 z5 |

Digital Image Processing

V.5. Method based Derivatives (Gradient)

on

First-Order

Roberts Cross-gradient Operators M ( x, y ) | z9 z5 | + | z8 z6 |

z1 z4 z7

z2 z5 z8

z3 z6 z9

Sobel Operators M ( x, y ) | ( z7 + 2 z8 + z9 ) ( z1 + 2 z2 + z3 ) | + | ( z3 + 2 z6 + z9 ) ( z1 + 2 z4 + z7 ) |

Digital Image Processing

86

43

Intensity transformation and spatial filtering

V.5. Method based Derivatives (Gradient)

on

First-Order

Digital Image Processing

87

V.5. Method based Derivatives (Gradient)


on

First-Order

Example

Digital Image Processing

88

44

Intensity transformation and spatial filtering

V.6. Combining Spatial Enhancement Methods


Solve:

1. Laplacian to highlight fine detail 2. Gradient to enhance prominent edges 3. Gray-level transformation to increase the dynamic range of gray levels

Digital Image Processing

89

V.6. Combining Spatial Enhancement Methods


Exampe

Digital Image Processing

90

45

Intensity transformation and spatial filtering

V.6. Combining Spatial Enhancement Methods


Exampe

Digital Image Processing

91

46

You might also like