Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

www.singidunum.ac.

rs

Digital Image Processing

Dr. Marina Marjanovic


University of Singidunum
Image Enhancement
in Spatial Domain
Lecture 5
What we saw in previous lecture:
•Arithmetic and Logic operations.
•Subtraction
•Image Averaging
•Convolution and Correlation
•Averaging filter:
 Box Filter
 Weighted Averaging Filter
Example
Given an 8-bit image segment and respective pixel values
below, Apply the kernel given below to calculate the
convolution response at pixel location (3,3).

65 25 95 65 40

10 95 40 65 25

95 25 65 40 65

65 40 40 10 25

25 65 10 65 10
3x3 Kernel

1 2 1
1

18 2 4 3

1 3 1
Image Enhancement in Spatial Domain
Order-Statistics Filters
•The order-statistics filters are nonlinear spatial filters whose response is based
on the ordering/ranking of the pixels contained image area encompassed by the
filter.
•The center pixel is replaced with the value determined by the ranking result.

•The best known ordered –statistics filter is the median filter.


•The median filter is excellent for random noise reduction with considerably less
blurring than the linear smoothing filters.
•Median filters is very effective for impulsive noise which is also called salt-and-
pepper noise (noise introducing white and black dots on the image)

•Given a 3x3 neighborhood having (10, 20 ,20 ,20 ,100 ,20 ,20 ,25 ,15) gray level
values. The sorted values of the neighborhood will be: (10, 15 ,20 ,20 ,20 ,20 ,20 ,
25 ,100) and the center pixel will be forced to the median value which is 20.
Image Enhancement in Spatial Domain
Order-Statistics Filters
Corrupted by
salt and pepper noise Averaging filter median filter
Image Enhancement in Spatial Domain
Sharpening Spatial Filters
•Sharpening is the operation to highlight fine details or enhance the detals that
has been blurred.
•Blurring is based on the averaging in a neighborhood which is analogous to
integration. Therefore the sharpening could be accomplish by differentiation.

•The derivative of a digital function is defined in terms of differences, where a


first order derivative of a one dimensional function f(x) is:
f
 f ( x  1)  f ( x)
x
•Second order derivative can be defined by:

2 f
2
 f ( x  1)  f ( x)  ( f ( x)  f ( x  1))
x
 f ( x  1)  f ( x  1)  2 f ( x)
Image Enhancement in Spatial Domain
Sharpening Spatial Filters
•The effect of the first and second-order derivatives on an image are:
•First-order derivative
- Zero in flat segments.
- Nonzero at ramps.

•Second-order derivative
- Zero in Flat segments.
- Nonzero at the beginning and
the end of ramps.
- Zero in along ramps.
Image Enhancement in Spatial Domain
Second-order Derivatives for Enhancement - The Laplacian
•Second-order derivative is used to construct a Laplacian filter mask. Laplacian
is an isotropic filter where the response of the filter is independent of the
direction of the discontinuities in the image.
•Isotropic filters are rotation invariant, which means that if you rotate and filter
the image or if you filter and then rotate the image you get the same result.

•Given an image f(x,y) the Laplacian operator is defined by:


 2
f  2
f
 f  2  2
2

x y
•The operator is a linear operator and can be expressed in discrete form in x-
direction by:
2 f
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
x 2
Image Enhancement in Spatial Domain
Second-order Derivatives for Enhancement - The Laplacian
•The operator can be expressed in discrete form in y-direction by:

2 f
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
y 2

•Then,2-D Laplacian is:

 2 f   f ( x  1, y )  f ( x  1, y )  f ( x, y  1)  f ( x, y  1) 
 4 f ( x, y )
Image Enhancement in Spatial Domain
Second-order Derivatives for Enhancement - The Laplacian
•The filter masks used to implement the digital Laplacian:

considers x, y
considers x and y and two diagonal
coordinates coordinates.
Isotropic results for 90o
Isotropic for 45o
Image Enhancement in Spatial Domain
Second-order Derivatives for Enhancement - The Laplacian
•The Laplacian operator highlights gray level discontinuities and de-emphasizes
the slowly varying gray-levels.
• The result of Laplacian operator will give edge lines and other discontinuities
on a dark and featureless background.
•The background features can be recovered and sharpening effect can be
preserved by adding the Laplacian image to the original image.

•Depending on the choice of the Laplacian coefficients the following criteria is


used for enhancement:
 f ( x, y )   f ( x, y )
2 •If the center coefficient of the
g ( x, y )   Laplacian mask is negative

 f ( x, y )   f ( x, y )
2 •If the center coefficient of the
Laplacian mask is positive
Image Enhancement in Spatial Domain
Second-order Derivatives for Enhancement - The Laplacian

Laplacian image
 2 f ( x, y )
Original image
f ( x, y )
Enhanced image
f ( x, y )   2 f ( x, y )
Image Enhancement in Spatial Domain
Second-order Derivatives for Enhancement - The Laplacian

Original image

Enhanced image
using the mask with
Center coefficient -8

Enhanced image
using the mask with
Center coefficient -4
Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient
•The first derivatives in image processing are implemented by using the
magnitude of the gradient.
• The gradient of f at coordinates (x,y) is defined by the two-dimensional column
vector:
 f 
Gx   x 
f      f 
G y   
 y 
•The magnitude of this vector, is referred to as the gradient, which is :
2

 
2
2 2 1/ 2  f   f 
f  mag (f )  Gx  G y      
 x   y 
Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient
•The magnitude of the gradient can be approximated by using the absolute
values instead of squares and square roots, which is cheaper to compute and still
preserves changes in the gray levels.

f  G x  G y

