EE409_4_Contrast_Enhancement_c

Page 1

EE409 – Digital Image Processing 2017-2018 Spring

4. Image Enhancement in Spatial Domain c) Image Derivatives, Edge Detection & Sharpening

by: Dr. Gökhan Koray GÜLTEKİN

Edges  Edges are those places in an image that correspond to object boundaries.  Edges are pixels where image brightness changes abruptly.

Brightness vs. Spatial Coordinates

1


Edges 

Ideal edge

A(x) x

It is usually ramped because of sensor processing during capture Noisy edge

A(x) x

A(x) x

Edge Detection 

Edge information in an image is found by looking at the relationship

P

a pixel has with its neighborhoods. 

If a pixel’s gray-level value is similar to those around it, there is probably not an edge at that point.

185 187 182 183 187 186 182 186 188 187 190 191 188 186 186 187 187 185 178 178 180 184 188 190 35 28 25 25 27 29 41

If a pixel’s has neighbors with widely varying gray levels, it may present

21 19 19 18 20 19 21 18 21 18 19 19 19 17

an edge point.

2


Edges in 2-D Images 

Direction of gradient at any point is the direction of maximum change.

Edge Detection Methods 

Many are implemented with convolution mask and based on discrete approximations to differential operators.

Differential operations measure the rate of change in the image brightness function.

Some operators return orientation information. Other only return information about the existence of an edge at each point.

3


Image Derivatives:

1st Order Derivative (Gradient) and

2nd Order Derivative (Laplacian)

Derivative(Gradient) of a Function  Derivative gives the rate of change(slope) of a function  Definition of 1 dimensional, discrete, 1st order derivative:  df / dx = f(x+1) – f(x)  Derivative operator: -1

f(x+1) f(x)

1 x

x+1

 The 2nd order derivative is the derivative of the 1st order derivative…

4


Derivatives of a 1D Signal  

First derivative: dA /dx

A x 

200 100 0

Second derivative, d2A/dx2,generates two peaks at beginning and end of edge

5

10

15

20

25

30

5

10

15

20

25

30

5

10

15

20

25

30

20

dA dx

0

-20 20

d2A dx 2

Called ‘ringing’

0

-20

Discrete Derivatives 200

1D Signal:

100 0

5

10

15

20

25

30

5

10

15

20

25

30

5

10

15

20

25

30

20

1st derivative:

0

-20 20

2nd derivative:

0

-20

5


Spatial Differentiation  Differentiation measures the rate of change of a function  Let’s consider a simple 1 dimensional differentiation example using this image:

Spatial Differentiation A

B

6


First and Second Order Derivative

A

B

First and Second Order Derivative

 1st order generally produces thicker edges  2nd order shows stronger response to detail  1st order generally response stronger to gray level step  2nd order produce double (pos/neg) response at step change

7


Horizontal and Vertical Gradients(derivative) -1 -1

1 1

Roberts (±45°) Edge Detector:

Sobel (0°,90°) Edge Detector:

Sobel Edge Detector Detects vertical edges

To 1. 2. 3.

Detects horizontal edges

find edge strength(magnitude) and direction(angle); Find the horizontal gradient (derivative) Find the vertical gradient (derivative) Find magnitude and angle from gradients

8


Edge Strength & Direction To 1. 2. 3.

find edge strength(magnitude) and direction(angle); Find the horizontal gradient (derivative) Find the vertical gradient (derivative) Find magnitude and angle from gradients

Edge Detection

9


2nd Order Derivative (Laplacian) The 2nd order derivative is the derivative of the 1st order derivative‌ F(x-1)

pixels

F(x)

F(x+1)

F(x+1) - F(x)

F(x+2) - F(x+1)

derive F(x) - F(x-1) 1st derivative derive [ F(x+1)-F(x) ] – [ F(x)-F(x-1) ] 2nd derivative F(x+1) -2F(x)+F(x-1)

2nd Order Derivative (Laplacian) One dimensional 2nd order derivative in x direction: F(x+1)-F(x) – (F(x)-F(x-1))= F(x+1) -2F(x) +F(x-1) 1

-2

1

One dimensional 2nd order derivative, in y direction:

