Kotebe University of
Education
Digital Image Processing
and CV
Mulugeta A.(PhD)
1
Chapter Three
Spatial and Frequency
Domain Image
Processing
2
Outline
Spatial and Frequency Domain Image Processing
Image Enhancement
Image enhancement techniques
Spatial domain
Frequency domain
Image Filtering
3
Image Enhancement
Improving the interpretability or perception of
information in images for human viewers
Providing `better' input for other automated image
processing techniques.
The idea behind enhancement techniques is to bring out
details that are obscured or hidden, or simple to
highlight certain features of interest in an image.
Example of image enhancement is when we increase the
contrast of an image because “it looks better.”
Two types of image enhancement techniques
Spatial domain methods
Operate directly on pixels
Frequency domain methods
Operate on the Fourier transform of an image
4
Spatial Domain Methods
Spatial means working in space i.e.(given
image).
we deal with images as it is.
The value of the pixels of the image change with
respect to scene.
It means working with pixel values or raw data.
Let g(x , y) be original image
Where g is gray level values and (x , y) is co-
ordinates
For 8-bit image, g can take values from 0-255
Where 0--- BLACK
255--- WHITE and
Others---shades of GRAY
5
Cont.
In an image with size 256*256 (x,y) can
assume any values from (0,0) to (255,255).
6
Cont.
Applying transform modifies the image
f(x,y)=Tg(x,y)
Where
g(x,y) is original image
T is transformation applied on g(x,y)
f(x,y) is new modified image.
In spatial domain techniques simply T changes.
Spatial domain enhancement is carried out in
two ways
Point processing(gray level transformation)
Neighborhood processing(Histogram processing)
7
Point Processing
Here, we work on single pixel i.e. T is 1x1 operator
New images depends on transform T and original
image.
Some important examples of point processing are
Digital Image Negative
Contrast Stretching
Thresholding
Gray Level slicing
Bit Plane Slicing
Dynamic Range Compressing(log transformation)
Power low Transformation
8
Digital Image Negative
Negative means inverting gray levels.
Particularly suited for enhancing white or gray detail embedded in the
dark regions of an images, especially when the black areas are
dominant in size.
Useful in large applications e.g. X-ray images.
9
Cont.
Digital Negative can be obtained by:
s=255-r (where rmax=255)
When r=0;s=255 and if r=255;s=0
Generally, s=(L-1)-r
Where L=>total number of gray levels(e.g. 256
for 8-bit image)
10
Contrast Stretching
Reason
Poor Illumination
Wrong setting of lens aperture
Idea behind contrast stretching is to make dark porting darker
and bright portion brighter.
Increase dynamic range of the gray levels in the image being
processed
In the below figure, solid line indicates contrast stretching.
Dark portion is being made darker by assigning slope of <1
Bright portion is being made brighter by assigning slope of >1
Any set of slopes cant be generalize for all kind of images
The location points(r1,s1) and (r2,s2) controls the shape of the
transformation function.
Formulation is given below
s = 1.r ; for 0<=r<=a
= m(r-a)+v ; ;for a<=r<=b
= n(r-b)+w; for b<=r<=L-1
11
Cont.
12
Thresholding
Extreme contrast stretching yields Thresholding
In contrast Stretching figure, if 1 and n slope are made
Zero and if m slope is increased then we get
Thresholiding Transformation.
If r1=r2,s1=0 and s2=L-1
Then we get Thresholding function
Expressing goes as under
s=0; if r<=a
s=L-1; if r>a
Where L is number of gray levels.
Note: it is subjective phenomenon.
Thresholded image has maximum contrast as it has only
Black and white gray values.
13
Cont.
14
Gray Level Slicing(Intensity Slicing)
Thresholding splits the image in 2 parts
At times, we need to highlight a specific range of gray
levels.
Eg. X-ray scan, CT scan
It looks similar to thresholding except that we select a band
of gray levels.
Formulation of gray level slicing w/o background(fig.1)
s= L-1 ; for a<=r<=b
= 0 ; otherwise
No background at all.
Sometimes we may need to retain the background
Formulation of gray level slicing with background(fig.2)
S = L-1 ; for a<=r<=b
= r; otherwise
15
Cont.
16
Bit Plane Slicing
Instead of highlighting gray-level ranges, Here, we find the
contribution made by each bit to the final image.
Consider a 256 * 256 image with 256 gray levels i.e. 8 bit
representation for each pixel. E.g. Black is represented as
0000_0000 and white by 1111_1111.
Consider LSB value of each pixel and plot image. Continue till
MSB is reached.
All 8-bit images will be binary.
Observing the images we conclude that
Higher order images contain visually sufficient data.
Lower order bits contain suitable details of image
Hence, PBS can be used in image Compression.
We can transmit only higher order bits and remove lower
order bits
E.g. stegnography
17
Cont.
18
Dynamic Range Compression(Log
Transformation)
At times, dynamic range of image exceeds the capability of
display device
Some pixel values are so large that the other low value pixel
gets obscured.
Eg. Stars in day time are not visible through present due to large intensity
of sun.
Thus dynamic range needs to be compressed.
19
Cont.
Log operator is an excellent compression
function
Thus, Dynamic range compression is achieved
using log operator.
Formulation:
s=C.log(1+|r|)
•Where C-Normalization constant
•r-input intensity
20
Power law transformation
Power law transform can be used to increase
dynamic range of image
The transformation is shown for different
values of ‘μ’ which is also the gamma
correction factor
By changing μ, we obtain the family of
transformation curves.
Nonlinearity encountered during image
capturing, storing and display can be
corrected using gamma correction.
Example
CRT(Cathode Ray Tube)
MR(magnitude resonance)
21
Cont.
22
Histogram Processing
In Statistics, Histogram is a graphical
representation showing a visual impression of
the distribution of data.
An Image Histogram is a type of histogram
that acts as a graphical representation of the
lightness/color distribution in a digital image.
It plots the number of pixels for each value.
The histogram of a digital image with gray
levels in the range [0, L-1] is a discrete
function h(rk) = nk, where rk is the kth gray level
and nk is the number of pixels in the image
having gray level rk.
23
Cont.
It is common practice to normalize a histogram
by dividing each of its values by the total
number of pixels in the image, denoted by n.
Thus, a normalized histogram is given by p(rk) = nk / n,
for k = 0, 1, …, L -1.
Thus, p(rk) gives an estimate of the probability
of occurrence of gray level rk.
Note that the sum of all components of a normalized
histogram is equal to 1.
24
Why Histogram?
Histograms are the basis for numerous spatial
domain processing techniques
Histogram manipulation can be used
effectively for image enhancement
Histograms can be used to provide useful
image statistics
Information derived from histograms are quite
useful in other image processing applications,
such as image compression and segmentation.
25
Examples
26
Assignment-1(10%)
Implement the following concepts using
python
Thresholding
Bit Plane Slicing
Dynamic Range Compressing(log transformation)
Histogram
Histogram Equalization(explain the concept and
implement)
29
Image Restoration
Noise in images is the vital factor which degrades the
quality of the images.
Reducing noise from the satellite images, medical images
etc., is a challenge for the researchers in digital image
processing.
Several approaches are there for noise reduction.
What is image restoration?
Image restoration is the process of recovering the
original image that has been degraded by noise using
a prior knowledge of the degradation phenomenon.
Goal of image restoration
Improve the quality and naturalness of an image in some
predefined sense
Features
A Prior knowledge:
A prior knowledge of the degradation phenomenon is
considered
Objective process:
Modeling the degradation and apply the inverse process to
recover the original image
Noise in an image
Noise in image is any degradation in an image signal,
caused by external disturbances during image
digitalization and/or image transmission.
Source of noise
Image acquisition: sensor heat while capturing an image
e.g., light levels, sensor temperature, etc.
Image digitization: involves sampling, quantization and
compression
e.g. Aliasing effects due to inadequate sampling
Image transmission: Error occurs in image signal while an image
is being sent electronically from one place to another via Satellite,
Wireless, and Network cable.
e.g., lightning or other atmospheric disturbance in
wireless network
Model the degradation and applying the inverse
process in order to recover the original image.
Modeling image degradation & restoration
process
g(x,y)=h(f(x,y))+h(x,y)f(x,y)=h-1(g(x,y))-h(x,i)
Types of Image Noise
Salt and pepper noise
Its also known as impulse noise. this
noise can be caused by sharp & sudden
disturbances in the image signal.
Its appearance is randomly scattered
white or black (or both)
An effective noise reduction method for
this type of noise is a median filter or a
morphological filter.
Gaussian noise
Gaussian noise is statistical noise having
a probability density function (PDF)
equal to that of the normal distribution
Gaussian noise is caused by random
fluctuations in the signal.
its modeled by random values added to
an image.
Types of Image Noise
Speckle noise
It is a granular 'noise' that inherently exists
in and degrades the quality of the image
It is caused by coherent processing of
backscattered signals from multiple
distributed targets.
Speckle noise can be modeled by random
values multiplied by pixel values of an
image.
Periodic noise
Periodic noise is appearance when signal is
subject to a periodic, rather than a random
disturbance.
Periodic noise in an image arises typically
from electrical or electromechanical
interference during image acquisition.
Periodic noise can be reduced significantly
via frequency domain filtering
Properties of image noise
Spatial properties of noise (e.g. additive noise)
Statistical behavior of the gray-level values of pixels
Noise parameters, correlation with the image
Apply spatial domain image restoration techniques
Frequency properties of noise (e.g. image blur)
A random signal having equal intensity at different frequencies
may happen
This is called white noise (a constant Fourier spectrum)
Apply frequency domain image restoration techniques
Filtering in spatial domain
Filtering is a technique for modifying or enhancing an image.
Spatial filtering encompasses a set of digital processing
functions which are used to enhance the appearance of an
image.
Spatial filters are designed to highlight or suppress specific features
in an image based on their spatial frequency.
Spatial frequency refers to the frequency of the variations in
quality that appear in an image.
"Rough" textured areas of an image, where the changes in quality are quick
over a small area, have high spatial frequencies,
while "smooth" areas with little variation in quality over several pixels, have
low spatial frequencies.
Spatial filtering
A common filtering procedure involves moving a 'window' of
a few pixels in dimension (e.g. 3x3, 5x5, etc.) over each pixel in
the image, applying a mathematical calculation using the pixel
values under that window, and replacing the central pixel with
the new value.
The window is moved along in both the row and column dimensions
one pixel at a time and the calculation is repeated until the entire
image has been filtered and a "new" image has been generated.
By varying the calculation performed and the weightings of the
individual pixels in the filter window, filters can be designed to
enhance or suppress different types of features.
Spatial filtering: Neighbors of a Pixel
Filtering is a neighborhood operation, in which the value of
any given pixel in the output image is determined by applying
some algorithm to the values of the pixels in the
neighborhood of the corresponding input pixel.
A pixel's neighborhood is some set of pixels, defined by their
locations relative to that pixel. A pixel p at coordinates (x,y)
has four horizontal and vertical neighbors whose coordinates
are given by: (x+1,y), (x-1, y), (x, y+1), (x,y-1)
(x, y-1)
(x-1, y) P (x,y) (x+1, y)
(x, y+1)
This set of pixels, called the 4-neighbors of p, is denoted by
N4(p). Each pixel is one unit distance from (x,y) and some of
the neighbors of p lie outside the digital image if (x,y) is on
the border of the image.
Spatial filtering: Neighbors of a Pixel
The four diagonal neighbors of p have coordinates:
(x+1, y+1), (x+1, y-1), (x-1, y+1), (x-1, y-1)
(x-1, y-1) (x+1, y-1)
P (x,y)
(x-1, y+1) (x+1, y+1)
and are denoted by ND (p).
These points, together with the 4-neighbors, are
called the 8-neighbors of p, denoted by N8 (p).
(x-1, y-1) (x, y-1) (x+1, y-1)
(x-1, y) P (x,y) (x+1, y)
(x-1, y+1) (x, y+1) (x+1, y+1)
As before, some of the points in ND (p) and N8 (p) fall
outside the image if (x,y) is on the border of the
image.
Low-pass vs High-pass Spatial Filtering
A low-pass filter is designed to emphasize larger,
homogeneous areas of similar tone and reduce the
smaller detail in an image.
Thus, low-pass filters generally serve to smooth
the appearance of an image.
Average and median filters are examples of low-
pass filters.
High-pass filters do the opposite and serve to
sharpen the appearance of fine detail in an image.
One implementation of a high-pass filter first
applies a low-pass filter to an image and then
subtracts the result from the original, leaving
behind only the high spatial frequency
information.
Spatial Noise filtering techniques
Minimum filtering: current pixel will be replaced
by minimum pixel value of its neighboring pixels
Min filter
f ( x, y ) min g ( s, t )
( s ,t )S xy
Maximum filtering: current pixel will be replaced
by maximum pixel value of its neighboring pixels
Max filter
f ( x, y ) max g ( s, t )
( s ,t )S xy
Spatial Noise filtering techniques
Mean filtering: current pixel will be replaced by
average of its neighboring pixel values
Median filtering: current pixel will be replaced by
median or middle pixel value of its neighboring
pixels
New generated filtering: current pixel will be
replaced by arithmetic mean of mid-1, mid, mid+1
of its neighboring pixels
Midpoint filter
f ( x, y ) 1 max g ( s, t ) min g ( s, t )
2 ( s ,t )S xy ( s ,t )S xy
Spatial Filtering: Mean Filtering
• Average (or mean) filtering is a method of
'smoothing‘ images by reducing the amount of
intensity variation between neighboring pixels.
• The average filter works by moving through the
image pixel by pixel, replacing each value with the
average value of neighboring pixels, including itself.
• Let Sx,y represent the set of coordinates in a
rectangle sub-image of size mxn, centered at (x,y),
Mean filtering works:
46
Mean filtering Example
• What is the new image obtained after applying
mean filtering using a 3x3 window
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 10 20 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0
0 20 40 60 60 60 40 20
0 0 0 0 0 0 0 0 0 0
0 30 60 90 90 90 60 30
0 30 50 80 80 90 60 30
0 30 50 80 80 90 60 30
0 20 30 50 50 60 40 20
10 20 30 30 30 30 20 10
10 10 10 0 0 0 0 0
Spatial filtering: Median Filtering
• Median filtering is very widely used in digital image
processing because it preserves edges while removing
noise.
• The median filter is a sliding-window spatial filter.
It replaces the value of the center pixel with the
median of the intensity values in the neighborhood
of that pixel.
Median filtering is a nonlinear operation often used
in image processing to reduce "salt and pepper"
noise because of its appearance as white and black
dots overlaid on an image.
A median filter is more effective than convolution
when the goal is to simultaneously reduce noise and
preserve edges.
• For every pixel, a 3x3 neighborhood with the pixel as
center is considered. In median filtering, the value of
the pixel is replaced by the median of the pixel values
in the 3x3 neighborhood.
Example: The resulting image after applying
median filtering
Exercise 1
What is the new value of the central pixel with value 8
(in the below 3x3 image) after applying median
filtering?
Answers: a) 7 b) 1 c) 3 d)9
Exercise 2
What are the values of the
shaded boxes with yellow colour
after applying median filtering?
Answers:
c)
a) b)
Assignment for next week
Filter or Smooth noise in 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
the following image
0 0 0 100 130 110 120 110 0 0
using: 0 0 0 110 90 100 90 100 0 0
Median filtering
0 0 0 130 100 90 130 110 0 0
Mean or average
0 0 0 120 100 130 110 120 0 0
filtering
0 0 0 90 110 80 120 100 0 0
Include in your report 0 0 0 0 0 0 0 0 0 0
Overview of the two
0 0 0 0 0 0 0 0 0 0
techniques
Show the algorithm to 0 0 0 0 0 0 0 0 0 0
explain how they
work
Depict the resulting
image
Concluding remarks
Reference
Linear Spatial filtering: Correlation
In correlation, the value of an output pixel is also computed as a weighted sum
of neighboring pixels.
The following figure shows how to compute the (4,2) output pixel of the
correlation of A, assuming h is a correlation kernel using the following steps:
Slide the center element of the correlation kernel so that lies on top of the (4,2)
element of A.
Multiply each weight in the correlation kernel by the pixel of A underneath.
Sum the individual products.
The (4,2) output pixel from the correlation is
Linear Spatial filtering: Convolution
In image processing, convolution is used for sharpening, embossing, edge
detection, and more.
This is accomplished by doing a convolution between a
kernel, convolution matrix or mask (which is a small matrix) and
an image.
Convolution is a neighborhood operation in which each output pixel is the
weighted sum of neighboring input pixels. The matrix of weights is called
the convolution kernel, also known as the filter. A convolution kernel is a
correlation kernel that has been rotated 180 degrees.
For example, suppose the image is:
and the correlation kernel is
Spatial filtering using convolution
The following steps will be used to
compute the output pixel at position
(4,2):
Rotate the correlation kernel 180 degrees
about its center element to create a
convolution kernel.
Slide the center element of the
convolution kernel so that it lies on top of
the (2,4) element of A.
Multiply each weight in the rotated
convolution kernel by the pixel of A
underneath.
Sum the individual products from step 3.
Hence the (4,2) output pixel is
Thank you !!!!
60