digital image processing - university of engineering and...

49
Digital Image Processing Lecture # 7 Image Enhancement in Spatial Domain- III

Upload: hadat

Post on 13-Apr-2019

246 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

Digital Image Processing

Lecture # 7

Image Enhancement in Spatial Domain- III

Page 2: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

ALI JAVED

Lecturer

SOFTWARE ENGINEERING DEPARTMENT

U.E.T TAXILA

Email:: [email protected]

Office Room #:: 7

Page 3: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

Presentation Outline Sharpening Spatial Filtering

Edge Detection

Derivatives

1st Order Derivative

2nd Order Derivative

Laplacian Operator

Unsharp Masking

High Boost Filtering

Gradient Operators

Sobel Operator

Prewitt Operator

Robert Cross Operator

Canny Edge Detection

Page 4: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Spatial Filtering for Sharpening

Background: To highlight fine detail in an image or to enhance blurred detail

Applications: Medical imaging, industrial inspection etc.

Foundation (Blurring vs Sharpening):

Blurring/smoothing is performed by spatial averaging (equivalent to integration)

Sharpening is performed by noting only the gray level changes in the image that is the differentiation

Page 5: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Edge Detection

What is an Edge? Edge is a change but every change is not an edge Edge is a noticeable or abrupt change

E.g 2 is not a noticeable change in the range of (0 to 255)

We have to define a threshold if the change is more than a specified threshold then we will define it as an edge point. Here gradual change exists you cannot pinpoint where the edge exists so the change must be abrupt For each pixel we have to look in horizontal, vertical and diagonal direction

dx/ds -> for horizontal direction dy/ds -> for vertical direction dd/ds -> for diagonal direction

5 7

50 55 60 65 70

50 15 35

40 20 30

225 195 230

Page 6: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Edge Detection

Page 7: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Spatial Filtering for Sharpening

Operation of Image Differentiation

Enhance edges and discontinuities (magnitude of output gray level >> 0)

De-emphasize areas with slowly varying gray-level values (output gray level: 0)

Mathematical Basis of Filtering for Image Sharpening

First-order derivatives [Gradient]

Second-order derivatives

Page 8: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Derivatives

