Intro To Matlab and Image Processing
Intro To Matlab and Image Processing
image processing
Amin Allalou
amin@cb.uu.se
Alternatives to imshow
>>imagesc(I)
>>imtool(I)
>>image(I)
Images and Matrices
• How to build a matrix (or image)?
>> A = [ 1 2 3; 4 5 6; 7 8 9 ];
A= 1 2 3
4 5 6
7 8 9
>> B = zeros(3,3)
B= 0 0 0
0 0 0
0 0 0
>> C = ones(3,3)
C= 1 1 1
1 1 1
1 1 1
for row=1:3
for col=1:3
if row==col
A(row, col)=1;
elseif abs(row-col)==1 A=
A(row, col)=2;
else 1 2 0
2 1 2
A(row, col)=0;
0 2 1
end
end
end
Flow Control
• while, expression, statements, end A=
12 3
Indx=1; 45 6
7 8 9
while A(Indx)<6
A(Indx)=0;
Indx=Indx+1;
end
A=
0 2 3
0 5 6
7 8 9
Working with M-Files
• M-files can be scripts that simply execute a series of MATLAB statements,
or they can be functions that also accept input arguments and produce
output.
• MATLAB functions:
– Are useful for extending the MATLAB language for your application.
– Can accept input arguments and return output arguments.
– Store variables in a workspace internal to the function.
Working with M-Files
• Create a new empty m-file
function B=test(I)
[row col]=size(I)
for r=1:row
for c=1:col
if r==c
A(r, c)=1;
elseif abs(r-c)==1
A(r, c)=2;
else
A(r, c)=0;
end
end
end
B=A;