Praktische Aspekte der Informatik - cg.cs.tu-bs.de fileSVCP Symposium on Visual Computing and...
Transcript of Praktische Aspekte der Informatik - cg.cs.tu-bs.de fileSVCP Symposium on Visual Computing and...
Praktische Aspekte
der InformatikMoritz Mühlhausen
Prof. Marcus Magnor
SVCP
Symposium on Visual Computing and Perception
7./8. June (Exkursionswoche)
Six talks of well known scientists within the field of image-information and visual perception.
Up to 25 students can attend the symposium for free.
Register in our secretariat.
- Email with your name & matriculationnr. to [email protected]
More information:
https://graphics.tu-bs.de/svcp17
MatlabPrototyping and designing new algorithms
Further Reading
Warning!The following slides are meant to give you
a very superficial introduction.
If you want to learn more, have a look at:http://www.mathworks.com/help/matlab/
http://www.cs.jhu.edu/CIRL/class/600.161/class2/shortmatlab.pdf
https://www.tu-braunschweig.de/it/service-interaktiv/software/liste#M
Outline
Introduction
Matrices
Plotting
Programming Language
Introduction
Benefits
• A large and widely used
toolbox of numeric and
image functions.
• A great tool for prototyping
and developing new
algorithms.
• A lot of high-level features.
• You can link C/C++!
Drawbacks
• It can be slow.
• You need a license.
• Untyped variables.
Introduction
Outline
Introduction
Matrices
Plotting
Programming Language
Matrices
• Variables and Data Types will be very familiar to you. char, int8, uint8, … int64, uint64, single, double, …
• Matlab treats all variables as matrices.
Vectors are matrices with only one row/column.
Values are matrices with only one entry.
>> M = [1,2,3; 4,5,6; 7,8,9]
M =
1 2 3
4 5 6
7 8 9
Matrices
>> M = [1,2,3; 4,5,6; 7,8,9]
M =
1 2 3
4 5 6
7 8 9
>> M_sub = M(1:2,:)
M_sub =
1 2 3
4 5 6
Matrices
j:k is the same as [j,j+1,...,k] is empty if j > k
j:i:k is the same as [j,j+i,j+2i, ..,k] is empty if i > 0 and j > k or if i < 0 and j < k.
A(:,j) is the j-th column of A.
A(i,:) is the i-th row of A.
A(:,:) is the equivalent two-dimensional array. For matrices this is A.
A(j:k) is A(j), A(j+1),...,A(k).
A(:,j:k) is A(:,j), A(:,j+1),...,A(:,k).
A(:,:,k) is the k-th page of three-dimensional array A.
A(i,j,k,:) is a vector in a four-dimensional array A.
A(:) is all the elements of A, as a single column.On the left side of an assignment statement, A(:) fills A.
Matrices
X = M’ Transposed matrix M
X = inv(M) Inverse of an 𝑛 × 𝑛 matrix M
X = det(M) Determinant of M
[X,D] = eig(M) Eigenvalues and Eigenvectors of M
[r,c] = size(M) Size of M
[Q,R] = qr(M) QR decomposition of M
Outline
Introduction
Matrices
Plotting
Programming Language
Plotting
• Matlab can also quickly plot your data
>> X = [1,4,6,8];
>> Y = [7,3,5,2];
>> plot(X,Y)
• You can also plot a single vector,Matlab will just use it’s indices
>> V = [6,4,8,2];
>> plot(V)
Plotting
• Bar Charts
>> V = [75 91 105 123.5 131 189];
>> bar(V)
• Scatter Plots
>> X = rand(1,100);
>> Y = rand(1,100);
>> plot(X,Y,'*')
Outline
Introduction
Matrices
Plotting
Programming Language
Programming Language
Conditional
if a == b,
…
elseif a > b
…
else
…
end
For-Loop
for i = 1:8
for j = {1:4,8,15}
…
end
end
While-Loop
while i < N
…
end
Programming Language
You can often avoid simple loops…
for i = 1:10000
x(i) = sin(i);
end
… by doing something like this
n = 1:10000;
x = sin(n);
Programming Language
You can also create reusable scripts and functions
imageDenoiseTest.m
image = imread('padi.png'); % RGB image
redChannel = image(:,:,1); % extract the first channel
redChannel = wiener2(redChannel,[5,5]); % denoising function
disp('Image denoised!');
imshow(redChannel); % show the result
>> imageDenoiseTest
Image denoised!
Programming Language
You can also create reusable scripts and functions
functionTest.m
function [denoisedImage] = functionTest(imageName)
image = imread(imageName); % RGB image
denoisedImage = image(:,:,1); % extract the first channel
denoisedImage = wiener2(denoisedImage,[5,5]); % denoising function
disp('Image denoised!');
end
>> image = functionTest('padi.png')
Image denoised!
>> imshow(image)
Matlab
Introduction
Matrices
Plotting
Programming Language