lecture 6 image enhancement in spatial domain › cms › aut2010 › cpdipbs › ... · lecture 6...

35
Digital Image Processing Digital Image Processing Lecture 6 Lecture 6 Image Enhancement in Spatial Image Enhancement in Spatial Domain Domain Fall 2010 Fall 2010

Upload: others

Post on 31-May-2020

26 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Digital Image ProcessingDigital Image Processing

Lecture 6 Lecture 6

Image Enhancement in Spatial Image Enhancement in Spatial

DomainDomain

Fall 2010Fall 2010

Page 2: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 2

Spatial FilteringSpatial Filtering

A spatial filter consists of (a) a neighborhood, and (b) apredefined operation

Linear spatial filtering of an image of size MxN with a filter of size mxn is given by the expression

( , ) ( , ) ( , )a b

s a t b

g x y w s t f x s y t=− =−

= + +∑ ∑

Page 3: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 3

Spatial FilteringSpatial Filtering

Page 4: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 4

Spatial CorrelationSpatial Correlation

The correlation of a filter ( , ) of size

with an image ( , ), denoted as ( , ) ( , )

w x y m n

f x y w x y f x y

×

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

s a t b

w x y f x y w s t f x s y t=− =−

= + +∑ ∑

Page 5: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 5

Spatial ConvolutionSpatial Convolution

The convolution of a filter ( , ) of size

with an image ( , ), denoted as ( , ) ( , )

w x y m n

f x y w x y f x y

×

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

s a t b

w x y f x y w s t f x s y t=− =−

= − −∑ ∑

Page 6: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 6

Page 7: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 7

Smoothing Spatial FiltersSmoothing Spatial Filters

Smoothing filters are used for blurring and for noise reduction

Blurring is used in removal of small details and bridging ofsmall gaps in lines or curves

Smoothing spatial filters include linear filters and nonlinear filters.

Page 8: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 8

Spatial Smoothing Linear FiltersSpatial Smoothing Linear Filters

The general implementation for filtering an M N image

with a weighted averaging filter of size m n is given

( , ) ( , )

( , )

( , )

where 2 1

a b

s a t b

a b

s a t b

w s t f x s y t

g x y

w s t

m a

=− =−

=− =−

×

×

+ +

=

= +

∑ ∑

∑ ∑

, 2 1.n b= +

Page 9: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 9

Smoothing Spatial FiltersSmoothing Spatial Filters

► used for blurring and for noise reduction

► blurring is used in preprocessing steps, such as

� removal of small details from an image prior to object extraction

� bridging of small gaps in lines or curves

► noise reduction can be accomplished by blurring with a linear filter and also by a nonlinear filter

► replacing the value of every pixel in an image by the average of the gray levels in the neighborhood will reduce the “sharp” transitions in gray levels.

► sharp transitions

� random noise in the image

� edges of objects in the image

► thus, smoothing can reduce noises (desirable) and blur edges (undesirable)

Page 10: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 10

Two Smoothing Averaging Filter MasksTwo Smoothing Averaging Filter Masks

Page 11: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 11

Page 12: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 12

Example: Gross Representation of ObjectsExample: Gross Representation of Objects

Page 13: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 13

OrderOrder--statistic (Nonlinear) Filtersstatistic (Nonlinear) Filters

— Nonlinear

— Based on ordering (ranking) the pixels contained in the filter mask

— Replacing the value of the center pixel with the value determined by the ranking result

E.g., median filter, max filter, min filter

Page 14: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 14

Median FiltersMedian Filters

► replaces 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 noise � salt and pepper noise) , they provide excellent noise-reduction capabilities, with considering less blurring than linear smoothing filters of similar size.

Page 15: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 15

Example: Use of Median Filtering for Noise ReductionExample: Use of Median Filtering for Noise Reduction

Page 16: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 16

Sharpening Spatial FiltersSharpening Spatial Filters

► Foundation

► Laplacian Operator

► Unsharp Masking and Highboost Filtering

► Using First-Order Derivatives for Nonlinear Image Sharpening — The Gradient

Page 17: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 17

Sharpening Spatial FiltersSharpening Spatial Filters

► to highlight fine detail in an image

► or to enhance detail that has been blurred, either in error or as a natural effect of a particular method of image acquisition.

► Blurring Vs. Sharpening

� as we know that blurring can be done in spatial domain by pixel averaging in a neighbors

� since averaging is analogous to integration

� thus, we can guess that the sharpening must be accomplished by spatial differentiation.

Page 18: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 18

Derivative operatorDerivative operator

► the strength of the response of a derivative operator is proportional to the degree of discontinuity of the image at the point at which the operator is applied.

