0% found this document useful (0 votes)
13 views34 pages

Dip Chap03 2

Uploaded by

hazemmohummed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views34 pages

Dip Chap03 2

Uploaded by

hazemmohummed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

Digital Image Processing

Chapter 3:
Image Enhancement in the
Spatial Domain

20 April 2014
Logic Operations

Application:
Crop areas
of interest
AND

OR

Original Image mask Result Region


image of Interest (Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
Arithmetic Operation: Subtraction
Application: Error measurement

Error
image

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Arithmetic Operation: Subtraction (cont.)
Application: Mask mode radiography in angiography work

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Arithmetic Operation: Image Averaging
Application : Noise reduction

Degraded image
g ( x, y )  f ( x, y )   ( x, y )
(noise)
Image averaging
K
1
g ( x, y ) 
K
 g ( x, y )
i 1
i

Averaging results in reduction of


Noise variance
1
 g ( x, y )   ( x , y )
K

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Arithmetic Operation: Image Averaging (cont.)

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Basics of Spatial Filtering

Sometime we need to manipulate values obtained from


neighboring pixels
Example: How can we compute an average value of pixels
in a 3x3 region center at a pixel z?
Pixel z
2 4 1 2 6 2
9 2 3 4 4 4
7 2 9 7 6 7
5 2 3 6 1 5
7 4 2 5 1 2
2 5 2 3 2 8
Image
Basics of Spatial Filtering (cont.)

Step 1. Selected only needed pixels

Pixel z


2 4 1 2 6 2
9 2 3 4 4 4 3 4 4
7 2 9 7 6 7 … 9 7 6 …
5 2 3 6 1 5 3 6 1
7 4 2 5 1 2


2 5 2 3 2 8
Basics of Spatial Filtering (cont.)

Step 2. Multiply every pixel by 1/9 and then sum up the values


3 4 4
… 9 7 6 …
1 1 1
3 6 1 y  3  4  4
9 9 9

1 1 1
 9  7  6
X 9 9 9
1 1 1
1 1 1 1  3  6  1
Mask or 9 9 9
9 1 1 1 Window or
1 1 1 Template

Note: An m*n mask would have a normalizing constant equal to 1/mn.


Basics of Spatial Filtering (cont.)

Question: How to compute the 3x3 average values at every pixels?

Solution: Imagine that we have


2 4 1 2 6 2 a 3x3 window that can be placed
9 2 3 4 4 4 everywhere on the image
7 2 9 7 6 7
5 2 3 6 1 5
7 4 2 5 1 2

Masking Window
Basics of Spatial Filtering (cont.)

Step 1: Move the window to the first location where we want to


compute the average value and then select only pixels
inside the window.
2 4 1 2 6 2 2 4 1 Step 2: Compute
the average value
9 2 3 4 4 4 9 2 3 3 3
1
7 2 9 7 6 7 7 2 9 y  p(i, j )
i 1 j 1 9
5 2 3 6 1 5 Sub image p
7 4 2 5 1 2 Step 3: Place the
Original image result at the pixel
4.3 in the output image
Step 4: Move the
window to the next
location and go to Step 2 Output image
Basics of Spatial Filtering (cont.)

The 3x3 averaging method is one example of the mask


operation or Spatial filtering.
 The mask operation has the corresponding mask (sometimes
called window or template).
 The mask contains coefficients to be multiplied with pixel
values.
Example : moving averaging
w(1,1) w(2,1) w(3,1)
1 1 1
w(1,2) w(2,2) w(3,2) 1
1 1 1
9
w(3,1) w(3,2) w(3,3) 1 1 1

Mask coefficients The mask of the 3x3 moving average


filter has all coefficients = 1/9
Basics of Spatial Filtering (cont.)

The mask operation at each point is performed by:


1. Move the reference point (center) of mask to the
location to be computed
2. Compute sum of products between mask coefficients
and pixels in subimage under the mask.
Mask frame

p(1,1) p(2,1) p(3,1) w(1,1) w(2,1) w(3,1)

… p(2,1) p(2,2) p(3,2) … w(1,2) w(2,2) w(3,2)

p(1,3) p(2,3) p(3,3) w(3,1) w(3,2) w(3,3)


Subimage Mask coefficients


N M
The reference point y  w(i, j ) p(i, j )
of the mask i 1 j 1
Basics of Spatial Filtering (cont.)

The spatial filtering on the whole image is given by:

1. Move the mask over the image at each location.


2. Compute sum of products between the mask coefficeints
and pixels inside subimage under the mask.
3. Store the results at the corresponding pixels of the
output image.
4. Move the mask to the next location and go to step 2
until all pixel locations have been used.
Examples of Spatial Filtering Masks

Examples of the masks


Sobel operators 3x3 moving average filter
-1 0 1 -1 -2 -1 1 1 1
1
-2 0 2 0 0 0 1 1 1
9
-1 0 1 1 2 1 1 1 1
P P
to compute to compute
x y

3x3 sharpening filter


-1 -1 -1
1
-1 8 -1
9
-1 -1 -1
Smoothing Linear Filter : Moving Average

Application : noise reduction


and image smoothing

Disadvantage: lose sharp details

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Smoothing Linear Filter (cont.)

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Order-Statistic Filters
Original image
subimage

Statistic parameters
Mean, Median, Mode,
Min, Max, Etc.

Moving
window

Output image
Order-Statistic Filters: Median Filter

nonlinear spatial filters whose response is based on ordering


(ranking) the pixels.
In order to perform median filtering at a point in an image, we first
sort the values of the pixel in question and its neighbors, determine
their median, and assign this value to that pixel.

E.X. In a 3*3 neighborhood the median is the 5th largest value,


in a 5*5 neighborhood the 13th largest value, and so on.
Sharpening Spatial Filters

Highlight fine detail in an image or to enhance detail that has been blurred.
There are intensity discontinuities near object edges in an image

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Laplacian Sharpening : How it works

Intensity profile 1

0.5 Edge
p(x)
0
20 40 60 80 100 120 140 160 180 200
0.2
1st derivative
0.1
dp
dx 0
0 50 100 150 200
0.05
2nd derivative
2 0
d p
dx 2 -0.05
0 50 100 150 200
Laplacian Sharpening : How it works (cont.)
1.5

p(x) 0.5

-0.5
0 50 100 150 200

1.5

1
2
d p
p( x )  10 2 0.5
dx
0

-0.5
0 50 100 150 200

Laplacian sharpening results in larger intensity discontinuity


near the edge.
Laplacian Sharpening : How it works (cont.)

Before sharpening
p(x)

After sharpening
d2p
p( x )  10 2
dx
Laplacian Masks

2 2
2  P  P
Used for estimating image Laplacian  P  2  2
x y

-1 -1 -1 0 -1 0
-1 8 -1 -1 4 -1 The center of the mask
is positive
-1 -1 -1 0 -1 0
or
1 1 1 0 1 0
The center of the mask
1 -8 1 1 -4 1 is negative
1 1 1 0 1 0

Application: Enhance edge, line, point


Disadvantage: Enhance noise
Laplacian Sharpening Example

p 2 P

2 P P  2 P

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
Laplacian Sharpening (cont.)

Mask for
2
P  P
0 -1 0 -1 -1 -1
-1 5 -1 or -1 9 -1
Mask for 0 -1 0 -1 -1 -1
2 P

1 1 1
1 -8 1
1 1 1
or
0 1 0
1 -4 1
0 1 0
(Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
Unsharp Masking and High-Boost Filtering

-1 -1 -1 0 -1 0

-1 k+8 -1 -1 k+4 -1

-1 -1 -1 0 -1 0

Equation:

kP ( x, y )  2 P ( x, y ) The center of the mask is negative


Phb ( x, y )  2
 kP ( x , y )   P ( x, y ) The center of the mask is positive
Unsharp Masking and High-Boost Filtering (cont.)

(Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition.
First Order Derivative

Intensity profile 1

p(x) 0.5 Edges


0
20 40 60 80 100 120 140 160 180 200
0.2
1st derivative
dp 0
dx
-0.2
0 50 100 150 200
2nd derivative 0.2

dp
0.1
dx
0
0 50 100 150 200
First Order Partial Derivative:
Sobel operators
-1 0 1 -1 -2 -1
P P
-2 0 2 to compute 0 0 0 to compute
x y
-1 0 1 1 2 1

P P P
x y
First Order Partial Derivative: Image Gradient
Gradient magnitude
2 2
 P   P 
P      
 x   y 

A gradient image emphasizes edges


(Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.
First Order Partial Derivative: Image Gradient

P
P y

P P
x
Image Enhancement in the Spatial Domain : Mix things up !

2 P

P

A B D smooth

+ -

Sharpening C (Images from Rafael C. Gonzalez and Richard E.


Wood, Digital Image Processing, 2nd Edition. E
Image Enhancement in the Spatial Domain : Mix things up !

Power
G
C E Law Tr.

F
A
Multiplication
H
(Images from Rafael C. Gonzalez and Richard E.
Wood, Digital Image Processing, 2nd Edition.

You might also like