Professional Documents
Culture Documents
Suggested readings
• Chapter 2
David A. Forsyth and Jean Ponce, “Computer Vision A Modern Approach”, 2nd
edition, Prentice Hall, Inc., 2003.
Acknowledgements Images
• Dr George Stockman
Professor Emeritus, Michigan State University
• Dr Mubarak Shah
Professor, University of Central Florida
Binary Gray Scale Color
• The Robotics Institute
Carnegie Mellon University
1
11/14/2018
Y
Row 1 1 1 1 10 5 9
1
X
0: Black Row q 100
1: White 0 0 0 0 0
then pixel = 1
else pixel = 0
clc; clear all; close all clc; clear all; close all
sign = imread('StopSign.jpg','jpg'); sign = imread('Coins.jpg','jpg');
red = (sign(:,:,1)>120) & (sign(:,:,2)<100) & (sign(:,:,3)<80); out = red*200; red = (sign(:,:,1)>80) & (sign(:,:,2)<240) & (sign(:,:,3)<140); out = red*200;
imwrite(out, 'SegStopSign.jpg', 'jpg'); imwrite(out, 'SegCoins.jpg', 'jpg');
subplot(1,2,1); imshow('StopSign.jpg'); title('Stop Sign - Original'); subplot(1,2,1); imshow('Coins.jpg'); title('Coins - Original');
subplot(1,2,2); imshow('SegStopSign.jpg'); title('Stop Sign - Segmented'); subplot(1,2,2); imshow('SegCoins.jpg'); title('Coins - Segmented');
2
11/14/2018
• Light Variations
• Camera Electronics
• Surface Reflectance
• Lens
Iˆ x, y I x, y n x, y
3
11/14/2018
Derivative Examples
df f ( x) f ( x x) y x2 x4
lim x0 f ( x) f x
dx x dy
2x 4x3
dx
ds
v Speed
dt
dv y sin x e x
a Acceleration
cos x (1)e x
dt dy
dx
df f ( x) f ( x x) df
lim x0 f ( x) f ( x) f ( x 1) f ( x) Backward difference
dx x dx
df
f ( x) f ( x 1) f ( x) Forward difference
df f ( x) f ( x 1) dx
f ( x)
dx 1 Take value of f(x) at
present instant and
df
subtract from the f ( x 1) f ( x 1) f ( x) Central difference
previous dx
df
f ( x) f ( x 1) f ( x)
dx
Gradient magnitude f ( x, y) f x2 f y2
Backward difference [-1 1]
Forward difference [1 -1]
fx
Central difference [-1 0 1] Gradient direction tan 1
fy
4
11/14/2018
Averages Correlation
I I In I i
f = image
h = kernel/filter
I 1 2 i 1
n n
• Weighted mean f1 f2 f3 h1 h2 h3
f h f1h1 f 2 h2 f 3h3
n f4 f5 f6 h4 h5 h6 f 4 h4 f5 h5 f 6 h6
w1 I1 w2 I 2 wn I n
wi I i f 7 h7 f8 h8 f9 h9
f7 f8 f9 h7 h8 h9
I i 1
n n
5
11/14/2018
Convolution Convolution
f * h f (k , l )h(i k , j l ) f h f ( x 1, y 1)h(1,1) f ( x, y 1)h(0,1) f ( x 1, y 1)h(1,1)
k l
f ( x 1, y )h(1,0) f ( x, y )h(0,0) f ( x 1, y )h(1,0)
h7 h8 h9 h1 h2 h3 f ( x 1, y 1)h(1,1) f ( x, y 1)h(0,1) f ( x 1, y 1)h(1,1)
f = image X-flip
h4 h5 h6 h4 h5 h6
h = kernel/filter f h
1 1
f h f ( x i, y i)h(i, j )
h1 h2 h3 h7 h8 h9
* x
i 1 j 1
Y-flip If h is symmetric here eg. Gaussian, correlation x
and convolution will have same results
f1 f2 f3 h9 h8 h7
f *h f1h9 f 2 h8 f 3h7 -1,1 0,1 1,1
f
f f*h
h 1 1 1
? ? ? ?
f*h
2 2 2 3 h
1 -1 -1 -1 2 1
2 2 2 3 5 ? ? ?
2 1 3 3 ? ? ? ? 1 -1 -1
1 2 -1 -1 -1 1
2 1 3 3 ? ? ? ?
2 2 1 2 ? ? ? ? 1 2 -1
1 1 1
2 2 1 2 ? ? ? ?
1 3 2 2 ? ? ? ? 1 1 1
Rotate 1 3 2 2 ? ? ? ?
Rotate
1 1 1
Apply
-1 2 1 1 1 1
Apply
-1 2 1
-1 -1 1 2*2 + 1*2 + (-1)*2 + 1*1 = 5
-1 -1 1
f f
1 1 1 1 1 1
f*h f*h
h -1 2 1 h -1 2 1
2 2 2 3 5 4 ? ? 2 2 2 3 5 4 4 ?
1 -1 -1 1 -1 -1
-1 -1 1 -1 -1 1
2 1 3 3 ? ? ? ? 2 1 3 3 ? ? ? ?
1 2 -1 1 2 -1
2 2 1 2 ? ? ? ? 2 2 1 2 ? ? ? ?
1 1 1 1 1 1
1 3 2 2 ? ? ? ? 1 3 2 2 ? ? ? ?
Rotate Rotate
1 1 1 1 1 1
Apply Apply
-1 2 1 -1 2 1
2*2+1*2+(-1)*2+1*1 = 5 2*2+1*2+(-1)*2+1*1 = 5
-1 -1 1 -1*2+2*2+1*2-1*2-1*1+1*3= 4 -1 -1 1 -1*2+2*2+1*2-1*2-1*1+1*3= 4
-1*2+2*2+1*3-1*1-1*3+1*3= 4
6
11/14/2018
f f
1 1 1
f*h f*h
h -1 2 1 h 1 1 1
2 2 2 3 5 4 4 -2 2 2 2 3 5 4 4 -2
1 -1 -1 1 -1 -1
-1 -1 1 -1 2 1
2 1 3 3 ? ? ? ? 2 1 3 3 9 ? ? ?
1 2 -1 1 2 -1
-1 -1 1
2 2 1 2 ? ? ? ? 2 2 1 2 ? ? ? ?
1 1 1 1 1 1
1 3 2 2 ? ? ? ? 1 3 2 2 ? ? ? ?
Rotate Rotate
1 1 1 1 1 1
Apply Apply
-1 2 1 -1 2 1
2*2+1*2+(-1)*2+1*1 = 5 2*2+1*2+(-1)*2+1*1 = 5
-1 -1 1 -1*2+2*2+1*2-1*2-1*1+1*3= 4 -1 -1 1 -1*2+2*2+1*2-1*2-1*1+1*3= 4
-1*2+2*2+1*3-1*1-1*3+1*3= 4 -1*2+2*2+1*3-1*1-1*3+1*3= 4
-1*2+2*3-1*3-1*3 = -2 -1*2+2*3-1*3-1*3 = -2
1*2+1*2+2*2+1*1-1*2+1*2= 9
And so on ……..
• One of the simplest methods is zero-padding • Replication – replace each off-image pixel with the value
from the nearest pixel that is in the image.
7
11/14/2018
0 0 0 0 0 0
* 0 1 0 0 0 1
*
0 0 0 0 0 0
No effect
1 1 1 1 1
1 1 1 1 1 1 1 1
1 1
* 1 1 1 * 1 1 1 1 1
9 25
1 1 1 1 1 1 1 1
1 1 1 1 1
Averaging
8
11/14/2018
2.4
0.3
0
Original Pixel offset Filtered
*
8 8
6
4.8
4 4
0.3
0
Original Pixel offset Filtered
9
11/14/2018
h(x,y) |H(sx,sy)|
g(x,y) |G(sx,sy)|
Does not look anything like what we have seen
Let the low frequencies pass and eliminating the high frequencies. Lets through the high frequencies (the detail), but eliminates the low
Low-pass image FFT of low-pass image frequencies (the overall shape). It acts like an edge enhancer.
High-pass image FFT of high-pass image
10
11/14/2018
Y = filter2(B,X) filters the data in X with the 2-D [FX,FY] = gradient(F) returns the numerical gradient of the
FIR filter in the matrix B matrix F. FX corresponds to dF/dx, FY corresponds to dF/dy
The result, Y, is computed using 2-D correlation and is • mean: Average or mean value
the same size as X
• Example: H=fspecial('gaussian',7,1)
Creates a 7x7 Gaussian filter with variance 1
11