Spatial Domain-Filtering
Spatial Domain-Filtering
1/22/2025 2
Point Operation
❖ Operation deals with pixel intensity values
individually.
❖ The intensity values are altered using particular
transformation techniques as per the requirement.
❖ The transformed output pixel value does not depend
on any of the neighbouring pixel value of the input
Examples:
image.
❑ Image Negative.
❑ Contrast Stretching.
❑ Thresholding.
❑ Brightness Enhancement.
❑ Log Transformation.
❑ Power Law Transformation.
….
Mask Operation
Transfer function
of
a) Negative
b) Log
c) Nth root
d) Identity
DIGITAL IMAGE PROCESSING
e) Nth power 6
f) Inverse log
Image Negative
Small
lesion
1/22/2025 8
Image Negative
Output
screen:
Output
screen:
Matlab code:
end
end
end
subplot(1,2,1),subimage(a),title('Original
Image');
subplot(1,2,2),subimage(b),title('contrast
Image'),xlabel(sprintf('Contrast increased by a
factor of %g in the range 50 to 200',x));
Output
screen:
Output
screen :
Expression goes as
under:
s = 0; if r = a
s = L – 1 ; if r >a
where, L is
number of gray
levels.
DIGITAL IMAGE PROCESSING 23
Thresholding
Output
screen:
Output
screen:
Output
screen:
36
Power Law Transformation
Matlab
% program for image enhancement using power
code: law
A=input('Enter the value of constant A');
x=input('Enter the value of power x');
a=imread('clown.png');
[m,n]=size(a);
for i=1:1:m
for j=1:1:n
b(i,j)=A*(a(i,j)^x);
end
end
subplot(1,2,1),subimage(a),title('Original Image');
subplot(1,2,2),subimage(b),title('Image after
power law
transformation'),xlabel(sprintf('Constant is %g\
nPower is %g',A,x));
DIGITAL IMAGE PROCESSING 37
Power Law Transformation
Output
screen:
1/22/2025 41
Bit-plane Slicing
1/22/2025 42
Bit-plane Slicing
1/22/2025 43
Histogram Processing
► Histogram Equalization
► Histogram Matching
1/22/2025 44
Histogram Processing
1/22/2025 45
1/22/2025 46
Histogram Equalization
► Histogram equalization is a method in image
processing of contrast adjustment using
the image's histogram.
► This method usually increases the global contrast of
many images, especially when the usable data of
the image is represented by close contrast values.
► Through this adjustment, the intensities can be
better distributed on the histogram.
► This allows for areas of lower local contrast to gain a
higher contrast.
► Histogram equalization accomplishes this by
effectively spreading out the most frequent intensity
values.
Weeks 1 & 2 47
Histogram Equalization
Weeks 1 & 2 48
Histogram Equalization
1/22/2025 49
Histogram Equalization
1/22/2025 50
Histogram Equalization
1/22/2025 51
Histogram Equalization
1/22/2025 52
Example
1/22/2025 53
Example
1/22/2025 54
Histogram Equalization
1/22/2025 55
Example: Histogram Equalization
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN
= 4096) has the intensity distribution shown in following
table.
Get the histogram equalization transformation function and
give the ps(sk) for each sk.
1/22/2025 56
Example: Histogram Equalization
1/22/2025 57
Example: Histogram Equalization
1/22/2025 58
1/22/2025 59
1/22/2025 60
Question
Is histogram equalization always
good?
No
1/22/2025 61
Histogram Matching
Histogram matching (histogram
specification)
— generate a processed image that has a specified
histogram
1/22/2025 62
Histogram Matching
1/22/2025 63
Histogram Matching: Procedure
► Obtain pr(r) from the input image and then obtain the
values of s
► Mapping from s to z
1/22/2025 64
Histogram Matching: Example
1/22/2025 65
Histogram Matching: Example
1/22/2025 66
Histogram Matching: Discrete Cases
► Obtain pr(rj) from the input image and then obtain the
values of sk, round the value to the integer range [0, L-1].
► Mapping from sk to zq
1/22/2025 67
Example: Histogram Matching
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN
= 4096) has the intensity distribution shown in the following
table (on the left). Get the histogram transformation function
and make the output image with the specified histogram,
listed in the table on the right.
1/22/2025 68
Example: Histogram Matching
1/22/2025 69
Example: Histogram Matching
1/22/2025 70
Example: Histogram Matching
s0 s1
s2 s3
s4 s5 s6 s7
1/22/2025 71
Example: Histogram Matching
1/22/2025 72
Example: Histogram Matching
1/22/2025 73
Example: Histogram Matching
1/22/2025 74
Example: Histogram Matching
1/22/2025 75
Example: Histogram Matching
1/22/2025 76
Local Histogram Processing
1/22/2025 78
Using Histogram Statistics for Image
Enhancement
Average
Intensity
Varianc
e
1/22/2025 79
Using Histogram Statistics for Image
Enhancement
1/22/2025 80
Using Histogram Statistics for Image
Enhancement: Example
1/22/2025 81
Spatial Filtering
1/22/2025 82
Spatial Filtering
1/22/2025 83
Spatial Correlation
1/22/2025 84
Spatial Convolution
1/22/2025 85
1/22/2025 86
Smoothing Spatial Filters
1/22/2025 87
Spatial Smoothing Linear Filters
1/22/2025 88
Two Smoothing Averaging Filter Masks
1/22/2025 89
Two Smoothing Averaging Filter Masks
A=
3 3 2 3
2 2 7 2
2 3 2 3
2 2 3 3
h=
ones(3,3)/9;
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
1/22/2025 90
I2 = imfilter (A,
h);
A=
3 3 2 3
2 2 7 2
2 3 2 3 1 2 2 2
2 3 3 2
2 2 3 3
1 3 3 2
1 2 2 1
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
1/22/2025 91
1/22/2025 92
Smoothing Filters: Averaging
(cont’d)
► Mask size determines the degree of smoothing
(loss of detail).
origin 3x3 5x5 7x7
al
15x15 25x25
Smoothing Filters: Averaging
(cont’d)
Example: extract largest, brightest objects
15 x 15 image
averaging thresholding
Example: Gross Representation of Objects
1/22/2025 95
Order-statistic (Nonlinear) Filters
— Nonlinear
1/22/2025 96
Smoothing Filters: Median Filtering
(cont’d)
►Replace each pixel by the median
in a neighborhood around the
pixel.
Example: Use of Median Filtering for Noise
Reduction
1/22/2025 98
Sharpening Spatial Filters
► Foundation
► Laplacian Operator
1/22/2025 99
Sharpening Spatial Filters: Foundation
1/22/2025 100
1/22/2025 101
Sharpening Spatial Filters: Laplace Operator
1/22/2025 102
Sharpening Spatial Filters: Laplace Operator
1/22/2025 103
Sharpening Spatial Filters: Laplace Operator
1/22/2025 104
1/22/2025 105
Unsharp Masking and Highboost Filtering
► Unsharp masking
Sharpen images consists of subtracting an unsharp
(smoothed) version of an image from the original image
e.g., printing and publishing industry
► Steps
1. Blur the original image
2. Subtract the blurred image from the original
3. Add the mask to the original
1/22/2025 106
Unsharp Masking and Highboost Filtering
1/22/2025 107
Unsharp Masking: Demo
1/22/2025 108
Unsharp Masking and Highboost Filtering:
Example
1/22/2025 109
Image Sharpening based on First-Order
Derivatives
Gradient
Image
1/22/2025 110
Image Sharpening based on First-Order
Derivatives
z1 z2 z3
z4 z5 z6
z7 z8 z9
1/22/2025 111
Image Sharpening based on First-Order
Derivatives
z1 z2 z3
z4 z5 z6
z7 z8 z9
1/22/2025 112
Image Sharpening based on First-Order
Derivatives
1/22/2025 113
Example
1/22/2025 114
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by
bringing out
more of the
skeletal detail
1/22/2025 115
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by
bringing out
more of the
skeletal detail
1/22/2025 116
Question: 1
117
118
Question 2
119