digital image processing, 2nd ed. © 2002 r. c. gonzalez & r. e. woods chapter 3 image...

61
Digital Image Processing, 2nd ed. www.imageprocessingbook.com 002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain

Upload: naomi-rundle

Post on 14-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Chapter 3Image Enhancementin the Spatial Domain

Chapter 3Image Enhancementin the Spatial Domain

Page 2: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Image Enhancement in theSpatial Domain

Image Enhancement in theSpatial Domain

• The spatial domain: – The image plane– For a digital image is a Cartesian coordinate system of discrete rows

and columns. At the intersection of each row and column is a pixel. Each pixel has a value, which we will call intensity.

• The frequency domain :– A (2-dimensional) discrete Fourier transform of the spatial domain– We will discuss it in chapter 4.

• Enhancement :– To “improve” the usefulness of an image by using some transformation

on the image. – Often the improvement is to help make the image “better” looking,

such as increasing the intensity or contrast.

Page 3: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

BackgroundBackground

• A mathematical representation of spatial domain enhancement:

where f(x, y): the input image

g(x, y): the processed image

T: an operator on f, defined over some neighborhood of (x, y)

)],([),( yxfTyxg

Page 4: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Gray-level TransformationGray-level Transformation

Page 5: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Some Basic Gray Level TransformationsSome Basic Gray Level Transformations

Page 6: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Image NegativesImage Negatives

rLs 1

• Let the range of gray level be [0, L-1], then

Page 7: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Log TransformationsLog Transformations

)1log( rcs where c : constant

0r

Page 8: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Power-Law TransformationPower-Law Transformation

crs

where c, : positive constants

Page 9: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Power-Law TransformationExample 1: Gamma Correction

Power-Law TransformationExample 1: Gamma Correction

4.0

Page 10: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Power-Law TransformationExample 2: Gamma CorrectionPower-Law TransformationExample 2: Gamma Correction

4.0 3.0

6.01

Page 11: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Power-Law TransformationExample 3: Gamma CorrectionPower-Law TransformationExample 3: Gamma Correction

0.3

0.50.4

1

Page 12: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Piecewise-Linear Transformation FunctionsCase 1: Contrast Stretching

Piecewise-Linear Transformation FunctionsCase 1: Contrast Stretching

Page 13: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Piecewise-Linear Transformation FunctionsCase 2:Gray-level Slicing

Piecewise-Linear Transformation FunctionsCase 2:Gray-level Slicing

An image Result of using the transformation in (a)

Page 14: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Piecewise-Linear Transformation FunctionsCase 3:Bit-plane Slicing

Piecewise-Linear Transformation FunctionsCase 3:Bit-plane Slicing

• Bit-plane slicing: – It can highlight the contribution made to total image appearance by

specific bits.

– Each pixel in an image represented by 8 bits.

– Image is composed of eight 1-bit planes, ranging from bit-plane 0 for the least significant bit to bit plane 7 for the most significant bit.

Page 15: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Piecewise-Linear Transformation FunctionsBit-plane Slicing: A Fractal Image

Piecewise-Linear Transformation FunctionsBit-plane Slicing: A Fractal Image

Page 16: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Piecewise-Linear Transformation FunctionsBit-plane Slicing: A Fractal Image

Piecewise-Linear Transformation FunctionsBit-plane Slicing: A Fractal Image

2

7 6

45 3

1 0

Page 17: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram ProcessingHistogram Processing

Page 18: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram ProcessingHistogram Processing

Page 19: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

• Histogram equalization:– To improve the contrast of an image

– To transform an image in such a way that the transformed image has a nearly uniform distribution of pixel values

• Transformation:– Assume r has been normalized to the interval [0,1], with r = 0

representing black and r = 1 representing white

– The transformation function satisfies the following conditions:• T(r) is single-valued and monotonically increasing in the interval

10 r

10for 1)(0 rrT

10 )( rrTs

Page 20: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

• For example:

Page 21: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

• Histogram equalization is based on a transformation of the probability density function of a random variable.

• Let pr(r) and ps(s) denote the probability density function of random variable r and s, respectively.

• If pr(r) and T(r) are known, then the probability density function ps(s) of the transformed variable s can be obtained

• Define a transformation function where w is a dummy variable of integration and the right side of this equation is the cumulative distribution

function of random variable r.

r

r dwwprTs0

)()(ds

drrpsp rs )()(

Page 22: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

• Given transformation function T(r),

ps(s) now is a uniform probability density function.

• T(r) depends on pr(r), but the resulting ps(s) always is uniform.

10 1)(

1)()()( s

rprp

ds

drrpsp

rrrs

)()()(

0rpdwwp

dr

d

dr

rdT

ds

drr

r

r

r

r dwwprT0

)()(

Page 23: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

• In discrete version:– The probability of occurrence of gray level rk in an image is

n : the total number of pixels in the image

nk : the number of pixels that have gray level rk

L : the total number of possible gray levels in the image– The transformation function is

– Thus, an output image is obtained by mapping each pixel with level rk in the input image into a corresponding pixel with level sk.

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

Lkn

nrprTs

k

j

k

j

jjrkk

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

nrp k

r

Page 24: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

Page 25: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

Page 26: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram EqualizationHistogram Equalization

• Transformation functions (1) through (4) were obtained form the histograms of the images in Fig 3.17(1), using Eq. (3.3-8).

Page 27: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Histogram MatchingHistogram Matching

• Histogram matching is similar to histogram equalization, except that instead of trying to make the output image have a flat histogram, we would like it to have a histogram of a specified shape, say pz(z).

• We skip the details of implementation.

Page 28: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Local EnhancementLocal Enhancement

• The histogram processing methods discussed above are global, in the sense that pixels are modified by a transformation function based on the gray-level content of an entire image.

• However, there are cases in which it is necessary to enhance details over small areas in an image.

original global local

Page 29: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Histogram Statistics for Image EnhancementUse of Histogram Statistics for Image Enhancement

• Moments can be determined directly from a histogram much faster than they can from the pixels directly.

• Let r denote a discrete random variable representing discrete gray-levels in the range [0,L-1], and p(ri) denote the normalized histogram component corresponding to the ith value of r, then the nth moment of r about its mean is defined as

where m is the mean value of r

• For example, the second moment (also the variance of r) is

1

0

)(L

iii rprm

1

0

22 )()()(

L

iii rpmrr

1

0

)()()(L

ii

nin rpmrr

Page 30: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Histogram Statistics for Image EnhancementUse of Histogram Statistics for Image Enhancement

• Two uses of the mean and variance for enhancement purposes:– The global mean and variance (global means for the entire

image) are useful for adjusting overall contrast and intensity.

– The mean and standard deviation for a local region are useful for correcting for large-scale changes in intensity and contrast. ( See equations 3.3-21 and 3.3-22.)

Page 31: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Histogram Statistics for Image EnhancementExample: Enhancement based on local statistics

Use of Histogram Statistics for Image EnhancementExample: Enhancement based on local statistics

Page 32: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Histogram Statistics for Image EnhancementExample: Enhancement based on local statistics

Use of Histogram Statistics for Image EnhancementExample: Enhancement based on local statistics

Page 33: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Histogram Statistics for Image EnhancementExample: Enhancement based on local statistics

Use of Histogram Statistics for Image EnhancementExample: Enhancement based on local statistics

Page 34: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Enhancement Using Arithmetic/Logic OperationsEnhancement Using Arithmetic/Logic Operations

• Two images of the same size can be combined using operations of addition, subtraction, multiplication, division, logical AND, OR, XOR and NOT. Such operations are done on pairs of their corresponding pixels.

• Often only one of the images is a real picture while the other is a machine generated mask. The mask often is a binary image

consisting only of pixel values 0 and 1. • Example: Figure 3.27

Page 35: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Enhancement Using Arithmetic/Logic OperationsEnhancement Using Arithmetic/Logic Operations

AND

OR

Page 36: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Image SubtractionExample 1

Image SubtractionExample 1

Page 37: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Image SubtractionExample 2

Image SubtractionExample 2

• When subtracting two images, negative pixel values can result. So, if you want to display the result it may be necessary to readjust the dynamic range by scaling.

Page 38: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Image AveragingImage Averaging

• When taking pictures in reduced lighting (i.e., low illumination), image noise becomes apparent.

• A noisy image g(x,y) can be defined by

where f (x, y): an original image : the addition of noise• One simple way to reduce this granular noise is to take

several identical pictures and average them, thus smoothing out the randomness.

),(),(),( yxyxfyxg

),( yx

Page 39: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Noise Reduction by Image AveragingExample: Adding Gaussian Noise

Noise Reduction by Image AveragingExample: Adding Gaussian Noise

• Figure 3.30 (a): An image of Galaxy Pair NGC3314.

• Figure 3.30 (b): Image corrupted by additive Gaussian noise with zero mean and a standard deviation of 64 gray levels.

• Figure 3.30 (c)-(f): Results of averaging K=8,16,64, and 128 noisy images.

Page 40: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Noise Reduction by Image AveragingExample: Adding Gaussian NoiseNoise Reduction by Image AveragingExample: Adding Gaussian Noise

• Figure 3.31 (a):

From top to bottom: Difference images between Fig. 3.30 (a) and the four images in Figs. 3.30 (c) through (f), respectively.

• Figure 3.31 (b): Corresponding histogram.

Page 41: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Basics of Spatial FilteringBasics of Spatial Filtering

• In spatial filtering (vs. frequency domain filtering), the output image is computed directly by simple calculations on the pixels of the input image.

• Spatial filtering can be either linear or non-linear.

• For each output pixel, some neighborhood of input pixels is used in the computation.

• In general, linear filtering of an image f of size MXN with a filter mask of size mxn is given by

where a=(m-1)/2 and b=(n-1)/2

• This concept called convolution. Filter masks are sometimes called convolution masks or convolution kernels.

a

as

b

bt

tysxftswyxg ),(),(),(

Page 42: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Basics of Spatial FilteringBasics of Spatial Filtering

Page 43: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

• Nonlinear spatial filtering usually uses a neighborhood too, but some other mathematical operations are use. These can include conditional operations (if …, then…), statistical (sorting pixel values in the neighborhood), etc.

• Because the neighborhood includes pixels on all sides of the center pixel, some special procedure must be used along the top, bottom, left and right sides of the image so that the processing does not try to use pixels that do not exist.

Basics of Spatial FilteringBasics of Spatial Filtering

Page 44: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Smoothing Spatial FiltersSmoothing Spatial Filters

• Smoothing linear filters– Averaging filters (Lowpass filters in Chapter 4))

• Box filter

• Weighted average filter

Box filter Weighted average

Page 45: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Smoothing Spatial FiltersSmoothing Spatial Filters

• The general implementation for filtering an MXN image with a weighted averaging filter of size mxn is given by

where a=(m-1)/2 and b=(n-1)/2

a

as

b

bt

a

as

b

bt

tsw

tysxftswyxg

),(

),(),(),(

Page 46: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Smoothing Spatial FiltersImage smoothing with masks of various sizes

Smoothing Spatial FiltersImage smoothing with masks of various sizes

Page 47: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Smoothing Spatial FiltersAnother Example

Smoothing Spatial FiltersAnother Example

Page 48: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Order-Statistic FiltersOrder-Statistic Filters

• Order-statistic filters– Median filter: to reduce impulse noise (salt-and-

pepper noise)

Page 49: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Sharpening Spatial FiltersSharpening Spatial Filters

• Sharpening filters are based on computing spatial derivatives of an image.

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

• The second-order derivative of a one-dimensional function f(x) is

)()1( xfxfx

f

)(2)1()1(2

2

xfxfxfx

f

Page 50: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Sharpening Spatial FiltersAn Example

Sharpening Spatial FiltersAn Example

Page 51: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Second Derivatives for EnhancementThe Laplacian

Use of Second Derivatives for EnhancementThe Laplacian

• Development of the Laplacian method– The two dimensional Laplacian operator for continuous

functions:

– The Laplacian is a linear operator.

2

2

2

22

y

f

x

ff

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

2

yxfyxfyxfx

f

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

2

yxfyxfyxfy

f

)(4)]1,()1,(),1(),1([2 xfyxfyxfyxfyxff

Page 52: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Second Derivatives for EnhancementThe Laplacian

Use of Second Derivatives for EnhancementThe Laplacian

Page 53: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Second Derivatives for EnhancementThe Laplacian

Use of Second Derivatives for EnhancementThe Laplacian

• To sharpen an image, the Laplacian of the image is subtracted from the original image.

• Example: Figure 3.40

positive. ismask Laplacian theoft coefficiencenter theif ),(

negative. ismask Laplacian theoft coefficiencenter theif ),(),(

2

2

fyxf

fyxfyxg

Page 54: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Page 55: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of Second Derivatives for EnhancementThe Laplacian: Simplifications

Use of Second Derivatives for EnhancementThe Laplacian: Simplifications

The g(x,y) maskNot only f2

Page 56: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of First Derivatives for EnhancementThe Gradient

Use of First Derivatives for EnhancementThe Gradient

• Development of the Gradient method– The gradient of function f at coordinates (x,y) is defined as

the two-dimensional column vector:

– The magnitude of this vector is given by

y

fx

f

G

G

y

xf

2

122

2

122)(mag

y

f

x

fGGf yxf

yx GGf

Page 57: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of First Derivatives for EnhancementThe Gradient

Use of First Derivatives for EnhancementThe Gradient

Roberts cross-gradientoperators

Sobeloperators

Page 58: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Use of First Derivatives for EnhancementThe Gradient: Using Sobel Operators

Use of First Derivatives for EnhancementThe Gradient: Using Sobel Operators

Page 59: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Combining Spatial Enhancement Methods

Combining Spatial Enhancement Methods

Page 60: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods

Combining Spatial Enhancement Methods

Combining Spatial Enhancement Methods

Page 61: Digital Image Processing, 2nd ed.  © 2002 R. C. Gonzalez & R. E. Woods Chapter 3 Image Enhancement in the Spatial Domain Chapter

Digital Image Processing, 2nd ed.Digital Image Processing, 2nd ed.www.imageprocessingbook.com

© 2002 R. C. Gonzalez & R. E. Woods