You are on page 1of 59

Spatial Domain Image

Processing

Dr. P. Arulmozhivarman
Associate Processor
School of Electrical Sciences
VIT University
Principal application areas

 Improvement of pictorial information for


human interpretation

 Processing of image data for storage,


transmission, and representation for
autonomous machine perception
Digital Image Processing

Digital Image Characteristics

Spatial Spectral

Gray-level Histogram DFT DCT

Pre-Processing

Enhancement Restoration

Point Processing Masking Filtering Degradation Models Inverse Filtering Wiener Filtering

Compression

Information Theory Lossless Lossy

LZW (gif) Transform-based (jpeg)

Segmentation

Edge Detection

Description

Shape Descriptors Texture Morphology


Features of an image

 Low Frequency Component


Smooth/uniform regions
Approximation component

 High frequency Component


Edges
Detailed component
Image processing

 Low level processing :


primitive operation- enhance quality of
image as suitable for application.
 Mid- level processing :

description of objects for computer


processing and classification.
 High level processing :

making sense of recognized objects


Image processing fundamentals
Example of negative image
Image Enhancement
MRI IMAGING
Image Encryption
Normalized histogram
Histogram Equalization
Image Preprocessing

Enhancement Restoration

• Inverse filtering
Spatial Spectral • Wiener filtering
Domain Domain

Filtering
Point Processing Spatial filtering • fft2/ifft2
•imadjust •filter2 • fftshift
•histeq
 Image restoration attempts to restore images
that have been degraded
 Identify the degradation process and attempt to
reverse it
 Similar to image enhancement, but more objective
Filtering to Remove Noise
We can use spatial filters of different kinds
to remove different kinds of noise
The arithmetic mean filter is a very simple
one and is calculated as follows:
ˆf ( x, y )  1
 g ( s, t )
mn ( s ,t )S xy
 This is implemented as the
 1/ 9  1/ 9  1/ 9 simple smoothing filter
1 
 /9  1/ 9  1/ 9
Blurs the image to remove
noise
 1/ 9  1/ 9  1/ 9
Other Means

 There are different kinds of mean filters all of


which exhibit slightly different behaviour:
 Arithmetic Mean
 Geometric Mean
 Harmonic Mean
 Contraharmonic Mean
Other Means (cont…)

 There are other variants on the mean which


can give different performance
 Geometric Mean:
1
 mn 
fˆ ( x, y )    g ( s, t ) 
( s ,t )S xy 
 Achieves similar smoothing to the arithmetic
mean, but tends to lose less image detail
Other Means (cont…)

Harmonic Mean:
mn
fˆ ( x, y ) 
1

( s ,t )S xy g ( s, t )
Works well for salt noise, but fails for pepper
noise
Also does well for other kinds of noise such as

Gaussian noise
Other Means (cont…)

Contraharmonic Mean:
 g ( s, t )
( s ,t )S xy
Q 1

fˆ ( x, y ) 
 g ( s, t )
( s ,t )S xy
Q

Q is the order of the filter and adjusting its value


changes the filter’s behaviour
Positive values of Q eliminate pepper noise

Negative values of Q eliminate salt noise


Order Statistics Filters

 Spatial filters that are based on ordering the


pixel values that make up the nieghbourhood
operated on by the filter
 Useful spatial filters include
 Median filter
 Max and min filter
 Midpoint filter
 Alpha trimmed mean filter
Median Filter

 Median Filter:
fˆ ( x, y )  mean{g ( s, t )}
( s ,t )S xy
 Excellent at noise removal, without the
smoothing effects that can occur with other
smoothing filters
 Particularly good when salt and pepper noise
is present
Max and Min Filter

 Max Filter:

fˆ ( x, y )  max {g ( s, t )}
( s ,t )S xy
 Min Filter:

fˆ ( x, y)  min {g ( s, t )}
( s ,t )S xy
 Max filter is good for pepper noise and min is
good for salt noise
Midpoint Filter

 Midpoint Filter:
ˆf ( x, y )  1  max {g ( s, t )}  min {g ( s, t )}
2 ( s ,t )S xy ( s ,t )S xy 
 Good for random Gaussian and uniform
noise
Alpha-Trimmed Mean Filter

 Alpha-Trimmed Mean Filter:


1
fˆ ( x, y ) 
mn  d
g
( s ,t )S xy
r ( s, t )

 We can delete the d/2 lowest and d/2 highest


