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

Post on 12-Jun-2020

7 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Digital Image Processing

Lecture 6(Enhancement)

Bu-Ali Sina UniversityComputer Engineering Dep.

Fall 2009

Outline� Image Enhancement in Spatial Domain

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

· 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

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

Chapter 3: Image Enhancement (Spatial Filtering)

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

Spatial Filtering

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

Chapter 3: Image Enhancement (Spatial Filtering)

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

Chapter 3: Image Enhancement (Spatial Filtering)

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

Spatial Filtering- Smoothing Filters

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

Chapter 3: Image Enhancement (Spatial Filtering)

Example of noise reduction :Spatial Filtering- Smoothing Filters

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

Spatial Filtering- Median Filter

Chapter 3: Image Enhancement (Spatial Filtering)

Example of noise reduction :Spatial Filtering- Median Filter

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

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

�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

Spatial Differentiation

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

Spatial Differentiation

A B

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

−+=∂∂

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

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

−−++=∂∂

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

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

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

−−++=∂∂

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

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

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),(),( ∇−=

Laplacian Image Enhancement

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

- =

OriginalImage

LaplacianFiltered Image

SharpenedImage

Laplacian Image Enhancement

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

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

Simplified Image Enhancement

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

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

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 +≈∇

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

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

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

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

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

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

Chapter 3: Image Enhancement (Spatial Filtering)Prewitt operators

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

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.

Spatial Filtering- High-boost filtering

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

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

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

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)

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

Combining Spatial Enhancement Methods

Compare the original and final images

top related