First Order Derivative A basic definition of the first-order derivative of a one-dimensional function f(x) is the difference Second Order Derivative Similarly, we define the second-order derivative of a one-dimensional function f(x) is the difference

)()1( xfxfx

f

)(2)1()1(2

2

xfxfxfx

f

Page 9: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

1st & 2nd Order Derivatives

Page 10: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

1st & 2nd Order Derivatives

First Order Derivative Must be zero in area of constant gray levels Non zero along the ramps Non zero at the onset of the gray level step or ramp

Second Order Derivative Zero in flat areas Zero along the ramps of constant slope Non zero at the onset and end of the gray level step or ramp

Page 11: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Example for Discrete Derivatives

Page 12: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Steps to Apply Edge Detector Kernel

Page 13: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Laplacian Mask: 2nd Order Derivative

Page 14: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Laplacian Mask: 2nd Order Derivative

Page 15: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Laplacian for Image Enhancement

Image background is removed by Laplacian filtering. Background can be recovered simply by adding original image to Laplacian output

Page 16: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Laplacian for Image Enhancement

Page 17: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Image Sharpening Based on Un-sharp Masking

Un-sharp masking Sharpen images consists of subtracting an unsharp (smoothed)

version of an image from the original image

Page 18: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

High Boost Filtering

Principal application:

High Boost filtering is used when input image is darker than desired

High-boost filter makes the image lighter and more natural

A slight further generalization of un-sharp masking is called High Boost filtering A high boost filtered image, fhb, is defined at any point (x, y) as

Page 19: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

High Boost Filtering Masks

Page 20: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

High Boost Filtering Masks

Page 21: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

1st Derivative Filtering- The Gradient

1st derivative filters is Gradient which represents change For a function f (x, y) the gradient of f at coordinates (x, y) is given as the column vector:

y

fx

f

G

G

y

xf

Page 22: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

1st Derivative Filtering- The Gradient

)f( magf

21

22

yx GG

21

22

y

f

x

f

The magnitude of this vector is given by:

The direction of this vector is given by:

Page 23: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

1st Derivative Filtering- The Gradient

Now we want to define digital approximations and their Filter Masks For simplicity we use a 3x3 region For example z5 denotes f(x,y), z1 denotes f(x-1,y-1) A simple approximation for First Derivative is

z1 z2 z3

z4 z5 z6

z7 z8 z9

Page 24: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

1st Derivative Filtering- The Gradient

A simple approximation for First Derivative is

Two other definitions proposed by Roberts use cross- difference

If we use

z1 z2 z3

z4 z5 z6

z7 z8 z9

Roberts Cross-Gradient Operators

Page 25: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

A Simple Edge Detector- The Gradient

Page 26: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Gradient Operators

Normally the smallest mask used is of size 3 x 3

Based on the concept of approximating the gradient several spatial masks have been proposed

Page 27: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Gradient Operators

Page 28: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Gradient Operators

Page 29: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Gradient Operators

Page 30: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Sharpening Masks Coefficients

Why the summation of coefficients in all masks of derivate operators equals to zero?

Page 31: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Noise in an image

Problem with Edge Localization

High Threshold may suppress meaningful edges

Low Threshold may include unwanted edges

Noise may have high magnitude

Page 32: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Blurred Edges

Page 33: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Canny Edge Detection

The Canny edge detection operator was developed by John F. Canny in 1986 and uses a multi-stage algorithm to detect a wide range of edges in images. Algorithm Steps

Image smoothing

Gradient computation

Edge direction computation

Non-maximum suppression

Hysteresis Thresholding

Page 34: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Image Smoothing

Reduces image noise that can lead to erroneous output Performed by convolution of the input image with a Smoothing filter

2 4 5 4 2

4 9 12 9 4

5 12 15 12 5

4 9 12 9 4

2 4 5 4 2

1 ―

159

Page 35: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Image Smoothing

Page 36: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Gradient Computation

Determines intensity changes High intensity changes indicate edges Performed by convolution of smoothed image with masks to determine horizontal and vertical derivatives

-1 0 1

-2 0 2

-1 0 1

-1 -2 -1

0 0 0

1 2 1

x y

Page 37: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Gradient Computation

Gradient magnitude determined by adding X and Y gradient images

= x + y

Page 38: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Edge Direction Computation

Edge directions are determined from running a computation on the X and Y gradient images Edge directions are then classified by their nearest 45° angle

x

Θx,y = tan-1 y

Page 39: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Edge Direction Computation

0 ° 90 ° 45 ° 135 °

Page 40: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Non-Maximum Suppression

Given estimates of the image gradients, a search is then carried out to determine if the gradient magnitude assumes a local maximum in the gradient direction.

This is worked out by passing a 3x3 grid over the intensity map. From this stage referred to as non-maximum suppression, a set of edge points, in the form of a binary image, is obtained.

Page 41: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Non-Maximum Suppression

So, for example,

if the rounded angle is zero degrees the point will be considered to be on the edge if its intensity is greater than the intensities in the north and south directions,

if the rounded angle is 90 degrees the point will be considered to be on the edge if its intensity is greater than the intensities in the west and east directions,

if the rounded angle is 135 degrees the point will be considered to be on the edge if its intensity is greater than the intensities in the north east and south west directions,

if the rounded angle is 45 degrees the point will be considered to be on the edge if its intensity is greater than the intensities in the north west and south east directions.

Page 42: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Non-Maximum Suppression

Page 43: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Thresholding

Reduce number of false edges by applying a threshold T

all values below T are changed to 0

selecting a good values for T is difficult

some false edges will remain if T is too low

some edges will disappear if T is too high

some edges will disappear due to softening of the edge contrast by shadows

Page 44: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Hysteresis Thresholding

Thresholding with hysteresis requires two thresholds - high and low. we begin by applying a high threshold. This marks out the edges we can be fairly sure are genuine. Starting from these, using the directional information derived earlier, edges can be traced through the image. While tracing an edge, we apply the lower threshold, allowing us to trace faint sections of edges. Once this process is complete we have a binary image where each pixel is marked as either an edge pixel or a non-edge pixel.

Page 45: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Hysteresis Thresholding

Apply two thresholds in the suppressed image

T2 = 2T1

two images in the output

Gives Strong Edge pixels

T2 T1

Gives Weak Edge pixels

T2 T1

TH TL

Page 46: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Hysteresis Thresholding

the image from T2 contains fewer edges but has gaps in the contours

the image from T1 has many false edges

combine the results from T1 and T2

link the edges of T2 into contours until we reach a gap

link the edge from T2 with edge pixels from a T1 contour until a T2 edge is found again

Page 47: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Hysteresis Thresholding

T2=2 T1=1

02000030

00000030

00000230

00000300

00020200

03020000

30000000

02010030

10100030

00000230

00000300

00021200

03120000

30000000

gaps

filled

from

T1

A T2 contour has pixels along the green arrows

Linking: search in a 3x3 of each pixel and connect the pixel at the center with the one having greater value

Search in the direction of the edge (direction of Gradient)

Page 48: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

5/8/2011

Hysteresis Thresholding

Page 49: Digital Image Processing - University of Engineering and ...web.uettaxila.edu.pk/CMS/AUT2010/seDIPbs/notes/Lecture_07 Image... · Digital Image Processing Lecture # 7 Image Enhancement

Any question