Professional Documents
Culture Documents
Peyman Milanfar
UCSC EE Dept.
Peyman Milanfar
UCSC EE Dept.
Pixel Domain
h(x,y)
g(x,y)
g ( x, y) f ( x, y) h( x, y)
Convolution
Multiplication
Peyman Milanfar
UCSC EE Dept.
Filter Types:
Ideal Low-pass Filters:
1
H ( x , y )
Cutoff Frequency
x2 y2 c
else
Peyman Milanfar
UCSC EE Dept.
Filter Types:
Other Ideal Filters:
Highpass
Bandpass
Lowpass
Peyman Milanfar
UCSC EE Dept.
H ( x , y )
1
x 2 y 2
1
2
2n
Gaussian Filters:
H ( x , y ) e
x 2 y 2
2 2
Peyman Milanfar
UCSC EE Dept.
H ( x , y )
Control parameters
x 2 y 2
1
2
Control parameters
Gaussian Filters:
H ( x , y ) e
2n
x 2 y 2
2 2
Advantage
h( x, y) 2 e 2
2 ( x2 y 2 )
MATLAB
Peyman Milanfar
UCSC EE Dept.
H ( x , y )
c2
1
2 2
y
x
2n
Gaussian Filters:
H ( x , y ) 1 e
x 2 y 2
2 2
h( x, y) ( x, y) 2 e2
2 ( x2 y 2 )
Peyman Milanfar
UCSC EE Dept.
P(x , y ) | H (x , y ) |2
P( ,
x
100%
) d x d y
( x , y )
P( ,
x
) d x d y
( x , y )Full
Peyman Milanfar
UCSC EE Dept.
Homomorphic Filtering:
Recall the Simple Model of (Gray) Image Formation:
f ( x, y) i( x, y)r ( x, y) F (x , y ) I (x , y ) R(x , y )
Typically high freq. content
10
Peyman Milanfar
UCSC EE Dept.
FL ( x , y ) I L ( x , y ) RL ( x , y )
APPLICATION:
Improve (Compress) Dynamic Range
Enhance Contrast
10
11
Peyman Milanfar
UCSC EE Dept.
Go to Retinex
11
12
Peyman Milanfar
UCSC EE Dept.
12
13
Peyman Milanfar
UCSC EE Dept.
Spectra of:
Cont. Signal
Sampling function
Sampled Signal
13
14
Peyman Milanfar
UCSC EE Dept.
Sampling Theorem:
Aliasing
14
15
Peyman Milanfar
UCSC EE Dept.
15
16
Peyman Milanfar
UCSC EE Dept.
16
17
Peyman Milanfar
UCSC EE Dept.
17
18
Peyman Milanfar
UCSC EE Dept.
18
19
Peyman Milanfar
UCSC EE Dept.
Ptolemy Demo
Chalmers Demos
19
Peyman Milanfar
UCSC EE Dept.
Image Interpolation
10
Peyman Milanfar
UCSC EE Dept.
Matlabs
interp1()
function
Peyman Milanfar
UCSC EE Dept.
Matlabs
interp2()
function
11
Peyman Milanfar
UCSC EE Dept.
Original
Zoomed
Projectivetransformed
Rotated
Peyman Milanfar
UCSC EE Dept.
Nearest-neighbor interpolation
The value of the nearest
pixel is copied
Original (sampled) grid
Resampled grid
Copied
12
Peyman Milanfar
UCSC EE Dept.
Bilinear interpolation
The values of the four
nearest samples are
linearly weighted
along both axes
Original (sampled) grid
Resampled grid
Peyman Milanfar
UCSC EE Dept.
13
Peyman Milanfar
UCSC EE Dept.
Sampling
(Picture taken and modified from Lecture 8Filtering in the frequency domain)
Peyman Milanfar
UCSC EE Dept.
Aliasing
14
Peyman Milanfar
UCSC EE Dept.
Sampling theorem
If the original image is sampled at a rate higher than
twice the highest frequency of it (the Nyquist rate),
then replicated spectra do not overlap and it can be
reconstructed without loss.
Peyman Milanfar
UCSC EE Dept.
Sampling
15
Peyman Milanfar
UCSC EE Dept.
Sampling
Reconstruction
Solution
Extract the central spectrum
(This is point-wise multiplication,
hence achieved by linear filtering)
Peyman Milanfar
UCSC EE Dept.
Sinc filter
Extracting the central spectrum is achieved by
multiplying a box in the frequency domain
Its spatial counterpart is called the sinc function
Inverse FT
FT
16
Peyman Milanfar
UCSC EE Dept.
Separable filters
A filter is separable when
Separable filters can be applied by two 1D filtering
operations; first along one axis, then along the other
axis
Peyman Milanfar
UCSC EE Dept.
Reconstruction
17
Peyman Milanfar
UCSC EE Dept.
Interpolation
Infinite
support
Peyman Milanfar
UCSC EE Dept.
18
Peyman Milanfar
UCSC EE Dept.
Sinc
(Lehmann et al., 1999)
Spatial
Frequency
Log Frequency
Peyman Milanfar
UCSC EE Dept.
Nearest-neighbor
(Lehmann et al., 1999)
Spatial
Frequency
Log Frequency
19
Peyman Milanfar
UCSC EE Dept.
Linear
(Lehmann et al., 1999)
Spatial
Frequency
Log Frequency
Peyman Milanfar
UCSC EE Dept.
Cubic
(Lehmann et al., 1999)
Below 1% at the
maximum sidelobe
Spatial
Frequency
Log Frequency
20
Peyman Milanfar
UCSC EE Dept.
Truncated sinc (5 x 5)
(Lehmann et al., 1999)
Overshoot
Peyman Milanfar
UCSC EE Dept.
Truncated sinc (6 x 6)
Overshoot
21
Peyman Milanfar
UCSC EE Dept.
Peyman Milanfar
UCSC EE Dept.
Matlab exercise
Simple zoom (and shrink)
imresize()
Rotation
imrotate()
Transformation of coordinates
To use interp2(), we have to transform coordinates
22
Peyman Milanfar
UCSC EE Dept.
imresize()
%% Read the original image
f = rgb2gray(im2double(imread('lena.tiff')));
%% Zoom
factor = 3;
gzoom_box = imresize(f, factor, 'box');
gzoom_cubic = imresize(f, factor, 'cubic');
figure(1)
subplot(1, 3, 1)
imagesc(gzoom_box); axis off; axis image; colormap(gray(256))
title('Box')
subplot(1, 3, 2)
imagesc(gzoom_cubic); axis off; axis image; colormap(gray(256))
title('Cubic')
subplot(1, 3, 3)
imagesc(gzoom_box - gzoom_cubic); axis off; axis image; colormap(gray(256))
title('Difference')
Peyman Milanfar
UCSC EE Dept.
imrotate()
%% Rotation
angle = 30;
grot_nearest = imrotate(f, angle, 'nearest');
grot_bicubic = imrotate(f, angle, 'bicubic');
figure(2)
subplot(1, 3, 1)
imagesc(grot_nearest); axis off; axis image; colormap(gray(256))
title('Nearest')
subplot(1, 3, 2)
imagesc(grot_bicubic); axis off; axis image; colormap(gray(256))
title('Bicubic')
subplot(1, 3, 3)
imagesc(grot_nearest - grot_bicubic); axis off; axis image; colormap(gray(256))
title('Difference')
23
Peyman Milanfar
UCSC EE Dept.
imtform()
%% Affine transformation
A = [1.25, 0.35, 0;
0.20, 0.80, 0;
0.00, 0.00, 1];
tform = maketform('affine', A);
gtform_nearest = imtransform(f, tform, 'nearest');
gtform_bicubic = imtransform(f, tform, 'bicubic');
figure(3)
subplot(1, 3, 1)
imagesc(gtform_nearest); axis off; axis image; colormap(gray(256))
title('Nearest')
subplot(1, 3, 2)
imagesc(gtform_bicubic); axis off; axis image; colormap(gray(256))
title('Bicubic')
subplot(1, 3, 3)
imagesc(gtform_nearest - gtform_bicubic); axis off; axis image; colormap(gray(256))
title('Difference')
Peyman Milanfar
UCSC EE Dept.
tformfwd()
%% Use interp2() to interpolation
% We have to have transformed *coordinates* to resample
M = 32;
[x, y] = meshgrid(1:M); % Oriignal grid coordinates
[xg, yg] = tformfwd(tform, x, y); % Transform according to tform
xg = xg - (max(xg(:)) - M)/2;
yg = yg - (max(yg(:)) - M)/2;
figure(4)
scatter(x(:), y(:), 'b')
hold on
scatter(xg(:), yg(:), 'r')
hold off
axis tight
title('Original and resampling points')
24
Peyman Milanfar
UCSC EE Dept.
interp2()
% Do it for image f
M = size(f, 1);
[x, y] = meshgrid(1:M); % Oriignal grid coordinates
[xg, yg] = tformfwd(tform, x, y); % Transform according to tform
xg = xg - (max(xg(:)) - M)/2;
yg = yg - (max(yg(:)) - M)/2;
gp2_nearest = interp2(x, y, f, xg, yg, 'nearest');
gp2_cubic = interp2(x, y, f, xg, yg, 'cubic');
figure(5)
subplot(1, 3, 1)
imagesc(gp2_nearest); axis off; axis image; colormap(gray(256));
title('Nearest')
subplot(1, 3, 2)
imagesc(gp2_cubic); axis off; axis image; colormap(gray(256))
title('Cubic')
subplot(1, 3, 3)
imagesc(gp2_nearest - gp2_cubic); axis off; axis image; colormap(gray(256))
title('Difference')
25