•If we consider a 3x3 filter mask then an approximation around the center pixel
will be as follows:

f  Gx  G y  ( z7  2 z8  z9 )  ( z1  2 z 2  z3 )
 ( z3  2 z6  z9 )  ( z1  2 z4  z7 )
Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient

•The above masks are called the Sobel operators and can be used to implement
gradient operation.
•The idea behind using weight value of 2 is to achieve some smoothing by giving
more importance to the center point.
•The mask on the left approximates the derivative in x-direction (row 3- row 1).
•The mask on the right approximates the derivative in y-direction (col 3- col 1).
Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient

Defects are more visible


Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient
•Edge Detection: Consider the following image and the respective sobel
operators

Horizontal Operator Vertical Operator

•If the image is convolved(or correlated) by using the sobel operators given
above. Then,
Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient
•Edge Detection:

gh gv
Horizontal Sobel Operator Vertical Sobel Operator
highlights the horizontal highlights the vertical
edges edges
Image Enhancement in Spatial Domain
The First Derivatives for Enhancement - The Gradient
•Edge Detection:
•The Gradient for each pixel can be defined to extract
edges.

2 2
g ( x , y )  g ( x, y ) h  g ( x, y ) v

•Edges are detected by combining horizontal and vertical


images obtained using respective Sobel operators.
Image Enhancement in Spatial Domain
Multi-diagonal Matrix Multiplication – Fast Binary Filter
A ξ-diagonal matrix is defined to be a symmetric square
matrix, ψkxk(ξ), which has value 1 on its ξ diagonals and 0
on the remaining members.

1 i  j  
 kk      i, j  1,, k ,   k
0 otherwise
1 1 1 0 0 0 0
1 1 1 1 0 0 0
 
1 1 1 1 1 0 0
 77  5    0 1 1 1 1 1 0

0 0 1 1 1 1 1
 
0 0 0 1 1 1 1
 0 0 0 0 1 1 1
Image Enhancement in Spatial Domain
Multi-diagonal Matrix Multiplication – Fast edge detection
 a11  a12  a1 j1  a1 j  a1 j 1 a1 n1  a1n 

 
   
1  Amn  nn  3   ai 1  ai 2  ai j 1  ai j  ai j 1  ai n 1  ai n 
 
   
a  a  am j 1  am j  am j 1  am n 1  am n 
 m1 m2
 a11  a2 1  a j11  a j 1  a j 11  an11  an 1 
 
   
 a j 1i  a j i  a j 1i  an1i  an i 
n  mm  3  a1i  a2 i
T
2  Am 
 
   
a  a  a j1 m  a j m  a j 1 m  an 1 m  an m 
 1m 2 m

 2a11  a12  a2 1  a1 j1  2a1 j  a2 j  a1 j 1  a1 n1  a2 n  2a1 n 


 
   
T  2a  a 
   1  2  i1 i 11  ai 2  ai  11  ai j1  ai 1 j  2ai j  ai  1 j  ai j 1  ai n 1  2ai n  ai 1 n  ai 1 n
 
   
 2a  a am n1  2am n  am1n 
 m1 m 11  am 2  am j1  2am j  am1 j  am j 1 
Image Enhancement in Spatial Domain
Multi-diagonal Matrix Multiplication – Fast Binary Filter
 a11  a12  a1 j1  a1 j  a1 j 1 a1 n1  a1n 

 
   
1  Amn  nn  3   ai 1  ai 2  ai j 1  ai j  ai j 1  ai n 1  ai n 
 
   
a  a  am j 1  am j  am j 1  am n 1  am n 
 m1 m2
 a11  a2 1  a j11  a j 1  a j 11  an11  an 1 
 
   
 a j 1i  a j i  a j 1i  an1i  an i 
n  mm  3  a1i  a2 i
T
2  Am 
 
   
a  a  a j1 m  a j m  a j 1 m  an 1 m  an m 
 1m 2 m

 2a11  a12  a2 1  a1 j1  2a1 j  a2 j  a1 j 1  a1 n1  a2 n  2a1 n 


 
   
T  2a  a 
   1  2  i1 i 11  ai 2  ai  11  ai j1  ai 1 j  2ai j  ai  1 j  ai j 1  ai n 1  2ai n  ai 1 n  ai 1 n
 
   
 2a  a am n1  2am n  am1n 
 m1 m 11  am 2  am j1  2am j  am1 j  am j 1 
Image Enhancement in Spatial Domain
Multi-diagonal Matrix Multiplication – Fast Binary Filter
By choosing a threshold value equal to ξ the connected
components with sizes less than ξ will be removed.
Ψn(ξ): ξ-diagonal
matrix
Salt and Pepper
noise
Ξ1
X
Filtered Binary
Binary Image +  1   i, j  
with noise A   Image
+ 0 otherwise A mn
Amxn
Ξ2
Transpose X Transpose

Ψm(ξ): ξ-diagonal
matrix
Image Enhancement in Spatial Domain
Multi-diagonal Matrix Multiplication – Fast Binary Filter

(a) (b) (c) (d)


(a) Original binary image, (b) corrupted image, (c) the generated intermediate image after
multiplications and addition, and (d) filter image after thresholding.

Multi-diagonal Matrix Multiplication can be used as edge detector as well


Check: http://www.mathworks.com/matlabcentral/fileexchange/22233-demirel-edge-detector
Summary
•We have looked at:
– How to use spatial domain filters.
– What is a mask/kernel?
– How to operate convolution and correlation.
– How to use Laplacian and Gradiant
– How multi-diagonal matrix operator works
•Next time we will talk about image enhancement
in frequency domain.
www.singidunum.ac.rs

Thank you for your attention!

You might also like