Top Banner
Image Enhancement (Spatial Filtering 2) Dr Samir H Abdul Dr Samir H Abdul-Jauwad Jauwad Dr. Samir H. Abdul Dr. Samir H. Abdul Jauwad Jauwad Electrical Engineering Department Electrical Engineering Department College of Engineering Sciences College of Engineering Sciences King Fahd University of Petroleum & Minerals King Fahd University of Petroleum & Minerals Dhahran Dhahran – Saudi Arabia Saudi Arabia [email protected] [email protected]
33

Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Aug 07, 2018

Download

Documents

trandang
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Image Enhancement (Spatial Filtering 2)

Dr Samir H AbdulDr Samir H Abdul--JauwadJauwadDr. Samir H. AbdulDr. Samir H. Abdul JauwadJauwadElectrical Engineering DepartmentElectrical Engineering DepartmentCollege of Engineering SciencesCollege of Engineering Sciences

King Fahd University of Petroleum & MineralsKing Fahd University of Petroleum & Mineralsg yg yDhahran Dhahran –– Saudi ArabiaSaudi [email protected]@kfupm.edu.sa

Page 2: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

ContentsContents

In this lecture we will look at more spatial filtering In this lecture we will look at more spatial filtering techniques

– Spatial filtering refresherSpatial filtering refresher– Sharpening filters

• 1st derivative filters1 derivative filters• 2nd derivative filters

– Combining filtering techniquesCombining filtering techniques

Page 3: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Spatial Filtering RefresherSpatial Filtering Refresherr s t

Origin xa b c

u v w

x y z

d e f

g h i*

*

FilterSimple 3*3

Neighbourhood e 3*3 FilterOriginal Image

Pixels

eprocessed = v*e + r*a + s*b + t*c +

u*d + w*f +y Image f (x, y)

u d w f x*g + y*h + z*i

Th b i t d f i l i thThe above is repeated for every pixel in the original image to generate the smoothed image

Page 4: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Sharpening Spatial FiltersSharpening Spatial Filters

Previously we have looked at smoothing filters which Previously we have looked at smoothing filters which remove fine detailSharpening spatial filters seek to highlight fine detailSharpening spatial filters seek to highlight fine detail

– Remove blurring from imagesHi hli ht d– Highlight edges

Sharpening filters are based on spatial differentiation

Page 5: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Spatial DifferentiationSpatial DifferentiationDifferentiation measures the rate of change of a functionLet’s consider a simple 1 dimensional example

Page 6: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Spatial DifferentiationSpatial Differentiation

A B

Page 7: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

11stst DerivativeDerivative

