DIP Notes Unit-2
DIP Notes Unit-2
UNIT 2
Image Transformation & Filtering
1
TOPICS COVERED:
Intensity transform functions
Histogram processing
Spatial filtering
Fourier transforms and its properties
Frequency domain filters
Colour models
Pseudo colouring
Colour transforms
Basics of Wavelet Transforms
2
Introduction
• To enhance a particular image we have to go
through image processing operations.
3
Spatial domain
• The term spatial domain refers to the image plane
itself, and
• Image processing in this domain are based on
direct manipulation of pixels in an image.
4
Frequency domain
• In this, first we transform an image into the
transform domain (Fourier transform), doing the
processing there, and obtaining the inverse
transform to bring the results back into the spatial
domain.
5
Categories of spatial domain
Two principle categories of spatial processing are:
1. Intensity transformations &
2. Spatial filtering.
• Intensity transformations operate on single pixels
of an image, principally for the purpose of
contrast manipulation and image thresholding.
• Spatial filtering deals with performing operations,
such as image sharpening, by working in a
neighborhood of every pixel in an image.
6
7
Intensity transformation
• It is represented by an expression
S= T(r)
Where, r = input intensity of the pixel before
transformation.
S= output intensity of the pixel after transformation.
T is transform operator.
Applications:
1. Contrast stretching and
2. Image thresholding.
8
1. Contrast stretching
• Contrast stretching is used to enhance the quality of image.
• If the value of r<k, it will be mapped to narrow range of
intensity levels towards the dark region.
• If the value of r>k, it will be mapped to narrow range of values
towards the brighter region.
9
2. Image thresholding
• Thresholding is based on the value of k.
• If r<k, it is assigned with black intensity level.
• If r>k, it is assigned with white intensity level.
Thus, produces binary image.
10
Spatial Filtering
General expression for spatial filtering is given by,
g(x, y) = T[ f(x, y)]
Where, f(x, y) is input image
g(x, y) is output image
T is transform operator
11
Spatial Filtering
• This neighborhood is called as spatial filter or
kernel or template or mask or window.
• If the origin of the neighborhood is at the border
of the image, part of the neighborhood will reside
outside the image will be ignored or to pad the
image with border of 0’s.
12
Spatial Operations
• These are the functions that create new spatial
data from specified input data.
• Spatial operation is performed on the pixels of a
given image.
There are 3 broad categories of spatial operations:
13
Single- pixel operations
• Alter the values of an image pixels based on the
intensity.
• Example : NOT operation
14
Single- pixel operations
• Single point operation on gray scale images.
15
Neighborhood operations
• Let Sxy denote the set of coordinates of a neighborhood
centered on an arbitrary point (x, y) in an image, f.
• Neighborhood processing generates a corresponding pixel at
the same coordinates in an output image, g,
• The value of this pixel is determined by a specified operation
involving the pixels in the input image with coordinates in
Sxy.
16
Neighborhood operations
• Neighbor
• Padding
17
Neighborhood operations
18
Neighborhood operations
19
Geometric spatial transformations
• A spatial transformation of an image is a geometric
transformation of the image coordinate system.
• In a spatial transformation each point (x, y) of image
is mapped to a point (v, w) in a new coordinate
system.
• The transformation of coordinates may be expressed
as
• Where (v, w) are pixel coordinates in the original
image and (x, y) are the corresponding pixel
coordinates in the transformed image.
20
Geometric spatial transformations
• General form of spatial coordinate transformation
given by:
21
Geometric spatial transformations
22
Intensity Transformation Functions
There are three types of transformation functions:
23
Linear Transformation
1.1 Image Negatives- The negative of an image with intensity levels
in the range [0, L-1] is obtained by using the negative
transformation. It is given by, S = L-1-r.
(If r =0, S = L-1 & If r = L-1, S=0)
24
Linear Transformation
1.2 Identity transformation-
• The intensity level of the image after transmission is identical to
that of the original image.
25
Log Transformations
2. Log Transformations- The general form of log transformation
is
S = c log (1+r)
Where, c is a constant, r ≥ 0.
26
• We use this transformation to expand the values of dark
pixels in an image while compressing the higher level
values.
27
Power-Law Transformations
3. Power-Law (Gamma) Transformations: Power law
transformation is given by,
Where C and γ are positive constants.
• We use gamma transformation where we need to expand or
compress darker region.
28
Power-Law Transformations
29
Application of Gamma Transformations
30
Application of Gamma Transformations
(Expansion of darker intensity level)
31
Application of Gamma Transformations
(Compression of brighter intensity level)
32
Piecewise-Linear Transformation Function
Advantage: It is less complex, compared to other
transformation function.
Disadvantage: It requires more user inputs.
Three Piecewise transformation functions are:
1. Contrast stretching
2. Intensity level slicing
3. Bit-plane slicing.
33
Contrast Stretching
• Low-contrast images can result from poor
illumination, lack of dynamic range in the
imaging sensor, or even the wrong setting of a
lens aperture during image acquisition.
• Contrast stretching is a process that expands
the range of intensity levels in an image so that
it spans the full intensity range of the recording
medium or display device.
34
Contrast Stretching
• The locations of points (r1, s1) and (r2, s2) control the shape of the transformation
function.
• r1≤ r2 and s1 ≤ s2 is assumed so that the function is single valued and
monotonically increasing.
• Case 1: If r1 = s1 and r2 = s2, the transformation is a linear function that produces
no changes in intensity levels.
• Case 2: If r1 = r2, s1 = 0 and s2 = L - 1, the transformation becomes a thresholding
function that creates a binary image.
• Case 3: If (r1, s1) = (rmin, 0) and (r2, s2) = (rmax, L - 1), where rmin & rmax denote
the minimum and maximum intensity levels in the image, Contrast stretching is
obtained.
35
Contrast Stretching
36
Intensity level slicing
• It is defined as Highlighting a specific range of
intensities in an image.
• Application include enhancing features such as
masses of water in satellite imagining and enhancing
flaws in X-ray images.
• Two approaches for implementing:
• One approach is to display in one value (say, white)
all the values in the range of interest.
• and in another (say, black) all other intensities.
37
Intensity level slicing
38
Bit-plane slicing
• Highlight the contribution made to total image appearance by
specific bits.(We highlight the entire image appearance).
• Pixels are digital numbers composed of bits.
• Plane 1 contains least significant information of image & plane
8 contains the most significant information of image.
39
Bit-plane slicing
• Fig 1 represent original image, Fig 2 represent bit plane 1
& fig 9 represent bit plane 8.
40
Histogram Processing
• Histogram processing is used to improve the quality of the
image.
• Histogram shows the no. of pixels for each intensity value of
an given image.
• Histogram is a discrete function of any digital image having a
intensity level in [0, L-1].
• It is given by :
41
Uses for Histogram Processing
• Image enhancements
• Image statistics
• Image compression
• Image segmentation
• Simple to calculate in software.
42
Uses for Histogram Processing
• Four basic intensity characteristics and their
corresponding histograms
Dark
Light
Low contrast
High contrast
Histogram commonly viewed in plot as
43
44
Histogram Equalization
• Histogram equalization is used to enhance contrast.
• It is a technique used to obtain flat profile of
histogram by improving the quality of the image.
45
Histogram Equalization
• Example of histogram equalization.
46
Histogram Equalization
47
Histogram Equalization
• Let Pr (r) and Ps (s) be the probability density functions of r and s.
• From the basic of probability theory
48
Histogram Equalization
• Differentiating S= T (r), w. r. to r on both side
49
50
Histogram Equalization
• For discrete values we deal with histogram values and
summations instead of probability density functions
and integrals.
• The probability of occurrence of intensity level in a
digital image is given by
51
Histogram Equalization
• A plot of pr (rk) versus rk is commonly referred to as a
histogram.
• The discrete form of the transformation is
52
Histogram Equalization: Example
• Perform Histogram equalization on 3-bit image (L=8) of size
64 × 64 pixels (MN = 4096) has the intensity distribution
shown in following table.
Original image
53
Histogram Equalization: Example
• The discrete form of the transformation is given by
54
Histogram Equalization: Example
55
Histogram Equalization: Example
56
Histogram Matching
• Histogram equalization determines a transformation
function that seeks to produce an output image.
57
Histogram Matching
58
Histogram Matching
59
Histogram Matching: Procedure
• Obtain pr(r) from the input image and then obtain the values of s
r
s ( L 1) pr ( w)dw
0
• Use the specified PDF and obtain the transformation function G(z)
z
G ( z ) ( L 1) pz (t )dt s
0
• Mapping from s to z
z G 1 ( s )
60
Histogram Matching: Example
Assuming continuous intensity values, suppose that an image
has the intensity PDF
2r
, for 0 r L -1
pr (r ) ( L 1) 2
0,
otherwise
Find the transformation function that will produce an image
whose intensity PDF is
3z 2
, for 0 z ( L -1)
pz ( z ) ( L 1) 3
0,
otherwise
61
Histogram Matching: Example
Find the histogram equalization transformation for the input image
r r 2w r2
s T (r ) ( L 1) pr ( w)dw ( L 1) dw
0 ( L 1) 2
0
L 1
Find the histogram equalization transformation for the specified
histogram
z z 3t 2 z3
G ( z ) ( L 1) pz (t )dt ( L 1) dt s
0 0 ( L 1)3 ( L 1) 2
62
Histogram Matching: Example
• For discrete intensity values: The transformation function
for discrete intensity values is given by,
k
( L 1) k
sk T (rk ) ( L 1) pr (rj ) nj
j 0 MN j 0
• Use the specified PDF and obtain the transformation
function G(zq), round the value to the integer range [0, L-1].
q
G ( zq ) ( L 1) pz ( zi ) sk
i 0
• Mapping from sk to zq
1
z q G ( sk )
63
Local Histogram Processing
• In histogram equalization & matching, we
apply transformation function on the entire
image. So, this type of approach is called
Global.
• In local histogram we apply transformation
function on the neighborhood of the pixel.
From pixel to pixel we perform this operation.
64
Local Histogram Processing
65
Using Histogram Statistics for Image Enhancement
66
Histogram Statistics for Image Enhancement
67
Histogram Statistics for Image Enhancement
68
Histogram Statistics : Example
Consider the following 2-bit image of size 5*5:
69
Histogram Statistics : Example
Case 1 : When histogram of image is known
70
Histogram Statistics : Example
Case 2: when histogram of image is not known
71
Spatial Filtering
• Spatial filtering is a tool used in image processing for a
broad spectrum of applications.
• A spatial filter consists of (a) a neighborhood, and (b) a
predefined operation.
• Linear spatial filtering of an image of size M×N with a
filter of size m×n is given by:
72
Spatial Filtering
• Figure shows the mechanics of linear spatial filtering
using a 3×3 neighborhood.
• At any point (x, y) in the image, the response, g(x, y),
of the filter is the sum of products of the filter
coefficients and the image pixels encompassed by the
filter:
73
74
Spatial Correlation & Convolution
• Correlation is the process of moving a filter mask
over the image and computing the sum of products at
each location.
• In convolution the mask or filter is first rotated by
180º.
75
76
77
78
General Expression for Correlation
79
General Expression for Convolution
80
Vector Representation of Linear Filtering
81
• As an example, a general mask 3×3 with
coefficients labeled in fig:
82
Classification of Spatial Filters
SPATIAL
FILTERS
SMOOTHING SHARPENING
FILTER SPATIAL FILTER
LINEAR NON-LINAER
FILTERS FILTERS
84
Smoothing filters – Example
85
Smoothing Linear Filters
• These are also called as averaging filter.
• Linear filter is simply the average of the pixels
contained in the neighborhood of the filter
mask.
• This operation is performed pixel to pixel, by
shifting its origin.
Drawback: It blur the edges of the image, which
is the main feature in an image.
86
Smoothing Linear Filters: Averaging
• Response of the averaging filter
87
Smoothing Linear Filters: Averaging
• Mask size determines degree of smoothing (i.e., loss
of detail).
88
Smoothing Linear Filters: Averaging
89
Smoothing Nonlinear filters
• Order-Statistic (Nonlinear) Filters.
• Replacing the value of the center pixel with the
value determined by the ranking result.
• E.g., median filter, max filter, min filter.
• Median Filter: Replace each pixel by the median
in a neighborhood around the pixel.
• The size of the neighborhood controls the amount
of smoothing.
90
Median filtering
91
Median filtering
• Median filters are popular because for certain types of random
noise, they provide noise reduction capabilities.
• Very effective for removing ‘salt and pepper’ noise (i.e.,
random occurrences of black and white pixels).
92
MAX & MIN filters
• Max Filters: The highest value is assigned to the
center pixel, which is useful for finding the
brightest points in an image.
• The response is given by:
93
Sharpening Spatial Filter
• Used to highlight the transitions in intensity.
• Useful for highlighting fine details.
• Enhance the blurred image and edges.
• It is accomplished by spatial differentiation.
• Applications: Electronics printing, medical
imaging and autonomous guidance in military
systems.
94
Sharpening Filters - Example
Input image Sharpened image
95
Basics of Sharpening
• To understand the concept various derivatives are used.
• For a first order derivative
1. It must be zero in areas of constant intensity.
2. It must be non-zero at the onset of an intensity step or ramp
and
3. It must be non-zero along ramps.
96
• For a second order derivative
1. It must be zero in constant areas.
2. It must be non-zero at the onset and end of intensity
ramp or step.
3. It must be zero along ramps of constant slope.
97
First & Second order derivative
98
Second Order Derivative for Image Sharpening:
(The Laplacian Operator)
99
• The laplacian operator for a function f(x,y) is given as
……….(1)
• In the x-direction
……….(2)
• In the y-direction
……….(3)
100
2D image f(x,y) Filter Mask
101
Image Smoothing & Sharpening using frequency
domain
102
Frequency domain
• In this, first we transform an image into the
transform domain (Fourier transform), doing the
processing there, and obtaining the inverse
transform to bring the results back into the spatial
domain.
103
2-D Discrete Fourier Transform & Its Inverse
104
2-D Discrete Fourier Transform & Its Inverse
105
Properties of 2-D discrete Fourier Transform
106
2. Translation and Rotation
Fourier transform pair satisfies the following translation
property as
107
Using the polar coordinates
108
3. Periodicity
• The Fourier transform & its inverse are
infinitely periodic in the u and v directions, i.e.
109
4. Symmetry Properties
Any real & complex function are the sum of even & odd
parts.
……………1
……………..3
110
5. 2 D convolution
Circular convolution of 2-D DFT is given as
111
Image Smoothing using Frequency Domain filters
112
Image Smoothing using Frequency Domain filters
113
1. Ideal low pass filters:
• A 2-D lowpass filter that passes without attenuation
all frequencies within a circle of radius D0 from the
origin and “cuts off” all frequencies outside this circle
is called an ideal lowpass filter (ILPF).
• The transfer function of ILPF for 2D image in
frequency domain can be represented as:
116
• If n=3 order shows the ideal LPF. Its almost gives the
sharp transition.
• If n=1 order BLPF gives very smooth transition.
117
118
3. Gaussian Low pass Filters
• The transfer function of a Gaussian lowpass filter
(GLPF) for 2-D images in frequency domain is
represented as:
119
120
Image Sharpening Using Frequency Domain Filters
121
Image Sharpening Using Frequency Domain Filters
122
1. Ideal Highpass Filters:
A 2-D ideal highpass filter (IHPF) is defined as
Fig: Perspective plot, image representation, and cross section of a typical ideal highpass Filter.
123
2. Butterworth Highpass Filters:
A 2-D Butterworth highpass filter (BHPF) of order
n and cutoff frequency D0 is defined as
Fig: Perspective plot, image representation, and cross section of a Butterworth highpass Filter.
124
3. Gaussian Highpass Filters:
The transfer function of a Gaussian highpass filter
(GLPF) is represented by:
Fig: Perspective plot, image representation, and cross section of a Gaussian highpass Filter.
125
Color Models
126
RGB Color Model
127
128
129
130
131
CMY Color Model
132
133
134
HSI Color Model
135
136
137
138
139
140
Color Transform
141
Converting colors from RGB to HSI
• Given an image in RGB color format, the H component of
each RGB pixel is obtained using this equation:
142
Converting colors from HSI to RGB
143
Pseudo Coloring
• Pseudo color processing is a technique that maps
each of gray levels of black & white image into
an assigned color.
• Images are grayscale which are assigned color
based on the intensities values.
• This colored image, when displayed can make
the identification of certain features easier for
the observer.
144
Pseudo Image Processing
• Basic concept of the grey level to color
transformation.
• Performing three independent transformations on the
grey level of any input pixel.
145
Wavelet
• Wavelets are the foundation of representing
images in various degrees of resolution. It is
used for image data compression.
• A Wavelet is a waveform of an effectively
limited duration that has an average value of
zero.
146
What is a wavelet?
• A function that “waves” above and below the x-axis
with the following properties:
– Varying frequency
– Limited duration
– Zero average value
• A wavelet is a waveform of effectively limited
duration that has an average value of zero.
147
148
Wavelets vs. Fourier Transform
• In Fourier transform (FT) we represent a signal in
terms of sinusoids
• FT provides a signal which is localized only in the
frequency domain
• It does not give any information of the signal in the
time domain.
• Basis functions of the wavelet transform (WT) are
small waves located in different times.
• Therefore, the WT is localized in both time and
frequency.
149
Wavelet Transform
• Wavelet transform is an efficient tool to
represent an image.
• Wavelet transform allows multi resolution
analysis of an image.
• Aim of transform is to extract relevant
information from image.
• Wavelet transform provides a time frequency
representation of signal.
150
Types of Wavelets
• There are many different wavelets, for
example:
151
Haar Wavelet
• It is bipolar step function. Expression for Haar
wavelet is given by
152
Morelet Wavelet
• The morelet wavelet is obtained by multiplying
the fourier basis with a gaussian window.
153
Daubechies wavelet
• They are a family of orthogonal
wavelets defining a discrete wavelet
transform and characterized by a maximal
number of vanishing moments for some
given support.
• With each wavelet type of this class, there is a
scaling function (called the father wavelet)
which generates an orthogonal multiresolution
analysis.
154
Continuous Wavelet Transform
• The continuous wavelet transform of one
dimensional signal x(t) is given by
155
156
Discrete Wavelet Transform
• It is obtained by filtering the signal through a series
of digital filters at different scales.
• Scaling operation is done by changing the resolution
of signal by sampling.
• DWT can be computed by either convolution or
shifting based procedures.
• DWT uses a finite set of wavelets i.e. defined at a
particular set of scales and locations.
157
Wavelets Applications
• Noise filtering
• Image compression
– Special case: fingerprint compression
• Image fusion
• Recognition
• Image matching and retrieval
158
Assignment Questions
Q1 What do you understand by histogram? Explain its various
specifications also explain histogram equalization and matching.
Q2 Explain various basic intensity transfer function?
Q3 Describe the mechanism of the spatial filtering. Also Explain
how smoothing is done by filters in an image.
Q4 What is Fourier transform? Explain its properties.
Q5 Explain Image Smoothing & Sharpening Using Frequency
Domain Filters.
159