chapter2_intensity transformations and spatial filtering

115
Ch2. Intensity Transformations and Spatial Filtering Digital Image Processing using MATLAB, Written by Gonzalez & Woods Image Processing 2012 Spring IELAB 1

Upload: shichibukai-aminnur

Post on 22-Oct-2014

143 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Chapter2_Intensity Transformations and Spatial Filtering

Ch2. Intensity Transformations and Spatial FilteringDigital Image Processing using MATLAB, Written by Gonzalez & Woods

Image Processing 2012 Spring

IELAB

1

Page 2: Chapter2_Intensity Transformations and Spatial Filtering

Introduction

Preview 2.1 Background 2.2 Intensity Transformation Functions 2.3 Histogram Processing and Function Plotting 2.4 Spatial Filtering 2.5 Image Processing Toolbox Standard Spatial Filters 2.6 Using Fuzzy Techniques for Intensity Transformations and

Spatial Filtering

2

Page 3: Chapter2_Intensity Transformations and Spatial Filtering

Preview

Image enhancement approaches fall into two broad cate-gories Spatial domain methodsThe term spatial domain refers to the image plane itsef, and approaches in this category are based on direct manipulation of pixels in an image Frequency domain methodsThis techniques are based on modifying the Fourier transform of an image

MATLAB formulations representative of processing techniques in two categories Neighborhood processing Spatial convolution

3

Page 4: Chapter2_Intensity Transformations and Spatial Filtering

Preview

This chapter is focused on spatial filtering methods for image enhancement

In addition to this, image processing using a fuzzy set theory will be explained

4

Page 5: Chapter2_Intensity Transformations and Spatial Filtering

2.1 Background

Spatial domain processes will be denoted by the expres-sion

where is the input image, is the processed image, and is an operator on , defined over some neighborhood of

can operate on a set of input images

5

( , ) [ ( , )]g x y T f x y (3.1 1)

Page 6: Chapter2_Intensity Transformations and Spatial Filtering

2.1 Background

Definition of a neighborhood The principal approach in defining a

neighborhood about a point is to use a square or rectangular subimage area centered at

The center of region is moved from pixel to pixel starting at the top left corner; it encompasses different neighborhoods

The operator is applied at each lo-cation to yield the output, , at that location

6

Page 7: Chapter2_Intensity Transformations and Spatial Filtering

The simplest form of the transformation is when the neighborhood in Fig.3.1 is of size (a single pixel)

In this case, the value of at depends only on the intensity of at that point, and becomes an intensity or gray-level transformation function

2.2 Intensity Transformation Function

7

Page 8: Chapter2_Intensity Transformations and Spatial Filtering

2.2 Intensity Transformation Function

Intensity transformation functions are frequently written in simplified form as

where and denote the intensity of and , respectively

As an example, we will briefly look three basic intensity transformation functions in the next slide

8

Page 9: Chapter2_Intensity Transformations and Spatial Filtering

2.2 Intensity Transformation Function

Three basic types of functions used frequently for image en-hancement Linear (negative and identity

transformations) Logarithmic (log and inverse-log

transformations) Power-law (nth power and nth

root transformations)

9

Page 10: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

In MATLAB we can do intensity transformations by us-ing imadjust function which is located in Image Process-ing Toolbox

g = imadjust(f, [low_in high_in], [low_out high_out], gamma)

Parameter gamma specifies the shape of the curve that maps the intensity values in f to create g

10

Page 11: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

, the mapping is weighted toward brighter

, linear mapping

, the mapping is weighted toward darker

11

Page 12: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

Example 3.1 Contrast enhancement

using power-law transfor-mations(with )

12

As gamma decreased from 0.6 to 0.4, more detail became visible

A further decrease of gamma to 0.3 enhanced a little more detail in the background, but began to reduce contrast to the point where the image started to have a very slight “washed-out” look, especially in the background

Page 13: Chapter2_Intensity Transformations and Spatial Filtering

Example 3.2 Another illustration of

power-law transformation (with )

2.2.1 Functions imadjust and stretchlim

13

Suitable results were obtained with gamma val-ues of 3.0 and 4.0, the letter having a slightly more appealing appearance because it has higher contrast

The result obtained with has areas that are too dark, in which some detail is lost

Page 14: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

Example of gamma correction

14

When input into the same monitor, this gamma-corrected input produces an output that is close in appearance to the original image

Page 15: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

a. Original digital mammo-gram

b. Negative image

c. Result of expanding the intensity (range [0.5 0.75])

d. Result of expanding the intensity (gamma = 2)

e. (e) and (f) result of using function strtchlim as an automatic input into func-tion imadjust

