Professional Documents
Culture Documents
Fundamentals of Computer Vision (CS 495) Topic: CH 1 Introduction (DIPUM 3ed)
Fundamentals of Computer Vision (CS 495) Topic: CH 1 Introduction (DIPUM 3ed)
495)
Topic : Ch 1 Introduction(DIPUM 3ed)
Dr. S. Hassan Amin
https://sites.google.com/a/nu.edu.pk/sha1/Home
Assist Prof and HOD(Computer Science)
FAST-NU Peshawar
Contents
𝑓 ( 𝑥 , 𝑦 ) =¿
Topic 2.2: Reading Images
1 3
4 6
Indexing Matrices (Cont’d)
>>T=A(1:2,1:3)
T=
1 2 3
4 5 6
To select all rows and a particular column:
>>C3=A(:,3)
ans =
3
6
9
Indexing Matrices (Cont’d)
Following statement sets all elements of a certain
column to a particular value:
>> B(:,2)=0
B=
1 0 3
4 0 6
7 0 9
Topic 2.8.3 : Indexing with a single
Colon
To convert the given matrix into a column vector
>>>> A
A=
1 2 3
4 5 6
7 8 9
>> B=A(:)
B=
1
4
7
2
5
8
3
6
9
Topic 2.8.3 : Indexing with a single
Colon (Cont’d)
To find sum of entire matrix:
>>total=sum(A(:))
Topic 2.8.5 : Linear Indexing
Linear indexing uses a single subscript to access a matrix or array.
>> A
A=
1 2 3
4 5 6
7 8 9
>> A([3 5 9])
ans =
7 5 9
Topic 2.8.7 : Sparse Matrices
When a matrix has a large number of 0s, it is advantageous to
express it in sparse form to reduce storage requirements.
>> A=[2 0 0; 0 3 0; 3 0 0]
A=2 0 0
0 3 0
3 0 0
>> S=sparse(A)
S = (1,1) 2
(3,1) 3
(2,2) 3
Topic 2.9 : Some Important Standard
Arrays
Zeros(M,N)
Ones(M,N)
True(M,N)
False(M,N)
Magic(M)
Eye(M)
Rand(M,N)
Randn(M,N)
Note: You get a square matrix if you use only one argument
in any one of the above.
Topic 2.10 : Introduction to M-Function
Programming
You need to write scripts and functions for any moderately
difficult problem.
M-file allows you to save your scripts and functions and run
these from command prompt
The components of a M-file are:
The function definition line
The H1 line
Help text
The function body
Comments
Topic 2.10 : Introduction to M-Function
Programming (Cont’d)
The function definition line has the form:
function [outputs] = name(inputs)
Example
function [s, p] = sumprod(f, g)
The H1 line immediately follows function definition
%Its a useful function
Topic 2.10 : Introduction to M-Function
Programming (Cont’d)
Example
if expression1
statement1
elseif expression2
statement2
else
statement3
end
Topic 2.10.3 : Flow Control (Cont’d)
Example :
if (ndims(A)>2)
error(‘Messeage 1’)
end;
Topic 2.10.3 : Flow Control (Cont’d)
For statement
Example :
For q = 0:5:100
x=x+5;
End;
Topic 2.10.3 : Flow Control (Cont’d)
While syntax
while expression
statements
end
Example
A =10
B=5
While a
a=a-1;
b=b+1
End;
Topic 2.10.3 : Flow Control (Cont’d)
Break Statement
Break terminates the execution of a for or while loop.
When a break statement is encountered, execution continues with
the next statement outside the loop.
Continue Statement
The continue statement passes the control to the next iteration of
the for or while loop in which it appears, skipping any remaining
statements in the body of the loop.
Topic 2.10.3 : Flow Control (Cont’d)
Switch statement
End