digital image processing lecture 6 - basu.ac.ir€¦ · digital image processing lecture 6...

51
Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University Computer Engineering Dep. Fall 2009

Upload: others

Post on 12-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Digital Image Processing

Lecture 6(Enhancement)

Bu-Ali Sina UniversityComputer Engineering Dep.

Fall 2009

Page 2: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Outline� Image Enhancement in Spatial Domain

– Spatial Filtering• Smoothing Filters• Median Filter• Sharpening• High Boost filter• Derivative filter

Page 3: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

· Image enhancement in the spatial domain can be represented as:

The transformation T maybe linear or nonlinear. We will mainlystudy linear operators T but will see one important nonlinearoperation.

How to specify T· If the operator T is linear and shift invariant (LSI), characterized by thepoint-spread sequence (PSS) h(m, n), then (recall convolution):

Spatial Filtering

Page 4: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Spatial Filtering

r s t

u v w

x y z

Origin x

y Image f (x, y)

eprocessed = v*e +r*a + s*b + t*c +u*d + w*f +x*g + y*h + z*i

FilterSimple 3*3

�eighbourhood e 3*3 Filter

a b c

d e f

g h iOriginal Image

Pixels

*

The above is repeated for every pixel in theoriginal image to generate the smoothed image

Page 5: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· If h(m, n) is a 3 by 3 mask given by :

Spatial Filtering

Page 6: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

o Image smoothing refers to any image-to-image transformation designed to“smooth” or flatten the image by reducing the rapid pixel-to-pixel variationin grayvalues.

o Smoothing filters are used for:o Blurring: This is usually a preprocessing step for removing small(unwanted) details before extracting the relevant (large) object,bridging gaps in lines/curves,o�oise reduction: Mitigate the effect of noise by linear ornonlinear operations.

o Image smoothing by averaging (lowpass spatial filtering)

o Smoothing is accomplished by applying an averaging mask.

o An averaging mask is a mask with positive weights, which sum to 1. Itcomputes a weighted average of the pixel values in a neighborhood. Thisoperation is sometimes called neighborhood averaging.

Spatial Filtering- Smoothing Filters

Page 7: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· Some 3 x 3 averaging masks:Spatial Filtering- Smoothing Filters

Page 8: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· This operation is equivalent to lowpass filtering.Example of Image Blurring

Spatial Filtering- Smoothing Filters

Page 9: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)Spatial Filtering- Smoothing Filters

Page 10: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

Example of noise reduction :Spatial Filtering- Smoothing Filters

Page 11: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· The averaging filter is best suited for noise whose distribution is Gaussian:

· The averaging filter typically blurs edges and sharp details.· The median filter usually does a better job of preserving edges.· Median filter is particularly suited if the noise pattern exhibits strong (positiveand negative) spikes. Example: salt and pepper noise.· Median filter is a nonlinear filter, that also uses a mask. Each pixel is replacedby the median of the pixel values in a neighborhood of the given pixel.· Suppose are the pixel values in a neighborhood of a givenpixel with Then :

Note: Median of a set of values is the “center value,” after sorting.· For example: If A = {0,1,2,4,6,6,10,12,15}, then median(A) = 6.

Spatial Filtering- Median Filter

Page 12: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Spatial Filtering- Median Filter

Page 13: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

Example of noise reduction :Spatial Filtering- Median Filter

Page 14: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)Spatial Filtering- Median Filter

Page 15: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)Spatial Filtering- Median Filter

Page 16: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

�To highlight fine detail or to enhanceblurred detail.– smoothing ~ integration– sharpening ~ differentiation

�Categories of sharpening filters:

– Derivative operators– Basic highpass spatial filtering– High-boost filtering

Spatial Filtering- Sharpening Filter

Page 17: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Spatial Differentiation

Differentiation measures the rate of change ofa functionLet’s consider a simple 1 dimensionalexample

Page 18: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Spatial Differentiation

A B

Page 19: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

1st Derivative

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