1 -2 1

10


2nd Order Derivative (Laplacian) Two dimensional 2nd order derivative: 0

0

0

1

-2

1

0

0

0

+

0

1

0

0

-2

0

0

1

0

=

0

1

0

1

-4

1

0

1

0

This mask is called the ‘LAPLACIAN’ (remember calculus ?)

Laplacian Masks

11


Calculating Laplacian in Matlab imd = im2double(im); % create laplacian h=[1 1 1;1 -8 1; 1 1 1]; % Filter: imlap=conv2(imd,h); % Normalize and show imshow(imlap,[]);

Notice: Derivatives may generate negative values

Laplacian Example

In Matlab: ‘saturn.png’

 1 1 1  1 8 1    1 1 1

12


What is Edge-enhancement? 

Physcophysical experiments indicate that an image with sharp edges is often more subjectively pleasing than the original image

How can we enhance edges?  

Q: What is a measure of the strength of an edge? A: How steep it is

A(x)

x

Now we will see methods to enhance (sharpen) edges

13


Sharpening in General:

High Boost Filtering and

Unsharp Masking

Sharpening (High Pass) Spatial Filters 

Previously we have looked at smoothing filters which remove fine detail

Sharpening spatial filters seek to highlight fine detail

Highlight edges (High Boost)

Remove blurring from images (Unsharp Masking)

Sharpening filters are based on spatial differentiation

14


High Boost Sharpening Edges detected by the Laplacian can be used to sharpen the image:

Image

+ Laplacian

Sharpened Image

In Matlab: ‘moon.tif’

15


High Boost Sharpening

High Boost Sharpening Filters Laplacian

Sobel

16


High Boost Sharpening Example: High boost sharpening in MATLAB imd=im2double(im); h=[1 1 1;1 -8 1; 1 1 1]; imlap=imfilter(imd,h); figure; imshow(imd) figure; imshow(imd+imlap) Note: imlap=imfilter(imd,h, ‘replicate‘) This command will apply border padding instead of zero padding

High Boost Sharpening Sharpening can be done in 1 pass: 0

-1

0

-1

4

-1

0

-1

0

LAPLACIAN

+

0

0

0

0

1

0

0

0

0

Original Image

=

0

-1

0

-1

5

-1

0

-1

0

Sharpened Image

17


High Boost Sharpening High Boost Sharpening Masks:

High Boost Sharpening

 1 1 1  1 8 1    1 1 1

 1 1 1  1 9 1    1 1 1

A high-pass filter (Laplacian)

A high-boost filter 36

18


High Boost Sharpening (Using Sobel) imd=im2double(im); h1=[1 2 1;0 0 0; -1 -2 -1];

% horizontal sobel mask

h2=h1';

% vertical sobel mask

p1=imfilter(imd,h1); % apply horiz. sobel filter on image p2=imfilter(v,h2); % apply vert. sobel filter on image p3=abs(p1)+abs(p2); % Add abs. Sobel edges imshow(imd),figure,imshow(p3+imd); % Add sobel edges to image

Unsharp Masking Basic Idea (unsharp masking): Subtract a BLURRED version of an image from the image itself !

Fsharp = F – Fblurred

19


Unsharp Masking Attenuate low frequencies Fsharp = a*F – Fblurred , a>=1

0

-1

0

-1

a-1

-1

0

-1

0

Unsharp Masked (sharpened) Image

=

0

0

0

0

a

0

0

0

0

Original Image (multiplied by a)

-

0

1

0

1

1

1

0

1

0

Averaging Filtered Image

Unsharp Masking Example: Unsharp masking sharpening in MATLAB imd=im2double(im); h=ones(3,3); imavg=imfilter(imd,h); figure; imshow(imd) figure; imshow(2*imd-imavg)

20


Unsharp Masking Different Examples of Sharpening Filters: 0

-1

0

-1

0

-1

0

-1

0

a=1

Laplacian + Image (High Boost) 0

-1

0

-1

5

-1

0

-1

0

a=6

Notice: Normalization may be needed after these operations

Questions

0

-1

0

-1

1e7

-1

0

-1

0

a=1e7+1

?

21


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.