Docsity

Image Processing with MATLAB, Slides of Matlab skills

Partial preview of the text

Download Image Processing with MATLAB and more Slides Matlab skills in PDF only on Docsity!

MATLAB for Image Processing

CS638-1 TA: Tuo Wang [email protected] Feb 12th, 2010

Outline

  • Introduction to MATLAB
    • Basics & Examples
  • Image Processing with MATLAB
    • Basics & Examples

The MATLAB Environment

  • MATLAB window components: Workspace > Displays all the defined variables Command Window > To execute commands in the MATLAB environment Command History > Displays record of the commands used File Editor Window > Define your functions

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

More about the Workspace

  • who, whos – current variables in the

workspace

  • save – save workspace variables to *.mat

file

  • load – load variables from *.mat file
  • clear – clear workspace variables

- CODE

Matrices in MATLAB

  • Matrix is the main MATLAB data type
  • How to build a matrix?
    • A=[1 2 3; 4 5 6; 7 8 9];
    • Creates matrix A of size 3 x 3
  • Special matrices:
    • zeros(n,m), ones(n,m), eye(n,m), rand(), randn()

Variable Name in Matlab

  • Variable naming rules
    • must be unique in the first 63 characters
    • must begin with a letter
    • may not contain blank spaces or other types of punctuation
    • may contain any combination of letters, digits, and underscores
  • are case-sensitive
  • should not use Matlab keyword
  • Pre-defined variable names
    • pi

Logical Operators

  • ==, <, >, (not equal) ~=, (not) ~
  • find(‘condition’) – Returns indexes

of A’s elements that satisfy the condition

Flow Control

  • MATLAB has five flow control constructs:
    • if statement
    • switch statement
    • for loop
    • while loop
    • break statement

if

  • IF statement condition
    • The general form of the IF statement is IF expression statements ELSEIF expression statements ELSE statements END

switch (cont.)

  • Note:
    • Only the statements between the matching CASE and the next CASE, OTHERWISE, or END are executed
    • Unlike C, the SWITCH statement does not fall through (so BREAKs are unnecessary)

for

  • FOR repeats statements a specific

number of times

  • The general form of a FOR statement is:

FOR variable=expr statements END

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

Functions in MATLAB (cont.)

  • Example:
    • A file called STAT.M: function [mean, stdev]=stat(x) %STAT Interesting statistics. n=length(x); mean=sum(x)/n; stdev=sqrt(sum((x-mean).^2)/n);
    • Defines a new function called STAT that calculates the mean and standard deviation of a vector. Function name and file name should be the SAME!