15

Page 16: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

16

cf) Low_High : a two-element vector of a lower and upper limit

Figure MATLAB

(b) g = imcomplement(f)

(c) g2 = imadjust(f, [0.5 0.75], [0 1])

(d) g3 = imadjust(f, [ ], [ ], 2)

Low_High = stretchlim(f)

(e) g = imadjust(f, stretchlim(f), [ ])

(f) g = imadjust(f, stretchlim(f), [1 0])

Page 17: Chapter2_Intensity Transformations and Spatial Filtering

2.2.1 Functions imadjust and stretchlim

Power-law transformations have the basic form

where and are positive constants

17

Power-law curves with fractional values of map a narrow range of dark input values in to a wider range of output values, with the opposite being true for higher values of input levels

The Curves generated with values of have ex-actly the opposite effect as those generated with val-ues of

1

1

Page 18: Chapter2_Intensity Transformations and Spatial Filtering

2.2.2 Logarithmic and Contrast-Stretching Transformations

Logarithmic and contrast-stretching transformations are basic tools for dynamic range manipulation

g = c • log(1 + f)

where c is a constant and f is floating point

The shape of this transformation is similar to the gamma curve Note that the shape of gamma curve is variable, whereas the

shape of the log function is fixed

18

Page 19: Chapter2_Intensity Transformations and Spatial Filtering

2.2.2 Logarithmic and Contrast-Stretching Transformations

One of the principal uses of the log transformation is to compress dynamic range

Use MATLAB to do this work for 8 bits

gs = im2uint8(mat2gray(g))

Using mat2gray brings the values to the range [0, 1] Using im2uint8 brings them to the range [0, 255], convert-

ing the image to class uint8

19

Page 20: Chapter2_Intensity Transformations and Spatial Filtering

2.2.2 Logarithmic and Contrast-Stretching Transformations

20

Example of logarithmic transformation Figure 3.5(a) is a Fourier spectrum with values in the range 0 to Figure 3.5(b) shows the result obtained using the commands

Page 21: Chapter2_Intensity Transformations and Spatial Filtering

2.2.2 Logarithmic and Contrast-Stretching Transformations

The function of Fig.3.4(a) is called a contrast-stretching transformation function

It expands a narrow range of input level into a wide range of output level

Fig.3.4(b) is binary image This function is called a thresholding function

21

Page 22: Chapter2_Intensity Transformations and Spatial Filtering

2.2.2 Logarithmic and Contrast-Stretching Transformations

Fig.3.4(a) has the form

where denotes the intensities of the input image, the cor-responding intensity values in the output image, and con-trols the slope of the function

In MATLAB above equation can be represented like

g = 1./(1 + (m./f).^E)

22

Page 23: Chapter2_Intensity Transformations and Spatial Filtering

2.2.3 Specifying Arbitrary Intensity Trans-formations

Suppose that it is necessary to transform the intensities of an image using a specified transformation function

Let T denote a column vector containing the values of the transformation function

For example, in the case of an 8-bit image, assume below mapping T(1) is the value to which intensity 0 is mapped, T(2) is the value to which intensity 1 is mapped, T(256) is the value to which intensity 255 is mapped

23

Page 24: Chapter2_Intensity Transformations and Spatial Filtering

2.2.3 Specifying Arbitrary Intensity Trans-formations

This kind of mapping can be simpley achieved by interp1 function

g = interp1(z, T, f)

where f is the input image, g is the output image, T is the column vector and z is a column vector of the same length as T

24

Page 25: Chapter2_Intensity Transformations and Spatial Filtering

2.3 Histogram Processing Intensity transformation functions based on information

extracted from image intensity histograms play a cen-tral role in image processing

The focus of this section is on obtaining and using his-tograms for image enhancement

25

Page 26: Chapter2_Intensity Transformations and Spatial Filtering

2.3 Histogram Processing

Example of histogram processing in image enhancement

26

Page 27: Chapter2_Intensity Transformations and Spatial Filtering

2.3.1 Generating and Plotting Image His-tograms

The histogram of a digital image with L total possible in-tensity levels in the range is defined as the discrete func-tion

where is the kth intensity level in the interval and is the number of pixels in the image whose intensity level

27

( )k kh r n

Page 28: Chapter2_Intensity Transformations and Spatial Filtering

2.3.1 Generating and Plotting Image His-tograms

Sometimes it is necessary to work with normalized his-tograms, obtained simply by dividing all elements of h() by the total number of pixels in the image, which we de-note by n

where, for integer images, k=0,1,2, …,L-1

28

Page 29: Chapter2_Intensity Transformations and Spatial Filtering

