Professional Documents
Culture Documents
Spatial Filtering
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 1
Background
• Image domains
Spatial domain techniques -operate directly on the
pixels of an image
Transform domain- operate on transform coefficients
Two main categories of spatial processing
Intensity transformation
- operation on single pixel of image
Ex- Contrast manipulation, image thresholding etc.
Spatial Filtering
- operation on a group of neighboring pixels
- Ex- image sharpening
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 2
Chapter 3
Intensity Transformations and Spatial
Filtering
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 3
Basic Intensity Transformation Functions
• Values of pixels
– before processing: r
– after processing: s
• These value are related by an expression of the form
s=T(r)
• Typically, process starts at the top left of the input
image and proceeds pixel by pixel in horizontal scan,
one row at a time
• Either ignore outside neighbors or pad the image with
a border of 0s or some other specified intensity
values
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 4
Intensity Transformations Functions
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 5
Image Negatives
• Negative of an image with intensity levels in the range [0, L-1]
is obtained using the expression
s=L–1–r
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 8
Fourier Spectrum
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 11
Gamma correction
• A variety of devices used for image capture, printing,
and display respond according to a power law.
• The process used to correct these power-law
response phenomena is called Gamma Correction
• CRT device have an intensity-to-voltage response
that is a power function with = 1.8 to 2.5.
• Different monitors / monitor setting require different
gamma correction values
• Current image standards do not contain the value of
gamma with which an image was created
Dr.Basant Kumar
12
Motilal Nehru National Institute of Technology, Allahabad
Gamma correction
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 13
Contrast Enhancement using Power-law
Transformation
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 14
Contrast Enhancement using Power-law
Transformation
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 15
Piecewise-Linear Transformation Functions
• Contrast Stretching: expands the range of intensity
levels in an image so that it spans the full intensity
range
– Points: (r1, s1) , (r2, s2)
if: r1 = s1 and r2 = s2 linear transformation that produces
no changes in the intensity levels
if: r1 = r2 and s1 = 0 and s2 = L -1 the transformation
becomes a thresholding function that creates a binary
image (Fig. 3.10 (d))
intermediate values of (r1, s1) , (r2, s2) produces various
degrees of spread in the intensity levels of the output
image, thus affecting its contrast
Use: (r1, s1) = (rmin, 0) and (r2, s2) = (rmax, L - 1)
(Fig.3.10 (c))
Dr.Basant Kumar
16
Motilal Nehru National Institute of Technology, Allahabad
Contrast Stretching
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 17
Intensity-level Slicing
Highlighting a specific range of intensities in an image
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 19
Bit-Plane Slicing- Example
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 20
Image Reconstruction using Bit-Planes
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 21
Histogram Processing
• In probabilistic methods of image processing, intensity
values are treated as random quantities
• Histogram of a digital image with intensity levels is a
discrete function
h(rk) = nk
where rk: the kth intensity value and nk: number of pixels in
the image with intensity rk
• Normalized histogram
p(rk) = nk / MN , for k = 0, 1, 2, … , L -1
• Sum of all components of a normalized histogram is equal
to 1
• High contrast image covers a wide range of the intensity
scale and pixels distribution is almost uniform
Dr.Basant Kumar
22
Motilal Nehru National Institute of Technology, Allahabad
Image Histogram
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 23
Histogram Equalization
Used to enhance the appearance of an image and to
make certain features more visible
An attempt to equalize the number of pixels with each
particular value
Allocate more gray levels where there are most pixels
and allocate fewer levels where there are few pixels.
Discrete form of the transformation is
( L 1) k
k
sk T (rk ) ( L 1) pr (rj ) nj
j 0 MN j 0
k 0, 1, 2, , L 1
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 24
Histogram Equalization- Example
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 25
Histogram Equalization- Example
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 26
Histogram Matching ( Specification)
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 29
Spatial Filtering
• Correlation
– Function of the displacement of the filter
– Used for matching between images
• Convolution
– Rotate filter by 180
• Padding an with (filter size m n)
– m-1 rows of 0s at the top and bottom and
– n-1 columns 0s at the left and right
• Cropping the result
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 30
Correlation and Convolution of a 2-D filter
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 31
Correlation and Convolution of a 2-D filter
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 32
Spatial Filtering
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 34
Smoothing Spatial Filters
• Box filter
• Weighted average filter
– Giving some pixels more importance (weight) at the
expenses of others
– Basic strategy: an attempt to reduce blurring in the
smoothing process
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 37
Digital Image Processing, 3rd ed.
Gonzalez & Woods
Chapter 3
Intensity Transformations and Spatial Filtering
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 38
Digital Image Processing, 3rd ed.
Gonzalez & Woods
Chapter 3
Intensity Transformations and Spatial Filtering
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 39
Order-Statistics Filters
• Median
– In 3 3 neighborhood is the 5th largest value
– In 5 5 neighborhood is the 13th largest value
• Principal function of median filtering is to
force pixels with distinct intensities to be more
like their neighbors
• Other order-statistics filters
– Max filter: find the brightest points in the image
– Min filter
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 42
Sharpening Spatial Filters
f
f ( x 1) f ( x)
x
2 f
f ( x 1) f ( x 1) 2 f ( x)
x 2
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 45
Sharpening Spatial Filters
• Edges in digital images often are ramp-like transitions in
intensity
- first derivative results in thick edges due to nonzero value
along the ramp
- Second derivative produces double edge one pixel thick
separated by zero
– I n the x-direction
– In the y-direction
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 49
Unsharp Masking and Highboost Filtering
Dr.Basant Kumar
50
Motilal Nehru National Institute of Technology, Allahabad
1-D illustration of Unsharp Masking
Dr.Basant Kumar
51
Motilal Nehru National Institute of Technology, Allahabad
First Order derivative for image sharpening- The Gradient
• First derivatives in image processing are magnitude of the
gradient
• For a function f( x, y), the gradient of f at coordinates ( x, y) is
defined as 2-D column vector
f
g x x
f grad( f )
g y f
y
Dr.Basant Kumar
52
Motilal Nehru National Institute of Technology, Allahabad
Gradient Operators
In some implementations,
it is more suitable to
approximate square root
operation with absolute
values
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 53
Dr.Basant Kumar Motilal Nehru National
54
Institute of Technology, Allahabad
Gradient for Edge Enhancement
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 55
Combining Sharpening Enhancement Methods
Dr.Basant Kumar
56
Motilal Nehru National Institute of Technology, Allahabad
Combining Sharpening Enhancement Methods
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 57
Combining Sharpening Enhancement Methods
Dr.Basant Kumar
Motilal Nehru National Institute of Technology, Allahabad 58