The formula for the 1st derivative of a function is as The formula for the 1 derivative of a function is as follows:

)()1( xfxff

)()1( xfxfxf

It’s just the difference between subsequent values and measures the rate of change of the function

Page 8: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

11stst Derivative (cont…)Derivative (cont…)

7

8

2

3

4

5

6

0

1

2

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7

6

8

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7

0 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0

-2

0

2

4

6

-8

-6

-4

2

Page 9: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

22ndnd DerivativeDerivative

The formula for the 2nd derivative of a function is as The formula for the 2 derivative of a function is as follows:

)(2)1()1(2

xfxfxff

)(2)1()1(2 xfxfxfx

Simply takes into account the values both before and after the current value

Page 10: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

22ndnd Derivative (cont…)Derivative (cont…)

7

8

2

3

4

5

6

0

1

2

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7

10

-1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0

-5

0

5

-15

-10

Page 11: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Using Second Derivatives For Image Using Second Derivatives For Image EnhancementEnhancementEnhancementEnhancement

The 2nd derivative is more useful for image genhancement than the 1st derivative

– Stronger response to fine detailg p– Simpler implementation– We will come back to the 1st order derivative later on

The first sharpening filter we will look at is the Laplacian– Isotropic– One of the simplest sharpening filters– We will look at a digital implementation

Page 12: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

The LaplacianThe LaplacianThe Laplacian is defined as follows:

yf

xff 2

2

2

22

where the partial 1st order derivative in the x direction is defined as follows:

yx

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

2

yxfyxfyxff

and in the y direction as follows:2x

2 f ),(2)1,()1,(2 yxfyxfyxfyf

Page 13: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

The Laplacian (cont…)The Laplacian (cont…)So, the Laplacian can be given as follows:

),1(),1([2 yxfyxff )]1()1( yxfyxf )]1,()1,( yxfyxf

),(4 yxfWe can easily build a filter based on this

0 1 00 1 0

1 -4 1

0 1 0

Page 14: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

The Laplacian (cont…)The Laplacian (cont…)

Applying the Laplacian to an image we get a new image Applying the Laplacian to an image we get a new image that highlights edges and other discontinuities

OriginalImage

LaplacianFiltered Image

LaplacianFiltered ImageImage Filtered Image Filtered Image

Scaled for Display

Page 15: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

But That Is Not Very Enhanced!But That Is Not Very Enhanced!The result of a Laplacian filtering is not an enhanced imageWe have to do more work in order to get our final imageSubtract the Laplacian result from the Subtract the Laplacian result from the original image to generate our final sharpened enhanced image

LaplacianFiltered Image

Scaled for Displaysharpened enhanced image

fyxfyxg 2)()( fyxfyxg ),(),(

Page 16: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Laplacian Image EnhancementLaplacian Image Enhancement

- =

In the final sharpened image edges and fine detail are

OriginalImage

LaplacianFiltered Image

SharpenedImage

In the final sharpened image edges and fine detail are much more obvious

Page 17: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Laplacian Image EnhancementLaplacian Image Enhancement

Page 18: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Simplified Image EnhancementSimplified Image Enhancement

The entire enhancement can be combined into a single The entire enhancement can be combined into a single filtering operation

fyxfyxg 2),(),( ),1(),1([),( yxfyxfyxf )1()1( ff

fyfyg ),(),(

)1,()1,( yxfyxf)],(4 yxf )],( yf

),1(),1(),(5 yxfyxfyxf )1,()1,( yxfyxf

Page 19: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Simplified Image Enhancement (cont…)Simplified Image Enhancement (cont…)

This gives us a new filter which does the whole job for This gives us a new filter which does the whole job for us in one step

0 1 00 -1 0

-1 5 -1

0 -1 0

Page 20: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Simplified Image Enhancement (cont…)Simplified Image Enhancement (cont…)

Page 21: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Variants On The Simple LaplacianVariants On The Simple Laplacian

There are lots of slightly different versions of the There are lots of slightly different versions of the Laplacian that can be used:

0 1 0 1 1 1

1 -4 1

0 1 0

1 -8 1

1 1 1

SimpleLaplacian

Variant ofLaplacian

0 1 0 1 1 1

-1 -1 -1

-1 9 -1

-1 -1 -1

Page 22: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Simple Convolution Tool In JavaSimple Convolution Tool In Java

A great tool for testing out different filtersA great tool for testing out different filters– From the book “Image Processing tools in Java”– Available from webCT later on today– Available from webCT later on today– To launch: java ConvolutionTool Moon.jpg

Page 23: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

11stst Derivative FilteringDerivative FilteringImplementing 1st derivative filters is difficult in practiceFor a function f(x, y) the gradient of f at coordinates (x, y) is given as the column vector:

xf

Gxf

yfx

Gyf

Page 24: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

11stst Derivative Filtering (cont…)Derivative Filtering (cont…)The magnitude of this vector is given by:

)f( magf

2122 GG yx GG

21

22

ff

yf

xf

For practical reasons this can be simplified as:GGf yx GGf

Page 25: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

11stst Derivative Filtering (cont…)Derivative Filtering (cont…)There is some debate as to how best to calculate these gradients but we will use:

321987 22 zzzzzzf

which is based on these coordinates 741963 22 zzzzzz

which is based on these coordinates

z1 z2 z31 2 3

z4 z5 z6

z7 z8 z9

Page 26: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Sobel OperatorsSobel OperatorsBased on the previous equations we can derive the Sobel Operators

1 2 1 1 0 1-1 -2 -1

0 0 0

-1 0 1

-2 0 2

f f

1 2 1 -1 0 1

To filter an image it is filtered using both operators the results of which are added together

Page 27: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Sobel ExampleSobel Example

An image of a gcontact lens which

is enhanced in order to make

defects (at fourdefects (at four and five o’clock in the image) more

obvious

Sobel filters are typically used for edge detection

Page 28: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

11stst & 2& 2ndnd DerivativesDerivatives

Comparing the 1st and 2nd derivatives we can conclude Comparing the 1 and 2 derivatives we can conclude the following:

– 1st order derivatives generally produce thicker edges1 order derivatives generally produce thicker edges– 2nd order derivatives have a stronger response to fine

detail e.g. thin linesdetail e.g. thin lines– 1st order derivatives have stronger response to grey level

stepp– 2nd order derivatives produce a double response at step

changes in grey levelg g y

Page 29: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

SummarySummary

In this lecture we looked at:In this lecture we looked at:– Sharpening filters

• 1st derivative filters1 derivative filters• 2nd derivative filters

– Combining filtering techniquesCo b g e g ec ques

Page 30: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Combining Spatial Enhancement MethodsCombining Spatial Enhancement Methods

Successful image enhancement is typically not achieved using a single operationRather we combine a range of techniques in order to achieve a final resultThis example will focus on This example will focus on enhancing the bone scan to the rightg t

Page 31: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Combining Spatial Enhancement Methods Combining Spatial Enhancement Methods (cont )(cont )(cont…)(cont…)

Laplacian filter ofbone scan (a)

(a)

(b)

Sharpened version ofbone scan achievedby subtracting (a)

(b)

(c)by subtracting (a)and (b) Sobel filter of bone

scan (a) (d)

Page 32: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Combining Spatial Enhancement Methods Combining Spatial Enhancement Methods (cont )(cont )(cont…)(cont…)

Sharpened image

Result of applying apower-law trans. to(g)

(h)

The product of (c)and (e) which will be

Sharpened imagewhich is sum of (a)and (f)

(g)

(f)

(g)

and (e) which will beused as a mask

(e)

(f)

Image (d) smoothed witha 5*5 averaging filter

Page 33: Image Enhancement (Spatial Filtering 2)faculty.kfupm.edu.sa/ee/samara/EE663_Lecture_6.pdf · Image Enhancement (Spatial Filtering 2) Dr Samir H AbdulDr. Samir H. Abdul-Jauwad Electrical

Combining Spatial Enhancement Methods Combining Spatial Enhancement Methods (cont )(cont )(cont…)(cont…)

Compare the original and final imagesCompare the original and final images