2.3.1 Generating and Plotting Image His-tograms

The core function in the toolbox for dealing with image histograms is imhist, with the basic syntax

h = imhist(f, b)

where f is the input image, h is its histogram, and b is the number of bins used in forming the histogram

We obtain the normalized histogram by using the expres-sion

p = imhist(f, b)/numel(f)

function numel(f) gives the number of elements in array

29

Page 30: Chapter2_Intensity Transformations and Spatial Filtering

2.3.1 Generating and Plotting Image His-tograms

Histograms can be plotted also using bar graphs. For this purpose we can use the function

bar(horz, z, width)

where z is a row vector containing the points to be plot-ted, horz is a vector of the same dimension as z that con-tains the increments of the horizontal scale, and width is a number between 0 and 1

30

Page 31: Chapter2_Intensity Transformations and Spatial Filtering

2.3.1 Generating and Plotting Image His-tograms

Various ways to plot an image histogram

31

Page 32: Chapter2_Intensity Transformations and Spatial Filtering

A concept of histogram equalization The method used to generate a processed image that has a

uniform histogram is called histogram equalization

2.3.2 Histogram Equalization

32

gray level

( )kH r

input

graylevel

( )kH r

output

Page 33: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Suppose that we perform the following transformation on the input lelvels to obtain output (processed) intensity levels, s,

where w is a dummy variable of integration

It can be shown that the probability density function of the output levels is uniform; that is

33

Page 34: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Due to the fact that we are dealing with discrete quantities, histogram of processed image will not be uniform

For discrete quantities we work with summations, and the equalization transformation becomes

for k = 0,1,2,…L-1, where is the intensity value in the output image corresponding to value in the input image

34

Page 35: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Mathematical derivation of histogram equalization Let the continuous variable represent the gray levels of the im-

age If and are known and is single-valued and monotonically in-

creasing, then the probability density function of the trans-formed variable can be obtained using the following equation

where and is the probability density function of random vari-able , , respectively

35

( )s r

drp p r

ds (3.3 3)

Page 36: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Mathematical derivation of histogram equalization For transformation function given by the expression

can be obtained by applying Eq.(3.3-3)

The resulting always is uniform, independent of the form of

36

r