► thus, image differentiation

� enhances edges and other discontinuities (noise)

� deemphasizes area with slowly varying gray-level values.

Page 19: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 19

Sharpening Spatial Filters: FoundationSharpening Spatial Filters: Foundation

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

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

( 1) ( )f

f x f xx

∂= + −

2

2( 1) ( 1) 2 ( )

ff x f x f x

x

∂= + + − −

Page 20: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 20

Page 21: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 21

Sharpening Spatial Filters: Laplace OperatorSharpening Spatial Filters: Laplace Operator

The second-order isotropic derivative operator is the Laplacian for a function (image) f(x,y)

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

∂= + + − −

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

- 4 ( , )

f f x y f x y f x y f x y

f x y

∇ = + + − + + + −

Page 22: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 22

Sharpening Spatial Filters: Laplace OperatorSharpening Spatial Filters: Laplace Operator

Page 23: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 23

Sharpening Spatial Filters: Laplace OperatorSharpening Spatial Filters: Laplace Operator

Image sharpening in the way of using the Laplacian:

2

2

( , ) ( , ) ( , )

where,

( , ) is input image,

( , ) is sharpenend images,

-1 if ( , ) corresponding to Fig. 3.37(a) or (b)

and 1 if either of the other two filters is us

g x y f x y c f x y

f x y

g x y

c f x y

c

= + ∇

= ∇

= ed.

Page 24: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 24

Page 25: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 25

UnsharpUnsharp Masking and Masking and HighboostHighboost FilteringFiltering

► Unsharp masking

Sharpen images consists of subtracting an unsharp (smoothed) version of an image from the original image

e.g., printing and publishing industry

► Steps

1. Blur the original image

2. Subtract the blurred image from the original

3. Add the mask to the original

Page 26: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 26

UnsharpUnsharp Masking and Masking and HighboostHighboost FilteringFiltering

Let ( , ) denote the blurred image, unsharp masking is

( , ) ( , ) ( , )

Then add a weighted portion of the mask back to the original

( , ) ( , ) * ( , )

mask

mask

f x y

g x y f x y f x y

g x y f x y k g x y

= −

= + 0k ≥

when 1, the process is referred to as highboost filtering.k >

Page 27: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 27

UnsharpUnsharp Masking: DemoMasking: Demo

Page 28: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 28

UnsharpUnsharp Masking and Masking and HighboostHighboost Filtering: ExampleFiltering: Example

Page 29: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 29

Image Sharpening based on FirstImage Sharpening based on First--Order DerivativesOrder Derivatives

For function ( , ), the gradient of at coordinates ( , )

is defined as

grad( )x

y

f x y f x y

f

g xf f

fg

y

∂ ∂ ∇ ≡ ≡ = ∂ ∂

2 2

The of vector , denoted as ( , )

( , ) mag( )x y

magnitude f M x y

M x y f g g

= ∇ = +Gradient Image

Page 30: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 30

Image Sharpening based on FirstImage Sharpening based on First--Order DerivativesOrder Derivatives

2 2

The of vector , denoted as ( , )

( , ) mag( )x y

magnitude f M x y

M x y f g g

= ∇ = +

( , ) | | | |x y

M x y g g≈ +

zz99zz88zz77

zz66zz55zz44

zz33zz22zz11

8 5 6 5( , ) | | | |M x y z z z z= − + −

Page 31: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 31

Image Sharpening based on FirstImage Sharpening based on First--Order DerivativesOrder Derivatives

zz99zz88zz77

zz66zz55zz44

zz33zz22zz11

9 5 8 6

Roberts Cross-gradient Operators

( , ) | | | |M x y z z z z≈ − + −

7 8 9 1 2 3

3 6 9 1 4 7

Sobel Operators

( , ) | ( 2 ) ( 2 ) |

| ( 2 ) ( 2 ) |

M x y z z z z z z

z z z z z z

≈ + + − + +

+ + + − + +

Page 32: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 32

Image Sharpening based on FirstImage Sharpening based on First--Order DerivativesOrder Derivatives

Page 33: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 33

ExampleExample

Page 34: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 34

Example:

Combining Spatial Enhancement Methods

Goal:

Enhance the image by sharpening it and by bringing out more of the skeletal detail

Page 35: Lecture 6 Image Enhancement in Spatial Domain › CMS › AUT2010 › cpDIPbs › ... · Lecture 6 Image Enhancement in Spatial Domain Fall 2010. Lecture # 6 2 Spatial Filtering

Lecture # 6 35

Example:

Combining Spatial Enhancement Methods

Goal:

Enhance the image by sharpening it and by bringing out more of the skeletal detail