It’s just the difference between subsequentvalues and measures the rate of change of thefunction

)()1( xfxfxf

−+=∂∂

Page 20: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

1st Derivative

0

1

2

3

4

5

6

7

8

-8

-6

-4

-2

0

2

4

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

Page 21: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

2nd Derivative

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

Simply takes into account the values bothbefore and after the current value

)(2)1()1(2

2

xfxfxfxf

−−++=∂∂

Page 22: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

2nd Derivative

0

1

2

3

4

5

6

7

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

-15

-10

-5

0

5

10

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

Page 23: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Using Second Derivatives For Image Enhancement

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

–Stronger response to fine detail–Simpler implementation–We will come back to the 1st order derivative

later onThe first sharpening filter we will look at is theLaplacian

–One of the simplest sharpening filters–We will look at a digital implementation

Page 24: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

The Laplacian

The Laplacian is defined as follows:

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

and in the y direction as follows:

yf

xff 2

2

2

22

∂∂

+∂∂

=∇

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

2

yxfyxfyxfxf

−−++=∂∂

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

2

yxfyxfyxfyf

−−++=∂∂

Page 25: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

The Laplacian

So, the Laplacian can be given as follows:

We can easily build a filter based on this

),1(),1([2 yxfyxff −++=∇)]1,()1,( −+++ yxfyxf

),(4 yxf−

0 1 0

1 -4 1

0 1 0

Page 26: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

The Laplacian

Applying the Laplacian to an image we get anew image that highlights edges and otherdiscontinuities

OriginalImage

LaplacianFiltered Image

LaplacianFiltered Image

Scaled for Display

Page 27: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

But That Is Not Very Enhanced!

The result of a Laplacian filtering isnot an enhanced imageWe have to do more work in orderto get our final imageSubtract the Laplacian result fromthe original image to generate ourfinal sharpened enhanced image

LaplacianFiltered Image

Scaled for Display

fyxfyxg 2),(),( ∇−=

Page 28: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Laplacian Image Enhancement

In the final sharpened image edges and finedetail are much more obvious

- =

OriginalImage

LaplacianFiltered Image

SharpenedImage

Page 29: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Laplacian Image Enhancement

Page 30: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Simplified Image Enhancement

The entire enhancement can be combined intoa single filtering operation

),1(),1([),( yxfyxfyxf −++−=)1,()1,( −+++ yxfyxf

)],(4 yxf−

fyxfyxg 2),(),( ∇−=

),1(),1(),(5 yxfyxfyxf −−+−=)1,()1,( −−+− yxfyxf

Page 31: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Simplified Image Enhancement

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

0 -1 0

-1 5 -1

0 -1 0

Page 32: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Simplified Image Enhancement

Page 33: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Variants On The Simple Laplacian

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

0 1 0

1 -4 1

0 1 0

1 1 1

1 -8 1

1 1 1

-1 -1 -1

-1 9 -1

-1 -1 -1

SimpleLaplacian

Variant ofLaplacian

Page 34: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

1st Derivative Filtering

Implementing 1st derivative filters is difficult inpracticeFor a function f(x, y) the gradient of f atcoordinates (x, y) is given as the columnvector:

∂∂∂∂

=

=∇

yfxf

GG

y

xf

Page 35: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

1st Derivative Filtering

The magnitude of this vector is given by:

For practical reasons this can be simplified as:

)f(∇=∇ magf

[ ] 2122

yx GG +=

21

22

∂∂

+

∂∂

=yf

xf

yx GGf +≈∇

Page 36: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

1st Derivative Filtering

There is some debate as to how best tocalculate these gradients but we will use:

which is based on these coordinates

( ) ( )321987 22 zzzzzzf ++−++≈∇

( ) ( )741963 22 zzzzzz ++−+++

z1 z2 z3

z4 z5 z6

z7 z8 z9

Page 37: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Sobel Operators

Based on the previous equations we canderive the Sobel Operators

To filter an image it is filtered using bothoperators the results of which are addedtogether

-1 -2 -1

0 0 0

1 2 1

-1 0 1

-2 0 2

-1 0 1

Page 38: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Sobel Example

Sobel filters are typically used for edgedetection

An image of acontact lens whichis enhanced inorder to makedefects (at fourand five o’clock inthe image) moreobvious

Page 39: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· We may use the approximation :

· This can implemented using the masks:

As follows:

· Alternatively, we may use the approximation:

· This can implemented using the masks:

As follows:

1st Derivative Filtering

Page 40: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· The resulting masks are called Roberts cross-gradient operators.· The Roberts operators and the Prewitt/Sobel operators (described later) are usedfor edge detection and are sometimes called edge detectors.

Example: Roberts cross-gradient operator :

Roberts cross-gradient operator

Page 41: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)

· Better approximations to the gradient can be obtained by:

· This can be implemented using the masks:

as follows:

· The resulting masks are called Prewitt operators.·

Prewitt operators

Page 42: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)Prewitt operators

Page 43: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

1st & 2nd Derivatives

Comparing the 1st and 2nd derivatives we canconclude the following:

–1st order derivatives generally produce thickeredges

–2nd order derivatives have a stronger responseto fine detail e.g. thin lines

–1st order derivatives have stronger response togrey level step

–2nd order derivatives produce a double responseat step changes in grey level

Page 44: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Spatial Filtering- High-boost filtering

· This is a filter whose output g is produced by subtracting a lowpass (blurred)version of f from an amplified version of f :

This is also referred to as unsharp masking.· Observe that :

· For A >1, part of the original image is added back to the highpass filtered versionof f.· The result is the original image with the edges enhanced relative to the originalimage.

Page 45: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Spatial Filtering- High-boost filtering

Page 46: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)Spatial Filtering- High-Boost Filtering

Page 47: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Chapter 3: Image Enhancement (Spatial Filtering)Spatial Filtering- Derivative filter

Page 48: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Combining Spatial Enhancement Methods

Successful imageenhancement is typically notachieved using a singleoperationRather we combine a rangeof techniques in order toachieve a final resultThis example will focus onenhancing the bone scan tothe right

Page 49: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Combining Spatial Enhancement Methods

Laplacian filter ofbone scan (a)

Sharpened version ofbone scan achievedby subtracting (a)and (b) Sobel filter of bone

scan (a)

(a)

(b)

(c)

(d)

Page 50: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Combining Spatial Enhancement Methods

The product of (c)and (e) which will beused as a mask

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

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

(e)

(f)

(g)

(h)

Image (d) smoothed witha 5*5 averaging filter

Page 51: Digital Image Processing Lecture 6 - basu.ac.ir€¦ · Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University ... Categories of sharpening filters: – Derivative

Combining Spatial Enhancement Methods

Compare the original and final images