r dwwpLrTs0

)()1()( (3.3 4)

)()1()()1()(

0rpLdwwp

dr

dL

dr

rdT

dr

dsr

r

r

(3.3 5)

10,1

1

)()1(

1)()()(

Ls

LrpLrp

ds

drrpsp

rrrs (3.3 6)

Page 37: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Additional description of histogram equalization For the particular values and related with , The probability of

the event must equal the probability of the event because of the one-to-one correspondence between and

Therefore, PDF of the random variable transformed with

is uniform probability density function

37

r

r dwwpLrTs0

)()1()(

s

( )sp s

0s 1

1

r

( )rp r

0r

Page 38: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization Example of implementation of HE

38

2 2 4 4

2 5 5 4

3 5 3 4

3 3 3 3

1 1 6 6

1 7 7 6

4 7 4 6

4 4 4 4

ks

0/16 0/16 3/16 6/16 4/16 3/16 0/16 0/16

0/16 0/16 3/16 9/16 13/16 16/16 16/16 16/16

0 0 0.18 0.56 0.8 1 1 1

7 0 0 1.3 3.9 5.6 7 7 7

0 0 1 4 6 7 7 7

( )r kp r

0

( )k

r jj

p r

Normalized histogram

CDF

Multiplied by 7

Output gray level

Input image

Output image

Histogram of the input image

Histogram of the output image

10 2 3 4 5 76

3 3

6

4

10 2 3 4 5 76

4

6

3 3

Page 39: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Advantage of histogram equalization Histogram equalization have the tendency of spreading the

histogram of the input image so that the levels of the his-togram-equalized image will span a fuller of the gray scale

Given an image, the process of histogram equalization con-sists simply of implementing Eq.(3.3-8)

which is based on information that can be extracted directly from the given image, without other parameters

39

1,...,2,1,0,)()(0 0

Lkn

nrprTs

k

j

k

j

jjrkk

Page 40: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

The toolbox implements histogram matching using the following syntax in histeq

g = histeq(f, nlev)

where f is the input image, nlev is the number of inten-sity levels specified for the output image

40

Page 41: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

Example of histogram equalization Can you see the difference?

41

Page 42: Chapter2_Intensity Transformations and Spatial Filtering

2.3.2 Histogram Equalization

The transformation function used in histogram equaliza-tion is the cumulative sum of normalized histogram val-ues.

Use function cumsum to obtain the transformation func-tion, as follows

42

Page 43: Chapter2_Intensity Transformations and Spatial Filtering

2.3.3 Histogram Matching(Specification)

It is useful in some applications to be able to specify the shape of the histogram that we wish the processed im-age to have.

The method used to generate an image that has a speci-fied histogram is called histogram matching or his-togram specification

43

graylevel

( )kH z

0z

output

gray level

( )kH r

0r

input

Page 44: Chapter2_Intensity Transformations and Spatial Filtering

2.3.3 Histogram Matching(Specification)

Conceptual diagram of histogram matching

44

0( ) ( )

input

inputoutput T input p w dw ( ) 1outputp output

s

( )sp s

0s 1

1

z

( )zp z

0zone-to-oneone-to-one

r

( )rp r

0r

input

)()]([ 11 sGrTGz

z

z sdttpLzG0

)()1()(dwwpLrTsr

r )()1()(0

Page 45: Chapter2_Intensity Transformations and Spatial Filtering

2.3.3 Histogram Matching(Specification)

In the previous section, the transformation

results in intensity levels, s, with a uniform probability den-sity function

Suppose now that we define a variable z with the property

Keep in mind that we are after an image with intensity levels, z, that have the specified density

From the preceding two equations, it follows that

45

Page 46: Chapter2_Intensity Transformations and Spatial Filtering

2.3.3 Histogram Matching(Specification) Example of implementation of HE

46

(a) Image of the Mars moon Phobos

(b) Histogram equalized image

(c) Result of enhancement by his-

togram matching

Page 47: Chapter2_Intensity Transformations and Spatial Filtering

2.3.4 Function adapthisteq

This toolbox function performs so-called contrast-lim-ited adaptive histogram equalization (CLAHE)

Neighboring tiles are then combined using bilinear inter-polation to eliminate artificially induced boundaries

The contrast can be limited to avoid amplifying noise The syntax for adapthisteq is

47

Page 48: Chapter2_Intensity Transformations and Spatial Filtering

2.3.4 Function adapthisteq

48

Page 49: Chapter2_Intensity Transformations and Spatial Filtering

2.4 Spatial Filtering

What is the mask? Some neighborhood operations work with the values of the im-

age pixels in the neighborhood and the corresponding values of a subimage that has the same dimensions as the neighborhood

The subimage is called a filter, mask, kernel, template, or window

The values in a filter subimage are referred to as coefficients

49

Page 50: Chapter2_Intensity Transformations and Spatial Filtering

A spatial filter is consisted of A neighborhood A predefined operation

Filtering creates a new pixel with coordinates equal to the coordinates of the center of the neighborhood.

If the operation performed on the image pixels is linear, than the filter is called a linear spatial filter

Otherwise, the filter is nonlinear spatial filter

2.4 Spatial Filtering

50

Page 51: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Mechanics of Linear filtering Linear filtering of an image with a

filter mask of size is given by

where and

51

( , ) ( , ) ( , )a b

s a t b

g x y w s t f x s y t

Page 52: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Spatial Correlation and Convolution Correlation is the process of moving a filter mask over the im-

age and computing the sum of product at each location. The correlation of a filter mask , of size with a function , de-

noted by

The mechanics of convolution are the same, except that the fil-ter is first rotated by 180°

The convolution of , and , denoted by

52

1

( , ) ( , ) ( , ) ( , )a b

s t b

w x y f x y w s t f x s y t

1

( , ) ( , ) ( , ) ( , )a b

s t b

w x y f x y w s t f x s y t

Page 53: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

One-dimensional correlation and convolution

53

Page 54: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Two-dimensional correlation and convolution

54

Page 55: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

When interest lies in the characteristic response, , of a mask either of correlations or convolution, it is convenient sometimes to write the sum of products as

where the s are the coefficients of an filter and the s are the corresponding image intensities encompassed by the filter

55

zwzwzwzwzwR Tmn

kkkmnmn

12211 ... (3.4-1)

Page 56: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

The Matlab using function imfilter, which has the follow-ing syntax

g = imfilter(f, w, filtering_mode, boundary_options, size_options)

where,f = input image

w = filter mask

g = filtered result

56

Page 57: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Smoothing filters are used for blurring and for noise re-duction

Blurring is used in preprocessing steps, such as removal of small details from an image prior to (large) object ex-traction, and bridging of small gaps in lines or curves

Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear filtering

57

Page 58: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Averaging filter The idea behind averaging filters is to replacing the value of

every pixel in an image by the average of the gray levels in the neighborhood defined by the filter mask

The most obvious application of averaging filter is noise re-duction

Averaging filters have the undesirable side effect that they blur edges

58

Page 59: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Weighted averaging filter Pixels are multiplied by different coefficients, thus giving more

importance to some pixels at the expense of others The general implementation for filtering an image with a

weighted averaging filter of size is given by the expression

59

( , ) ( , )( , )

( , )

a b

s a t ba b

s a t b

w s t f x s y tg x y

w s t

(3.5 1)

Page 60: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Two 3 3 averaging filter masks

60

Page 61: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

Example 3.13 Image smoothing with masks of various sizes

61

Page 62: Chapter2_Intensity Transformations and Spatial Filtering

2.4.1 Linear Spatial Filtering

The effects of smoothing as a function of filter size The size of the mask establishes the relative size of the objects

that will be blended with the background

62

Fig. 3.34 shows that a number of objects have either blended with the background or their intensity has diminished considerably

Page 63: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

Order-statistic(Nonlinear) filters Order-statistic filters are nonlinear spatial filters whose re-

sponse is based on ordering the pixels contained in the image area encompassed by the filter, and then replacing the value of the center pixel with the value determined by the ranking result

In this section, we are going to focus on median filter which is one of the most popular order-statistic filters

63

Page 64: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

Median filter Median filter replaces the value of a pixel by the median of

the gray levels in the neighborhood of that pixel Median filters are particularly effective in the presence of im-

pulse noise, also called salt-and-pepper noise The principal function of median filters is to force points with

distinct gray levels to be more like their neighbors

64

Page 65: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

Example 3.14 Use of median filtering for noise reduction

65

The image processed with averaging filter has less visible noise, but the price paid is significant blurringIn general, median filtering is much better suited than averaging for the removal of salt-and-pepper noise

Page 66: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

The toolbox provides two functions for performing gen-eral nonlinear filtering : nlfilter and colfilt Although colfilt requires more memory, it generally executes

significantly faster than nlfilter

B = colfilt(A, [m n], block_type, fun)

B processes the image A by rearranging each block of A into a column of a temporary matrix, and then applying the function fun to this matrix. fun must be a function handle. colfilt zero-pads A, if necessary

66

Page 67: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

B = nlfilter(A, [m n], fun)

B = nlfilter(A, [m n], fun) applies the function fun to each sliding block of A. fun is a function that accepts an matrix as input and returns a scalar result.

67

Page 68: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

The input image must be padded explicitly before filter-ing. For this we use function padarray, which, for 2-D functions, has the syntax

fp = padarray(f, [r c], method, direction)

where,

f = input image

fp = padded image

[r c] = gives the number of rows and columns by which to pad f

68

Page 69: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

method and direction are as explained in Table

69

Page 70: Chapter2_Intensity Transformations and Spatial Filtering

2.4.2 Nonlinear Spatial Filtering

70

Method

Direction

Page 71: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

The Matlab supports a number of predefined 2-D linear spatial filters, obtained by using function fspecial

where,

‘type’ specifies the filter type

‘parameters’ specifies the filter

71

f = fspecial(‘type’, parameters)

Page 72: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

The spatial filters that fspecial can generate are summa-rized in Table.

72

Page 73: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Sharpening The principal objective of sharpening is to highlight fine detail

in an image or to enhance detail that has been blurred The sharpening could be accomplished by spatial differentia-

tion The strength of the response of a derivative operator is pro-

portional to the degree of discontinuity of the image at the point which the operator is applied

Image differentiation enhances edges and other discontinu-ities (such as noise) and deemphazises areas with slowly varying gray-level values

73

Page 74: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

A basic definition of the first-order derivative of a one-dimensional function is difference

A second-order derivative is given by

74

( 1) ( )f

f x f xx

2

2( 1) ( 1) 2 ( )

ff x f x f x

x

Page 75: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Comparing the response between first- and second-order derivatives

75

First-order derivatives generally produce thicker edges in an image

Second-order derivatives have a stronger response to fine detail, such as thin lines and isolated points

First-order derivatives generally have a stronger response to a gray-level step

Second-order derivatives produce a double response at step change in gray-level

Second-order derivatives have a stronger response to a line than to a step, and to a point than to a line

Page 76: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

In the most applications, the second derivative is better suited than the first derivative for image enhancement because of the ability of the former to enhance fine detail

Although the principle of use of first derivatives in im-age processing is for edge extraction, they do have im-portant uses in image enhancement

76

Page 77: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Laplacian For a function of two variables, Laplacian is defined as

Laplacian is a linear operator

Digital second derivative Partial second-order derivative in the x-direction

Partial second-order derivative in the y-direction

77

2 22

2 2

f ff

x y

2

2( 1, ) ( 1, ) 2 ( , )

ff x y f x y f x y

x

2

2( , 1) ( , 1) 2 ( , )

ff x y f x y f x y

y

( , )f x y

(3.6-1)

(3.6-2)

(3.6-3)

Page 78: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Digital implementation of the two-dimesional Laplacian in Eq. (3.6-1)

Laplacian mask

Function fspecial(‘laplacian’, ‘alpha’) mask

78

2 [ ( 1, ) ( 1, ) ( , 1) ( , 1)] 4 ( , )f f x y f x y f x y f x y f x y (3.6-4)

0 1 0

1 -4 1

0 1 0

Page 79: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Method for image enhancement using the Laplacian

Imaging sharpening with the Laplacian

79

Fig. 3.38(e) shows the result obtained using Eq. (3.6-5)

The detail in the result image is unmistakably clearer and sharper than in the original image

),(),(),( 2 yxfcyxfyxg (3.6-5)

Page 80: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Unsharp masking and high-boost filtering Unsharp masking

Unsharp masking is to subtracting a blurred version of an image from the image itself

This process is expressed as

where denotes the sharpened image obtained by unsharp masking, and is a blurred version of

80

),(),(),( yxfyxfyxgmask (3.6-6)

Page 81: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

High-boost filtering A slight further generalization of unsharp masking is called high-boost

filtering Since can be obtained using Eq.(3.6-6), Eq.(3.6-7) becomes

81

),(*),(),( yxgkyxfyxg mask(3.6-7)

Page 82: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Example 3.16 Image enhancement with a high-boost filter

82

By varying the boost coefficient k=4.5, it generally is possible to ob-tain an overall increase in average gray level of the image, thus helping to brighten the final result

Page 83: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Gradient The gradient of at coordinates is defined as the two-dimen-

sional column vector

The magnitude of this vector is given by

83

x

y

fG x

fGy

f

2 2 1/ 2 2 2 1/ 2( ) [ ] [( ) ( ) ]x y

f ff mag G G

x y

f

x yf G G

(3.6-10)

(3.6-11)

(3.6-12)

Page 84: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Roberts cross-gradient operator and

D Df

Sobel operator

84

3x3 mask

9 5( )xG z z 8 6( )yG z z 2 2 1/ 2

9 5 8 6[( ) ( ) ]f z z z z

9 5 8 6| | | |f z z z z

7 8 9 1 2 3

3 6 9 1 4 7

| ( 2 ) ( 2 ) |

| ( 2 ) ( 2 ) |

f z z z z z z

z z z z z z

(3.6-13)

(3.6-14)

(3.6-15)

(3.6-16)

Page 85: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Masks of the Robert cross-gradient and Sobel operator

85

Fig. 3.41 (b) and (c) show the masks of Robert cross-gradient operator

Fig. 3.41 (d) and (e) show the masks of sobel operator

The coefficients in all the masks shown in Fig. 3.41 sum to 0

Page 86: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Example 3.17 Use of the gradient for edge enhancement

86

Fig. 3.42 (b) shows the gradient obtained using Eq. (3.6-16) with the two sobel masks in Fig. 3.41(d) and (e)

The edge defects also are quite visible in this image, but with the added advan-tage that constant or slowly varying shades of gray have been eliminated

Page 87: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Complementary enhancement techniques Frequently, a given enhancement task will require application

of several complementary enhancement techniques in order to achieve an acceptable result

Example of combining spatial enhancement methods Objective

Highlighting fine details Enhancing prominent edges Increasing the dynamic range

87

Page 88: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Example of combining spatial enhancement methods(continued)

88

Page 89: Chapter2_Intensity Transformations and Spatial Filtering

2.5 Image Processing Toolbox Standard Spa-tial Filters

Example of combining spatial enhancement methods(continued)

89

(a) Original (b) Laplacian of original(c) Sharpened image obtained by the sum of (a) and (b)

Page 90: Chapter2_Intensity Transformations and Spatial Filtering

Example of combining spatial enhancement methods(continued)

2.5 Image Processing Toolbox Standard Spa-tial Filters

90

(a) Original (d) Sobel of original

(e) Sobel image smoothed with a 5x5 averaging filter

Page 91: Chapter2_Intensity Transformations and Spatial Filtering

Example of combining spatial enhancement methods(continued)

2.5 Image Processing Toolbox Standard Spa-tial Filters

91

(e) Sobel image smoothed with a 5x5 averaging filter

(f) Mask image formed by the product of (c) and (e)

(c) Sharpened image obtained by the sum of (a) and (b)

Page 92: Chapter2_Intensity Transformations and Spatial Filtering

Example of combining spatial enhancement methods(continued)

2.5 Image Processing Toolbox Standard Spa-tial Filters

92

(a)Original(g) Sharpened image obtained by

the sum of (a) and (f)(f) Mask image formed by the

product of (c) and (e)

Page 93: Chapter2_Intensity Transformations and Spatial Filtering

Example of combining spatial enhancement methods(continued)

2.5 Image Processing Toolbox Standard Spa-tial Filters

93

(g) Sharpened image obtained by the sum of (a) and (f)

(h) Final result obtained by applying a power-law transformation to (g) (a)Original

Page 94: Chapter2_Intensity Transformations and Spatial Filtering

2.6 Using Fuzzy Techniques for Intensity Transformations and Spatial Filtering

We conclude this chapter with an introduction to fuzzy sets and their application to intensity transformations and spatial filtering

Fuzzy sets provide a framework for incorporating human knowledge in the solution of problems whose formula-tion is based on imprecise concepts

94

Page 95: Chapter2_Intensity Transformations and Spatial Filtering

2.6.1 Background

A set is a collection of objects and set theory consists of tools that deal with operations on and among sets

Central to set theory is the notion of set membership We are used to dealing with so-called “crisp” sets whose

membership can be only true or false in the traditional sense of bivalued Boolean logic

However, Fuzzy set theory permits the gradual assess-ment of the membership of elements in a set

Fuzzy sets provide a formalism for dealing with impre-cise information

95

Page 96: Chapter2_Intensity Transformations and Spatial Filtering

2.6.2 Introduction to Fuzzy Sets

96

Fig. 3.44 (a) summarizes this concept using an age threshold of 20 years and letting denote the membership function just discussed(This kind of membership function is used in crips sets)

Fig. 3.44 (b) shows one possibility. The key feature of this function is the it is infinite valued, thus allowing a continuous transition between young and not young(This kind of membership function is used in Fuzzy sets)

)(zA

Page 97: Chapter2_Intensity Transformations and Spatial Filtering

2.6.2 Introduction to Fuzzy Sets

Let Z be a set of elements (objects), with a generic element of Z denoted by z; that is, Z ={z}.

A fuzzy set A in Z is characterized by a membership func-tion, ,that associates with each element of Z a real number in the interval [0,1].

A fuzzy set is an ordered pair consisting of values of z and corresponding membership function that assigns a grade of membership to each z. That is,

97

}|)(,{ ZzzzA A (3.8-1)

Page 98: Chapter2_Intensity Transformations and Spatial Filtering

2.6.2 Introduction to Fuzzy Sets

Terminologies and operations of Fuzzy Sets Empty Set A fuzzy set is empty Equality Two fuzzy sets A and B are equal Complement (3.8-2) Subset (3.8-3) Union (3.8-4) Intersection (3.8-5)

98

)(1)( zz AA

)()( zz BA

)](),(max[)( zzz BAU

)](),(min[)( zzz BAI

Page 99: Chapter2_Intensity Transformations and Spatial Filtering

2.6.2 Introduction to Fuzzy Sets

Example of Fuzzy set operations

99

Page 100: Chapter2_Intensity Transformations and Spatial Filtering

2.6.3 Using Fuzzy Sets

Example of using Fuzzy set theory Suppose that we are interested in using color to categorize a given

type of fruit into three groups: verdant, half verdant, and mature. Verdant fruit is green, half-mature fruit is yellow, and mature fruit

is red. The problem-specific knowledge just explained can be formalized

in the form of the following fuzzy IF-THEN rules

R1: IF the color is green, THEN the fruit is verdant

OR

R2: IF the color is yellow, THEN the fruit is half-mature

OR

R3: IF the color is red, THEN the fruit is mature

100

Page 101: Chapter2_Intensity Transformations and Spatial Filtering

2.6.3 Using Fuzzy Sets

101

Page 102: Chapter2_Intensity Transformations and Spatial Filtering

2.6.3 Using Fuzzy Sets

Figures 3.47 and 3.48, together with the rule base, contain all the information required to relate inputs and outputs

(3.8-12)

102

3( , ) min{ ( ), ( )}red matz v z v

Page 103: Chapter2_Intensity Transformations and Spatial Filtering

2.6.3 Using Fuzzy Sets

Let z0 denote a specific value of red, yellow and green. As noted before, the AND operations is implemented using the minimum operation:

Three rules are associated by the OR operation. Thus, the complete fuzzy output is given by

103

)},(),(min{)( 0303 vzzvQ red

)},(),(min{)( 0202 vzzvQ yellow

)},(),(min{)( 0101 vzzvQ green

)}},(),(max{min{)( 00 vzzvQ rs (3.8-17)

Page 104: Chapter2_Intensity Transformations and Spatial Filtering

2.6.3 Using Fuzzy Sets

Q(v) from Eq. (3.8-17) can have K possible values, Q(1), Q(2), Q(3), …, Q(K), its center of grav-ity is given by

104

K

v

K

v

vQ

vvQv

1

10

)(

)(

(3.8-18)

Page 105: Chapter2_Intensity Transformations and Spatial Filtering

2.6.3 Using Fuzzy Sets

Another example of using Fuzzy set theory

105

Page 106: Chapter2_Intensity Transformations and Spatial Filtering

2.6.5 Using Fuzzy Sets for Intensity Trans-formation

Consider the general problem of contrast enhancement The process of enhancing the contrast of a gray-scale image using

the following rules

IF a pixel if dark, THEN make it darker

IF a pixel if gray, THEN make it gray

IF a pixel if bright, THEN make it brighter

Keeping in mind that these are fuzzy terms, we can express the concepts of dark, gray, and bright by the membership functions in Fig.3.53(a)

106

Page 107: Chapter2_Intensity Transformations and Spatial Filtering

2.6.5 Using Fuzzy Sets for Intensity Trans-formation

In terms of the output, we can consider darker as being de-grees of a dark intensity value, brighter, as being degrees of a bright shade, and gray as being degrees of an intensity in the middle of the gray scale

When interpreted as constant intensities whose strength is modified, the output membership functions are singletons, as Fig.3.53(b)

107

Page 108: Chapter2_Intensity Transformations and Spatial Filtering

2.6.5 Using Fuzzy Sets for Intensity Trans-formation

The various degree of an intensity in the range [0, 1] occur when the singletons are clipped by the strength of the re-sponse from their corresponding rules

We are dealing with constants in the output membership functions, it follows from Eq. (3.8-18) that the output, v0, to any input, z0, is given by

108

)()()(

*)(*)(*)(

000

0000 zzz

vzvzvzv

brightgraydark

bbrightggrayddark

(3.8-22)

Page 109: Chapter2_Intensity Transformations and Spatial Filtering

2.6.5 Using Fuzzy Sets for Intensity Trans-formation

Result of a contrast enhancement by using Fuzzy set theory

109

Page 110: Chapter2_Intensity Transformations and Spatial Filtering

2.6.6 Using Fuzzy Sets for Spatial Filtering

IF - THEN – ELSE rulesIF() AND () AND ... AND () THEN ()

IF() AND () AND ... AND () THEN ()

...

IF() AND () AND ... AND () THEN ()

ELSE ()

Evaluating the antecedents of the th rule in Eq.(3.8-19) produces a scalar output, , given by

ELSE rule is executed when none of the preceding rules is com-pletely satisfied.

110

(3.8-19)

Page 111: Chapter2_Intensity Transformations and Spatial Filtering

2.6.6 Using Fuzzy Sets for Spatial Filtering

in the previous slide is called strength level which indi-cates the degree of dominance

If is larger than max(), we follow the ELSE rule Otherwise, we follow IF rule

111

Page 112: Chapter2_Intensity Transformations and Spatial Filtering

2.6.6 Using Fuzzy Sets for Spatial Filtering

We can develop a boundary extraction algorithm based on a simple fuzzy concept : If a pixel belongs to a uni-form region, then make it white; else make it black, where, black and white are fuzzy sets

112

Page 113: Chapter2_Intensity Transformations and Spatial Filtering

2.6.6 Using Fuzzy Sets for Spatial Filtering

In order to do this, a simple set of four IF-THEN rules and one ELSE rule is useddi = zi – z5, where the zs are intensity valuesIF is zero AND is zero THEN is white

IF is zero AND is zero THEN is white

IF is zero AND is zero THEN is white

IF is zero AND is zero THEN is white

ELSE is black

113

Page 114: Chapter2_Intensity Transformations and Spatial Filtering

2.6.6 Using Fuzzy Sets for Spatial Filtering

Membership function of the Fuzzy set and Fuzzy rules

114

Page 115: Chapter2_Intensity Transformations and Spatial Filtering

2.6.6 Using Fuzzy Sets for Spatial Filtering

Example 3.20

115

The contrast of this image can be improved significantly by expanding the gray scale.Fig.3.59(c) was obtained by performing the intensity scaling defined in Eqs. (2.6-10) and (2.6-11), with k = L – 1. the net result is the intensity values in Fig.3.59(c) span the full gray scale from 0 to (L -1)