This document provides an introduction and overview of image processing using Matlab. It discusses the basics of Matlab including its environment, syntax, variables, vectors and matrices. It then covers image processing topics such as importing and exporting images, viewing histograms, and applying filters like box filters and linear filters to images. The document is intended to teach the fundamentals of working with images in the Matlab programming language.
2. Agenda
• Introduction to Matlab
• Basics & Examples
• Image processing with Matlab
• Basics & Examples
3. What is Matlab?
• Matlab stand for Matrix Laboratory
• Matlab is high-level language
• perform computationally intensive tasks faster
than with traditional programming languages
such as c++
• The help in Matlab is very good, use it!
• Everything is treated as a matrix
4. The Matlab Environment
• Matlab window components:
• Workspace
• Displays all the defined variables
• Command window
• To execute commands in the Matlab
environment
• File editor window
• Define your functions
5. Matlab Help
• Matlab help is an extremely powerful assistance
to learning Matlab
• Help not only contains the theoretical
background, but also shows demos for
implementation
• Matlab help can be opened by using the HELP
pull-down menu
6. Basics syntax
• Comment : ctrl + / OR %
• Uncomment : ctrl + t
• Semicolon : suppress printing
• Arithmetic operators:
+ addition
- subtraction
* multiplication
^ power
' transpose
left division
/ right division
7. • Variable :
>> 2 * 25 + 6 * 22 + 100 / 2
ans =
232
>> a = 25; b = 22;
>> d = a * b
ans =
550
sqrt
returns the
square root of
each element of
the array X
abs
absolute value for
real numbers
cos cosine function
sin sin function
exp
exponential
function
8. • Who, Whos : current variables in the workspace
• Save : save workspace variables to *.mat file
• Load : load variables from *.mat file
• Clear : clear workspace variables
• Clc : clear command window
• Close : closes the current figure window
9. Vectors and Matrices
• How to build a matrix?
>> a = [1 5 8]
a =
1 5 8
>> a = [ 1 2 3]'
a =
1
2
3
10. >> a = [ 0:2:4 ; 8:1:10; 35:5:45]
a =
0 2 4
8 9 10
35 40 45
>> a = [1:3; 4:6; 7:9]
a =
1 2 3
4 5 6
7 8 9
11. • A particular element of a matrix can be
assigned:
>> a(3,2)
ans = 40
• Place the number 5 in the first row, second
column:
• >> a(3,2) = 29
12. • Operations ad functions that were defined scalars
in the previous section can also be used on
vectors and matrices, For example.
>> a = [ 1 2 3];
>> b = [ 4 5 6];
>> c = a + b
c =
5 7 9
13. • Special matrices:
• zeros(n,m) : n*m matrix of zeros
• ones(n,m) : n*m matrix of ones
• eye(n) : n*n identity matrix
• rand(n) : n*n random matrix
14. Flow Control
• Matlab has five flow control constructs:
1. if statement
2. for loop
3. while loop
4. break statement
15. if
• If statement condition
• The general form of the IF statement is
IF expression
statements
ELSEIF expression
statements
ELSE
statements
END
16. • Example:
s = input(‘Please enter a scalar value =‘);
if s > 1
error(‘Error!’);
else
disp(‘ok’);
end
17. for
• FOR repeats statements a specific number of
times
• The general form of a FOR statement is:
FOR variable = expression
statements
END
18. for i=1:10
x(i) = sin(i * pi / 10);
end;
for i=[ 1, 2, 3, 7]
x(i) = i + 1;
end;
19. while
• WHILE repeats statements an indefinite number
of times
• The general form of a WHILE statement is:
• WHILE expression
• statements
• END
20. t = 1;
while t ~= -1
t = input(' enter ..... ');
end
21. Scripts and Functions
• There are two kinds of M-files:
• scripts, which do not accept input arguments
or return output arguments. They operate on
data in the workspace.
• Functions, which can accept input arguments
and return output arguments. Internal
variables are local to the function.
22. function
function [ output_args ] = functionName( input_args )
%functionName Summary of this function goes here
% Detailed explanation goes here
end
24. Visualization and Graphics
• Plot ( x, y) : plot 1D function
• figure : open a new figure
• hold on, hold off : refreshing
• title(‘figure title) : add title to figure
31. Image Filtering
• Let’s replace each pixel with a weighted average
of its neighborhood.
• The widths are called the filter kernel
• What are the weighs for the average of a 3*3
neighborhood?
111
111
111
“box filter”
32. Image Filtering
I = imread(‘filename.format file’);
h = fspecial(‘unsharp’);
I2 = imfilter(I,h);
imshow(I2);