grey levels
 So gr(s, t) represents the remaining mn – d
 pixels
Detection of Discontinuities

 3 basic types of gray-level discontinuities:

Points
Lines
Edges

 Common method of detection: run a mask


through the image.
Filter Mask
Point Detection

 | R | T
T: nonnegative threshold:
9
R  w1 z1  w2 z2  ...  w9 z9   wi zi
i 1

Point Detection

 A point has been detected at the location on


which the mask is centered if: |R|>T

 The gray level of an isolated point will be


quite different from the gray levels of its
neighbors

 measure the weighted differences between the


center point and its neighbors
Line Detection

R1 R2 R3 R4

 If at a certain point |Ri|>|Rj|, this point is


more likely associated with a line in the
direction of mask i.
Edge Detection

 Edge (a set of connected pixels):


 the boundary between two regions with relatively
distinct gray-level properties.
 Note: edge vs. boundary

 Assumption:
 the regions are sufficiently homogeneous, so that
the transition between two regions can be
determined on the basis of gray-level
discontinuities alone.
Image Segmentation
Edge Detection
 Basic Idea:

 A profile is defined perpendicularly to the edge


direction and the results are interpreted.
 The magnitude of the first derivative is used to
detect an edge (if a point is on a ramp)
 The sign of the second derivative can determine
whether an edge pixel is on the dark or light side of
an edge.

 Remarks on second derivative:


 It produces two responses for every edge
 The line that can be formed joining its positive and
negative values crosses zero at the mid point of
the edge (zero-crossing)
Edge Detection

 Computation of a local derivative operator

 A profile is defined perpendicularly to the edge


direction and the results are interpreted.

 The first derivative is obtained by using the


magnitude of the gradient at that point.

 The second derivative is obtained by using the


Laplacian.
Gradient Operators

 f 
Gx   x 
F      f 
G y   
 y 

The gradient vector points in the direction of


maximum rate of change of f at (x,y).
Gradient Operators

Gradient: f  mag (F )  [Gx2  G y2 ]1/ 2


(maximum rate of increase of f(x,y) per unit distance)

f | Gx |  | Gy |

 Gy 
Direction angle of ∇f at (x,y): a( x, y)  tan  
1

 Gx 
Image Segmentation
Image Segmentation
Image Segmentation
Image Segmentation
Image Segmentation
Gradient Operators

 Computation of the gradient of an image:

 Soebel operators provide both a differencing &


a smoothing effect:
Gx  ( z7  2 z8  z9 )  ( z1  2 z 2  z3 )

Gy  ( z3  2 z6  z9 )  ( z1  2 z4  z7 )
Summary: Gradient Operators

Smooth edges due to


blurring (result of sampling)

Positive: leading
Negative: trailing
Zero: in constant gray levels

Positive: from dark side


Negative: from light side
Zero: in constant gray levels
 The magnitude of the first derivative detects
the presence of an edge and the sign of the
second detects whether the edge pixel lies on
the dark or light side of an edge.

 The second derivative has a zero-crossing at


the mid-point of a transition.
Laplacian

 2
f  2
f
  f  2  2
2
(of a 2-D function f(x,y)):
x y

• A 3 x 3 discrete mask based on the above is:

2 f  4 z5  ( z2  z4  z6  z8 )
Laplacian

 The idea:

 Coefficient of center pixel should be positive


 Coefficients of outer pixels should be negative
 Sum of coefficients should be zero
(the Laplacian is a derivative)
Image Segmentation
Laplacian

 The Laplacian is seldom used in practice,


because:

 It is unacceptably sensitive to noise (as second-


order derivative)
 It produces double edges
 It is unable to detect edge direction
Laplacian

 An important use of the Laplacian:

 To find the location of edges using its zero-


crossings property.

 Plus, the Laplacian plays only the role of


detector of whether a pixel is on the dark
or light side of an edge.
Laplacian

 Convolve an image with the Laplacian of a


2D Gaussian function of the form:
 x 2  y 2 
h(x, y)  exp 2 
 2 

where  is the standard deviation.


Laplacian

 The Laplacian of the above Gaussian is:

r 2   2   r 2 
 h   4 exp 2 
2

    2 

where r2 = x2 + y2.


 determines the degree of blurring that occurs.
Image Segmentation
Image Segmentation
Thank you!

You might also like