Basics - Bilkent University Computer Engineering Department

Transkript

Basics - Bilkent University Computer Engineering Department
1
Basics
CS 554 – Computer Vision
Pinar Duygulu
Bilkent University
CS554 Computer Vision © Pinar Duygulu
2
Outline
• Image Representation
• Review some basics of linear algebra and
geometrical transformations
– Slides adapted from Octavia Camps, Penn State and
Stefan Roth, Brown University
• Introduction to Matlab
• Handling Images in Matlab
CS554 Computer Vision © Pinar Duygulu
3
Image Representation
• Digital Images are 2D arrays (matrices) of numbers
• Each pixel is a measure of the brightness (intensity of light)
– that falls on an area of an sensor (typically a CCD chip)
CS554 Computer Vision © Pinar Duygulu
4
Image Representation
CS554 Computer Vision © Pinar Duygulu
5
Vectors
Ordered set of numbers
Example: coordinates of point
CS554 Computer Vision © Pinar Duygulu
6
Vectors
CS554 Computer Vision © Pinar Duygulu
7
Vectors
Vector addition:
CS554 Computer Vision © Pinar Duygulu
8
Vectors
Vector subtraction:
CS554 Computer Vision © Pinar Duygulu
9
Vectors
Scalar Product:
CS554 Computer Vision © Pinar Duygulu
10
Vectors
Inner (dot) Product:
CS554 Computer Vision © Pinar Duygulu
11
Vectors
Projection of one point onto the other
Different notations
The shown segment has length <x,y>, if x and y are unit vectors
CS554 Computer Vision © Pinar Duygulu
12
Linear Dependence
CS554 Computer Vision © Pinar Duygulu
13
Basis
CS554 Computer Vision © Pinar Duygulu
14
Bases
CS554 Computer Vision © Pinar Duygulu
15
Bases
Orthonormal basis:
CS554 Computer Vision © Pinar Duygulu
16
Vectors
Vector (cross) product:
Note that vXw is not equal to wXv
CS554 Computer Vision © Pinar Duygulu
17
Vectors
Vector product computation:
CS554 Computer Vision © Pinar Duygulu
18
Matrices
CS554 Computer Vision © Pinar Duygulu
19
Matrices
CS554 Computer Vision © Pinar Duygulu
20
Matrices
CS554 Computer Vision © Pinar Duygulu
21
Matrices
CS554 Computer Vision © Pinar Duygulu
22
Matrices
CS554 Computer Vision © Pinar Duygulu
23
Matrices
For singular matrices determinant is 0
CS554 Computer Vision © Pinar Duygulu
24
Eigenvalues and Eigenvectors
CS554 Computer Vision © Pinar Duygulu
25
Eigenvalues and Eigenvectors
CS554 Computer Vision © Pinar Duygulu
26
Eigendecomposition
CS554 Computer Vision © Pinar Duygulu
27
Singular Value Decomposition (SVD)
CS554 Computer Vision © Pinar Duygulu
28
Singular Value Decomposition
CS554 Computer Vision © Pinar Duygulu
29
Singular Value Decomposition (SVD)
The columns of U are the eigenvectors of
AAT and the (non-zero) singular values of
A are the square roots of the (non-zero)
eigenvalues of AAT
CS554 Computer Vision © Pinar Duygulu
30
Geometrical Transformations
2D Translation:
CS554 Computer Vision © Pinar Duygulu
31
Geometrical Transformations
2D Translation Equation:
CS554 Computer Vision © Pinar Duygulu
32
Geometrical Transformations
2D Translation using matrices:
CS554 Computer Vision © Pinar Duygulu
33
Geometrical Transformations
Homogeneous Coordinates
CS554 Computer Vision © Pinar Duygulu
34
Geometrical Transformations
Back to Cartesian Coordinates
CS554 Computer Vision © Pinar Duygulu
35
Geometrical Transformations
2D Translation using Homogeneous Coordinates
CS554 Computer Vision © Pinar Duygulu
36
Geometrical Transformations
Scaling
CS554 Computer Vision © Pinar Duygulu
37
Geometrical Transformations
Scaling Equation
CS554 Computer Vision © Pinar Duygulu
38
Geometrical Transformations
CS554 Computer Vision © Pinar Duygulu
39
Geometrical Transformations
Scaling & Translating
CS554 Computer Vision © Pinar Duygulu
40
Geometrical Transformations
CS554 Computer Vision © Pinar Duygulu
41
Geometrical Transformations
Rotation
CS554 Computer Vision © Pinar Duygulu
42
Geometrical Transformations
Rotation Equations:
CS554 Computer Vision © Pinar Duygulu
43
Geometrical Transformations
Rotation Equations:
y'
x = r.cosA
y = r.sinA
y
x' = r.cos(A+B) = r.cosA.cosB – r.sinA.sinB
y' = r.sin(A+B) = r.sinA.cosB + r.cosA.sinB
B
A
x'
x
x' = x.cosB – y.sinB
y' = y.cosB + x.sinB
[ x' ] = [cosB -sinB] [x]
[ y' ] [sinB cosB ] [y]
sin ( A + B ) = sin A cos B + cos A sin B
cos ( A + B ) = cos A cos B - sin A sin B
CS554 Computer Vision © Pinar Duygulu
44
Geometrical Transformations
Scaling, Translating & Rotating:
CS554 Computer Vision © Pinar Duygulu
45
Geometrical Transformations
3D Rotation of Points:
CS554 Computer Vision © Pinar Duygulu
46
Geometrical Transformations
3D Translation of Points:
CS554 Computer Vision © Pinar Duygulu
47
Introduction to Matlab
One kind of object – a rectangular numerical matrix
Scalars : 1x1 matrices
Vectors : matrices with only one row or one column
a 3x3 matrix
A = [1 2 3; 4 5 6; 7 8 9]
is equal to
A = [1 2 3
456
7 8 9]
CS554 Computer Vision © Pinar Duygulu
48
Introduction to Matlab
A = [1 2; 3 4]
N=5
v = [1 0 0]
V = [1; 2; 3]
v = v'
v = 1:2:7
v = []
% creates a 2x2 matrix
% a scalar
% a row vector
% a column vector
% transpose of a vector
% [start:stepsize:end] v = [1 3 5 7]
% empty vector
CS554 Computer Vision © Pinar Duygulu
49
Introduction to Matlab
m = zeros(2,3)
v = ones(1,3)
m = eye(3)
v = rand(3,1)
m = zeros(3)
% creates a 2x3 matrix of zeros
% creates a 1x3 matrix (row vector) of ones
% identity matrix
% randomly filled matrix
% 3x3 matrix of zeros
d = diag(a)
% diagonal of matrix a
CS554 Computer Vision © Pinar Duygulu
50
Introduction to Matlab
v = [1 2 3]
v(3)
% access a vector element
m = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
m(1,3) % access a matrix element (row #, column #)
m(2,:) % access a whole matrix row
m(:,1) % access a whole matrix column
m(1,1:3) % access elements 1 through 3 of 1st row
m(2:end, 3)
CS554 Computer Vision © Pinar Duygulu
51
Introduction to Matlab
m = [1 2 3; 4 5 6]
size(m)
% returns the size of a matrix
m1 = zeros(size(m))
a = [1 2 3 4]'
2*a
a/4
b = [5 6 7 8]'
a+b
a–b
a .^2
CS554 Computer Vision © Pinar Duygulu
52
Introduction to Matlab
a = [1 4 6 3]
sum(a)
% sum of vector elements
mean(a)
% mean
var(a)
% variance
std(a)
% standard deviation
max(a)
% maximum
min(a)
% minimum
a = [1 2 3; 4 5 6]
mean(a)
% mean of each column
mean(a,2)
% mean of each row
max(max(a)) % maximum value of the matrix
CS554 Computer Vision © Pinar Duygulu
53
Introduction to Matlab
a = [1 2 3; 4 5 6; 7 8 9]
inv(a) % matrix inverse
eig(a)
% vector of eigenvalues of a
[V, D] = eig(a)
% D:eigenvalues on diagonal
%V :matrix of eigenvectors
[U,S,V] = svd(a) % singular value decomposition of a
% a = U * S * V'
CS554 Computer Vision © Pinar Duygulu
54
Introduction to Matlab
B = zeros(m,n)
for i=1:m
for j=1:n
if A(i,j) > 0
B(i,j) = A(i,j)
end
end
end
B = zeros(m,n)
ind = find(A>0)
B(ind) = A(ind)
CS554 Computer Vision © Pinar Duygulu
55
Introduction to Matlab
x = [0 1 2 3 4]
plot(x, 2*x)
xlabel('x')
ylabel('2*x')
title('dummy')
bar(x)
CS554 Computer Vision © Pinar Duygulu
56
Introduction to Matlab
myfunction.m
function y = myfunction(x)
a = [-2 -1 0 1]
y = a + x;
CS554 Computer Vision © Pinar Duygulu
57
Handling Images in Matlab
I = imread('img.jpg');
imshow(I)
imwrite(I, filename)
CS554 Computer Vision © Pinar Duygulu
% read a jpg image
% shows an image
% writes an image to file
58
Handling Images in Matlab
figure
imagesc(I)
colormap gray;
CS554 Computer Vision © Pinar Duygulu
% display it as gray level image
59
Handling Images in Matlab
size(img)
90 150 3
CS554 Computer Vision © Pinar Duygulu
60
Handling Images in Matlab
CS554 Computer Vision © Pinar Duygulu
61
Handling Images in Matlab
CS554 Computer Vision © Pinar Duygulu
62
Handling Images in Matlab
Histograms
CS554 Computer Vision © Pinar Duygulu
63
Handling Images in Matlab
Histograms
CS554 Computer Vision © Pinar Duygulu

Benzer belgeler

Öğr.No. (Son üç hane) fonksiyon 1 fonksiyon 2 fonksiyon 3 001 disp

Öğr.No. (Son üç hane) fonksiyon 1 fonksiyon 2 fonksiyon 3 001 disp isnan isnumeric isrow isscalar issparse isvector length max min ndims numel size blkdiag diag eye freqspace ind2sub linspace logspace meshgrid ndgrid ones rand randi randn RandStream sub2ind zeros ...

Detaylı

˙Ingilizce – Türkçe Sözlük

˙Ingilizce – Türkçe Sözlük çekirdek çekirdekleme k merkezli en yakın k komşu bilgi saklı yanal kafes katman önder öbekleme yaprak birini dışarıda bırak düzey etki (ilişkilendirme kuralının) olabilirlik doğrusal bağ...

Detaylı