|
framED 9211: Tutorial 1: Introduction to MATLAB
framED9211
Introduction to MATLAB
Contents
- Getting started with MATLAB
- The MATLAB Language
- Starting MATLAB
- The MATLAB Syntax
- Image processing toolbox
Getting started with MATLAB
MATLAB stands for Matrix Laboratory, it is a numerical computing environment and programming language. It was created by The Mathworks. It performs computationally intensive tasks faster than traditional programming languages like C, C++ and Fortran.MATLAB allows the user to integrate the MATLAB m-codes with a variety of applications and languages.
The MATLAB language
The MATLAB language supports matrix and vector operations that are fundamental to most of the scientific and engineering problems including the current problem statement.
MATLAB allows you to develop algorithms and program faster than the traditional programming languages.
This is primarily because MATLAB does not require you to do low level administrative tasks such as declaring variables, specifying data types, allocating memory and defining structures.
One such example is that MATLAB eliminates the need for “for” loops. Thus one line of MATLAB code can replace many lines of C, C++ code.
MATLAB also provides the features of the traditional programming languages like arithmetic operators, flow control, data types, data structures, object oriented programming(OOP) and various debugging features.
Starting MATLAB
While installing the edition that you have, make sure that it also includes the Image Processing Toolbox which is required for our problem statement. There are some small versions of MATLAB which does not contain the Image Processing Toolbox.
After installing MATLAB, you can start it from the start menu by going to Start>Programs>Matlab 7.1>Matlab 7.1. (Here 7.1 is the edition of the MATLAB software you might own)
Here you will see the start-up screen.

The start up screen generally contains three parts, The Command Window, The Workspace and Command History.
The command prompt >> is where you will type the commands. In a way MATLAB can be used as an interactive mathematical shell. You can write lengthier codes in a text file, provided by the MATLAB editor. This code can be written in the form of a script or in the form of a function encapsulating the various MATLAB functions. The editor can also be used in various other forms like cells which will be explained later in this tutorial.
The MATLAB syntax
Variables:
Variables are assigned using the assignment operator ‘=’ , MATLAB is variably typed, means that the variables can be assigned without specifying their type and this type can be changed.
The values assigned to the variables can come from constants, from computation involving the values of other variables or from the output of a function.
The following are examples of inputs that can be given in the MATLAB workspace:
>> x = 3
>> y = ‘matlab’
>> z = pi / 2
You can see that as soon as you press return, the value of the variable will be displayed on the command window as a matrix of the specified dimension. To avoid seeing the variable, you must add a semicolon(;) after the instruction.
>> x = 3;
Vectors / Matrices:
MATLAB provides many convenient ways for creating matrices of various dimensions.
In the MATLAB vernacular, a vector is a one dimensional matrix (1 x N or N x 1), this is referred to in other programming languages as an array.
A matrix in MATLAB terminology refers to a multi dimensional matrix, for instance N x M or N x M x L etc. where N, M & L are greater than 1. In traditional programming languages this is referred to as an array of arrays, or simply as a multidimensional array.
MATLAB provides an easy way to define simple one dimensional matrices using the syntax:
initiator : increment : terminator.
For instance: The input
>> array = 1 : 2 : 9
array =
1 3 5 7 9
This defines a variable named array (or assigns a new value to the existing variable with the name array).
In this case the array starts at the init value 1, and each subsequent value is incremented from the previous value by the increment value (Which in this case is 2).
The array stops once it reaches a value not exceeding the value of the terminator.
Another example is:
>> array = 1 : 4 : 10
array =
1 5 9
Note here that the value of increment can also be left out of the syntax(along with one of the colons), in this case the increment will take a default value of 1.
>> array = 1 : 5
array =
1 2 3 4 5
All the arrays created using this command are row matrices, to create column matrices, you must use the transpose command ( ’ ). An example of the same command is given using the same variable above.
>> array = 1 : 5; % This creates your row matrix%
>> array = array’
array =
1
2
3
4
5
To create matrices with more than one row, you must insert a semicolon (;) after each of the values.
>> array = [1 2; 3 4]
array =
- 2
- 4
Calling C and Fortran Functions:
Introduction to the Image Processing Toolbox
Among the various toolboxes present in the MATLAB library is the Image Processing Toolbox. This toolbox is essential for an event like framED9211 but also for any other basic to advanced Image Processing operations.
The Image Processing Toolbox is a collection of functions that extend the capability of the MATLAB® numeric computing environment. The toolbox supports a wide range of image processing operations, including:
- Geometric operations
- Neighbourhood and block operations
- Linear filtering and filter design
- Transforms
- Image analysis and enhancement
- 'Binary image operations
- Region of interest operations
Many of the toolbox functions are MATLAB M-files, series of MATLAB statements that implement specialized image processing algorithms. You can view the MATLAB code for these functions using the statement:
type function_name
You can extend the capabilities of the Image Processing Toolbox by writing your own M-files
Image Types in the Toolbox
The Image Processing Toolbox supports four basic types of images:
- Indexed Images
- Intensity Images
- Binary Images
- RGB Images
Detailed information on each type of images is available easily in matlab help and other online sources. The images we use are RGB images.
Converting Image Types
For certain operations, it is helpful to convert an image to a different image type. For example, if you want to filter a color image that is stored as an indexed image, you should first convert it to RGB format. When you apply the filter to the RGB image, MATLAB filters the intensity values in the image, as is appropriate. If you attempt to filter the indexed image, MATLAB simply applies the filter to the indices in the indexed image matrix, and the results might not be meaningful. A list of commands that can be used for this purpose is given in the matlab help.
Displaying Images
‘imshow’ and ‘imview’ the commands which can be used for the displaying of images in matlab.Their detailed usage with respect to the different kind of images is explained in detail in matlab help.
Multiframe Image Arrays:
The Image Processing Toolbox provides support to store multiple images in a single array. Each separate image in this case is called a frame. If an array holds multiple frames, it is concatenated along the fourth dimension. Many of the functions in the toolbox operate only on the first three dimensions, to use the four dimensional arrays, you must process each frame individually.
To view the images that are in a multiframe array, you can display each frame individually, display all the frames at once (using the montage function), or convert the array into a movie, using the imovie function.
Zooming in on a Region of an Image:
The zoom command enables you to examine the details of an image, when you zoom in, the figure remains the same, and only a small part of the image is displayed. MATLAB enables zoom by changing the axis limits; it does not change the image data.
Here in this part of our tutorial we tried to introduce the basics of matlab to get you initiated but for the detailed reference towards various functions which you might require and which have been used in other parts of this series of event tutorial you can refer to the matlab help which is very well documented and seek assistance from various other sources online.
- http://www.mathworks.com/products/matlab/demos.html
- http://www.mathworks.com/products/image/
- http://www.mathworks.com/products/neuralnet/
- http://www.mathworks.com/products/matlab/
- http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/f0-8778.html
...and ofcourse there is always RoboWiki and Forum to help you.



