L-5, 6,7 - (Digital ImageProcessing - Image Enhancement in Spatial Domain)
L-5, 6,7 - (Digital ImageProcessing - Image Enhancement in Spatial Domain)
Established in 1998
Session: 2020-21
Image Negatives
Log Transformations
Power-Law
Transformations
Image Negatives
Function of s = cLog(1+r)
Log Transformations
• As illustrated in figure 3.2 (above), this function maps the intensity values
in image f to new values in g, such that values between low_in and
high_in map to values between low_out and high_out.
• Values below low_in and above high_in are clipped; that is values below
low_in map to low_out, and those above high_in map to high_out.
Function imadjust
• The input image can be of class uint8, uint16, or double, and the output
image has the same class as the input.
f g
Function imadjust
Examples
• Cont. Example1:
g = imcomplement (f);
Function imadjust
Examples
• Example2:
f g
Function imadjust
Examples
• Example3:
f g
Function imadjust
Examples
• Example4:
f g
Logarithmic Transformations
• The shape of logarithmic function curve, is similar to the gamma curve
where gamma < 1, where low values set to 0 and high values set to 1 on
both scales.
• The shape of the gamma curve is variable (because of the change of low
and high values), while the shape of the log function is fixed.
gs = im2uint8 (mat2gray(g));
• Use of mat2gray brings the values to the range [0 1] and im2uint8 brings
them to the range [0 255]
Logarithmic Transformations
• Example:
f g g
s
Contrast-Stretching Transformation
The function shown in the figure below, is called a contrast-stretching
transformation function, because it compresses the input levels lower than m into
a narrow range of dark levels in the output image. Similarly, it compresses the
values above m into a narrow band of light levels in the output. The result is an
image of higher contrast.
The limiting case shown below (b), shows the output of a binary image. This
function is called Thresholding, as mentioned earlier. Thresholding, is a simple tool
that can be used for image segmentation.
Contrast-Stretching Transformation
• The function takes the form of:
• Example1:
>>g = 1 ./ (1+ (100 ./(double(f) + eps)) .^ 20);
>> imshow(f), figure, imshow(g);
Contrast-Stretching Transformation
• Example2:
>> g = 1 ./ (1+ (50 ./(double(f) + eps)) .^ 20);
>> imshow(f), figure, imshow(g);
Contrast-Stretching Transformation
• Example3:
>> g = 1 ./ (1+ (150 ./(double(f) + eps)) .^ 20);
>> imshow(f), figure, imshow(g);
Image Enhancement in
Frequency Domain
Introduction
Background (Fourier Series)
G u , v H u , v F u , v
Basic Steps
1. Multiply pixel f(x,y) of the
input image by (-1)x+y.
2. Compute F(u,v), the DFT
3. G(u,v)=F(u,v)H(u,v)
4. g1(x,y)=F-1{G(u,v)}
5. g(x,y) = g1(x,y)*(-1)x+y
Uses of image filtering
• Noise Reduction
– Low Pass Filter
• Image Recovery
– Wiener Filter
• Edge Detection
– High Pass Filter
The Filtering Operation
• Convolution
– Continuous (Analog)
1 if D(u , v ) D 0
H (u , v )
0 otherwise
• The inverse DFT of H.F is the smoothed image.
D(u,v) is distance
from the origin of
the Fourier
transform, shifted
to the center
Demo
D=15 D=30
D=80 D=230
High Pass Filtering
1 1 1 1
f x sin x sin 3 x sin 5 x sin 7 x sin 9 x ...
3 5 7 9
1-D Continuous
• f(x) is a linear combination of simple periodic
patterns. Spatial frequency (measured in
whole cycle per unit of x)
f ( x) F (u )e i 2xu
du
Simple periodic patterns
Inverse Fourier transform
Weight function for the given frequency
Image co-
F (u ) f ( x ) e i 2xu ordinate
• Where dx
Fourier transform
1
1-D Discrete (con’d)
• In image processing, we deal with a
discrete function.
• Since we only have to obtain a finite
(a)
number of values, we only need a
finite number of functions to do it.
• For example: 1 1 1 1 -1 -1 -1 -1,
which we may take as a discrete
approximation to the square wave (b)
of figure (a). This can be expressed
as the sum of two sine functions, (b)
and (c)
(c)
Definition of 1-D DFT
Suppose f [ f 0 , f1 , f 2 , , f N 1 ]
is a sequence of length N. Define its discrete Fourier transform
F [ F0 , F1 , F2 , , FN 1 ]
N 1
1 xu
where Fu
N
x 0
exp[2 i ] f x
N
We can express this definition as matrix multiplication
F Ff
1 mn
Where F is an NxN matrix defined by Fm , n exp[ 2 i ]
N N
Definition of 1-D DFT
2 i
Given N, we shall define exp[ ]
N
1 mn 1 mn
So that Fm , n Fm ,n exp[ 2 i ]
N N N
F
Example
Suppose f [1, 2,3, 4] so that N=4. Then
2 i
exp[ ]
4
i
exp[ ]
2
cos( ) i sin( )
2 2
i
1 1 1 1 1 1 1 1
1 i (i ) 2 (i )3 1 i 1 i
Then we have F
1 (i ) 2 (i ) 4 (i ) 6
1 1 1 1
1 (i ) (i )6 (i )9 1 i 1 i
3
1 1 1 1 1 10
1 1 i 1 i 2 1 2 2i
F
4 1 1 1 1 3 4 2
F Ff 1 i 1 i 4
2 2i
The Inverse DFT
N 1
xu
Inverse DFT: f x exp 2i Fu
u 0 N
Difference with forward transform:
(1). There is no scaling factor 1/N
(2). The sign inside the exponential function has been changed to positive
Inverse DFT can also be expressed as matrix product
where
1 2 i
w exp
w N
Matlab Functions: fft/ifft
• Example:
» a=[1 2 3 4 5 6 7 8 9]
» b=fft(a)
» ifft(b)
» x = [ 2 3 4 5 6 7 8 1]
» x1 = (-1).^[0:7].*x
x1 = 2 -3 4 -5 6 -7 8 -1
» X=fft(x') » X1=fft(x1')
X = X1 =
36.0000 4.0000
-9.6569 + 4.0000i 1.6569 + 4.0000i
-4.0000 - 4.0000i -4.0000 + 4.0000i
1.6569 - 4.0000i -9.6569 - 4.0000i
4.0000 36.0000
1.6569 + 4.0000i -9.6569 + 4.0000i
-4.0000 + 4.0000i -4.0000 - 4.0000i
-9.6569 - 4.0000i 1.6569 - 4.0000i
y0 y1 y2 y3 y0 y1 y2 y3
y0 y3 y2 y1 y0 y1 y2 y3
Then we expand
p (u ) q (u )(1 u 4 ) 5 16u 34u 2 60u 3 66u 4 68u 5 66u 6 60u 7 61u 8 52u 9 32u 10
Extracting the coefficients of u4,u5,…., u7 we obtain
F(u)
f(x)
THANK YOU!