1. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
College of Informatics
Department of Computer Science
ComputerVision and Image Processing (CoSc4113)
ChapterThree: Spatial Domain Image Processing
University of Gondar
2. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Domain Image Processing
Objectives
By the end of this lesson, you will be able to:
Explain the concept and significance of spatial domain image processing
1
2
3
4
Apply basic intensity transformation functions to enhance digital images
Implement spatial filtering techniques for image enhancement
Interpret image histograms to assess image properties
perform histogram processing to improve image contrast and detail
Combine multiple spatial enhancement methods for advanced image
processing
5
6
3. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Processing of Digital Images
Basic Intensity Transformation Functions
Histogram of Images
Histogram Processing
Spatial Filtering
Combining Spatial Enhancement Methods
Contents
1
2
3
4
5
6
Spatial Domain Image Processing
4. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Processing of Digital Images
1
The Term Spatial domain refers to the image plane itself, and image
processing methods in this category are based on direct
manipulation of pixels in an image
Spatial Domain Technique operate directly on the pixel of an image
Two Principal categories of Spatial Processing are Intensity
transformation and Spatial Filtering
Spatial domain process on image can be described as
g(x,y)=T[f(x,y)]
Where f(x,y) is the input image, g(x,y) is the output image, T is
an operator
T operates on the neighbors of (x, y) (a square or rectangular sub-image centered at
(x,y) to yield the output g(x, y).
Spatial Domain Image Processing
5. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Processing of Digital Images Cont’d
1
The operator T can apply to a single image or to a set of images
such as performing the pixel-by-pixel sum of a sequence of
images for noise reduction
The point (x,y) shown is an arbitrary location in the image and
the small region shown containing the point is a neighborhood
of (x,y)
Spatial domain
Spatial Domain Image Processing
6. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Processing of Digital Images Cont’d
1
The process shown in figure illustrates moving the origin of the
neighborhood from pixel to pixel and applying the operator T to
the pixels in the neighborhood to yield the output at the location
Thus, for any specific location (x,y), the value of the output image
g at those coordinates is equal to the result of applying T to the
neighborhood with origin at (x,y) in f.
3 x 3 neighborhood of (x,y)
A 3 x 3 neighborhood about a point (x,y)
in an image in the spatial domain. The
neighborhood is moved from pixel to pixel
in the image to generate an output image
Spatial Domain Image Processing
7. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Processing of Digital Images Cont’d
1
The smallest neighborhood (mask) is of size 1 x 1 (pixel)
Here, T is called intensity transformation function or (mapping,
gray level function)
g(x,y) =T[f(x,y)]
S=T(r)
Where s,r, denote the intensity of g and f at any point (x,y)
S r
Spatial Domain Image Processing
8. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
For example, if T(r) has the form as shown in
figure, the effect of applying the
transformation to every pixel of f to generate
the corresponding pixels in g would be to
produce an image of higher contrast than the
original by darkening the intensity levels
below k and brightening the levels above k
This technique, sometimes called as contrast
stretching, values of r lower than k are
compressed by the transformation function
into a narrow range of s, toward black.
The opposite is true for values of r higher
than k
Spatial Processing of Digital Images Cont’d
1
Spatial Domain Image Processing
9. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Function shown in figure, T(r)
produces a two-level (binary) image.
A mapping of this form is called a
thresholding function.
Approaches whose results depend
only on the intensity at a point
sometimes are called point processing
techniques, as opposed to the
neighborhood processing techniques.
Spatial Processing of Digital Images Cont’d
1
Spatial Domain Image Processing
10. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions
2
Intensity transformations the values of pixels, before and after processing,
will be denoted by r and s, respectively.
Expression of the form s = T(r), is used where T is a transformation that
maps a pixel value r into a pixel value s.
As dealing is in digital quantities, values of a transformation function
typically are stored in a one-dimensional array and the mappings from r to s
are implemented via table lookups.
For an 8-bit environment, a lookup table containing the values of T will have
256 entries.
There are three basic gray level transformation
Linear (Identity and Negative Transformation)
Logarithmic (log and log inverse)
Power – law (nth power and nth root transformations)
Spatial Domain Image Processing
11. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions
2
In Identity transformation, each value of the input image is directly mapped
to each other value of output image. That results in the same input image
and output image
Identity Transformation
Spatial Domain Image Processing
12. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions Cont’d
2
The negative of an image with intensity
levels in the range [0, L - 1] is obtained by
using the negative transformation shown in
figure
The expression is
s=L-1-r
Reversing the intensity levels of an image in
this manner produces the equivalent of a
photographic negative
each value of the input image is subtracted
from the L-1 and mapped onto the output
image
Since the input image of Einstein is an 8bpp
image, so the number of levels in this image
are 256. Putting 256 in the equation, we get
s = 255 – r
Image Negatives:
Spatial Domain Image Processing
13. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions Cont’d
2
Such processing is suited for enhancing white or gray level details embedded in dark
regions of an image, especially when the black areas are dominant in size
a. Original digital mammogram b. Negative image obtained using the negative
transformation
The original image is a digital mammogram showing a small lesion.
In spite of the fact that the visual content is the same in both images, Analysis of
breast tissue in the negative image is much easier.
Image Negatives:
Spatial Domain Image Processing
14. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions Cont’d
2
The general form of the log transformation in
figure is
s=c log(1+r)
where ¢ is a constant, and it is assumed
that r > =0
The shape of the log curve in figure shows
that this transformation maps a narrow range
of low intensity values in the input into a
wider range of output levels
This transformation is used to expand the
value of dark pixels in an image compressing
the higher level-values
Log Transformations:
Spatial Domain Image Processing
15. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions Cont’d
2
The log function compresses the dynamic range of
images with large variations in pixel values.
In Fourier spectrum pixel values have a large dynamic
range
Fourier spectrum with values in the range 0 to 1.5 x106 is
shown in first figure
When these values are scaled linearly for display in an 8-
bit system, the brightest pixels will dominate the display.
The effect of this dominance is relatively small area of
the image is not perceived as black
After applying s = ¢ log (1 + r) with ¢ = 1 to the spectrum
values, then the range of values of the result becomes 0
to 6.2, which is more manageable.
Second figure shows the result of scaling this new range
linearly and displaying the spectrum in the same 8-bit
display.
Log Transformations:
Spatial Domain Image Processing
16. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Basic IntensityTransformation Functions Cont’d
2
Power-law transformations have the basic form S
=c.r y
where ¢ and y are positive constants.
Sometimes above equation is written as S = c(r+) y
for an offset
Plots of s versus r for various values of are shown
in figure
Here, possible transformation curves obtained
simply by varying y. Curves generated with values of
y > 1 have exactly the opposite effect as those
generated with values of y < 1
A variety of devices used for image capture,
printing, and display respond according to a power
law.
The exponent in the power-law equation is referred
to as gamma and the process used to correct these
power-law response phenomena is called gamma
correction
Power-Law (Gamma) Transformations:
Plots of the equation s =
¢.r7 for various values of y
(C = 1 for all cases)
Spatial Domain Image Processing
17. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Histogram of an Image
3
Spatial Domain Image Processing
18. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Histogram of an Image cont’d
3
Spatial Domain Image Processing
19. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Histogram Processing
4
Spatial Domain Image Processing
20. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Histogram Processing cont’d
4
Spatial Domain Image Processing
21. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
22. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
23. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
24. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
25. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
26. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
27. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
28. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
29. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
30. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
31. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
32. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
33. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
34. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
35. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
36. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
37. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
38. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
39. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
40. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
41. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
42. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
43. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
4 Histogram Processing cont’d
Spatial Domain Image Processing
44. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering
5
Remember that types of neighborhood:
intensity transformation: neighborhood of size 1x1
spatial filter (or mask ,kernel, template or window): neighborhood of
larger size , like 3*3 mask
The spatial filter mask is moved from point to point in an
image. At each point (x,y), the response of the filter is
calculated
Origin x
y Image f (x, y)
(x, y)
Neighbourhood
Spatial Domain Image Processing
45. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Neighbourhood Operations
For each pixel in the origin image, the outcome is
written on the same location at the target image.
Origin x
y Image f (x, y)
(x, y)
Neighbourhood
Target
Spatial Domain Image Processing
46. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Simple Neighbourhood Operations
Simple neighbourhood operations example:
Min: Set the pixel value to the minimum in the
neighbourhood
Max: Set the pixel value to the maximum in the
neighbourhood
Spatial Domain Image Processing
47. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
The Spatial Filtering Process
j k l
m n o
p q r
Origin x
y Image f (x, y)
eprocessed = n*e + j*a + k*b +
l*c + m*d + o*f + p*g + q*h +
r*i
Filter (w)
Simple 3*3
Neighbourhood
e 3*3 Filter
a b c
d e f
g h i
Original
Image
Pixels
*
The above is repeated for every pixel in the original image to
generate the filtered image
Spatial Domain Image Processing
48. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters
1.Smoothing Spatial filters [low pass].
for Smoothing / Blurring
2. Sharpening Spatial Filters[high pass].
for Edge Detection / Sharpening
Spatial Domain Image Processing
49. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing ( low pass)
Use: for blurring and noise reduction.
Type of smoothing filters:
1.Standard average
2. weighted average.
3. Median filter
linear
Order statistics
Spatial Domain Image Processing
50. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Smoothing Spatial Filters
One of the simplest spatial filtering operations we can
perform is a smoothing operation
Simply average all of the pixels in a neighbourhood around
a central value
Especially useful
in removing noise
from images
Also useful for
highlighting gross
detail
All weights are equal
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
Simple
averaging
filter
Spatial Domain Image Processing
51. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Smoothing Spatial Filtering
Origin x
y Image f (x, y)
e = 1/9*106 + 1/9*104 + 1/9*100 +
1/9*108 + 1/9*99 + 1/9*98 + 1/9*95 +
1/9*90 + 1/9*85 = 98.3333
Filter
Simple 3*3
Neighbourhood
106
104
99
95
100108
98
90 85
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
3*3 Smoothing
Filter
104 100 108
99 106 98
95 90 85
Original
Image
Pixels
*
The above is repeated for every pixel in the original image to
generate the smoothed image
Spatial Domain Image Processing
52. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing
linear smoothing : averaging kernels
Standard average
Spatial Domain Image Processing
53. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing
Standard and weighted Average- example
130
90
120
110
200
98
94
91
100
99
91
90
90
85
96
82
Standard averaging filter:
(110 +120+90+91+94+98+90+91+99)/9 =883/9 = 98.1
The mask is moved
from point to point in
an image. At each
point (x,y), the
response of the filter
is calculated
Spatial Domain Image Processing
54. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
What happens when the Values of the Kernel Fall
Outside the Image??!
Spatial Domain Image Processing
55. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
First solution :Zero padding,
-ve: black border
Spatial Domain Image Processing
56. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
border padding
Spatial Domain Image Processing
57. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing
Averaging effects: blurring + reducing noise
Original image 3 x 3 averaging
5 x 5 averaging 9 x 9 averaging
15 x 15 averaging 35 x 35 averaging
Notice how detail
begins to disappear
Spatial Domain Image Processing
58. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing
linear smoothing : averaging kernels
weighted average.
Used to reduce blurring more.
Spatial Domain Image Processing
59. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing
Standard and weighted Average- example
130
90
120
110
200
98
94
91
100
99
91
90
90
85
96
82
:Weighted averaging filter:
(110 +2 x 120+90+2 x 91+4 x 94+2 x 98+90+2 x 91+99)/16 =
The mask is moved
from point to point in
an image. At each
point (x,y), the
response of the filter
is calculated
Spatial Domain Image Processing
60. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters: Order-Statistic Filters :
130
90
120
110
200
98
94
91
100
99
95
90
90
85
96
82
Steps:
1. Sort the pixels in ascending order:
90,90, 91, 94, 95, 98, 99, 110, 120
2. replace the original pixel value by the
median :95
95
becomes
These are non-linear spatial filters whose response is based on ordering
(increasing /decreasing) the pixel contained in the area encompassed by the filter
Then replacing the value of the center with the middle value determined by
ranking result
E.g. Median Filter, Max Filter, Min filter
I. Median Filter
Popular with certain random
noise and impulse noise (salt
& paper noise)
They provide excellent noise
reduction
Spatial Domain Image Processing
61. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters : Smoothing
order statistics: Median filter
use : blurring + reduce salt and pepper noise
The original
image with salt
and pepper noise
The smoothed
image using
averaging
The smoothed image
using median
Spatial Domain Image Processing
62. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Smoothing Filters: Median Filtering
(non-linear)
Very effective for removing “salt and pepper” noise).
averaging
median
filtering
Spatial Domain Image Processing
63. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Spatial Filtering cont’d
5
Spatial filters: Order-Statistic Filters :
ii. Max Filter
It used to find the brightest points in an image
Response of a 3 x 3 max filter is given by
R = 𝑀𝑎𝑥 𝑧𝑘 𝐾 = 1, 2, 3, 4, , ,, , 9
E.g. Given a 3×3 neighborhood
Then the center pixel (50) will be replaced with the maximum value, which is 90
iii. Min Filter
Used to find the darkest points in an image
Spatial Domain Image Processing
64. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
Combining Spatial Enhancing Methods
6
Reading Assignment
Spatial Domain Image Processing
65. Getnet T. Email: [email protected] , College of Informatics , University of Gondar, July 2025
End of Spatial Domain Image Processing
Thank You