Unit 1 SCI
Unit 1 SCI
Common Uses
• Developing Algorithms
• Data Analysis
• Data Visualization
• Numeric Computation
General Features of MATLAB
▪ The operations are designed to be as natural as
possible
▪ Basic data element is an array that does not require
dimensioning
▪ Consists a family of add-on application-specific
solutions called toolboxes
▪ Toolboxes are comprehensive collections of MATLAB
functions (M-files)
– to learn and apply specialized technology like
signal processing, control systems, neural networks,
fuzzy logic, wavelets, simulation, and many others.
Strengths and Weakness
Strengths Weaknesses
• MATLAB may behave as a • MATLAB is not a general purpose
calculator or as a programming programming language such as C,
language. C++, or FORTRAN
• MATLAB is designed for scientific
• MATLAB combine nicely computing, and is not well suitable
calculation and graphic plotting. for other applications
• MATLAB is relatively easy to learn. • MATLAB is an interpreted
• MATLAB is interpreted (not language, slower than a compiled
compiled), errors are easy to fix. language such as C++
• MATLAB is optimized to be • MATLAB commands are specific
for MATLAB usage. Most of them
relatively fast when performing do not have a direct equivalent
matrix operations with other programming language
• MATLAB does have some commands
object-oriented elements.
Competitors:
One of MATLAB’s competitors is Mathematica, the symbolic computation program.
Other competitors: Scilab, GNU Octave and Rlab.
The graphical interface to the MATLAB workspace
Getting started with MATLAB
• Command Window:
In this window, one must type and immediately execute the
statements, as it requires quick prototyping. These statements
cannot be saved. Thus, this is can be used for small, easily
executable programs.
• Editor (Script):
In this window, one can execute larger programs with multiple
statements, and complex functions These can be saved and are
done with the file extension ‘.m ‘
• Workspace:
In this window, the values of the variables that are created in the
course of the program (in the editor) are displayed.
Basic Functions
Writing a MATLAB program
1) Using Command Window:
Only one statement can be typed and executed at a time. It executes the
statement when the enter key is pressed. This is mostly used for simple
calculations. Note: ans is a default variable created by MATLAB that stores
the output of the given computation.
2) Using Editor:
Multiple lines of code can be written here and only after pressing the run
button (or F5) will the code be executed. It is always a good practice to write
clc, clear and close all in the beginning of the program. Note: Statements
ending with a semicolon will not be displayed in the command window,
however, their values will be displayed in the workspace.
Any statement followed by % in MATLAB is considered as a comment.
3) Vector Operations:
Operations such as addition, subtraction, multiplication and division can be
done using a single command instead of multiple loops.
SCILAB: The Free Platform for
Numerical Computation
What is SCILAB?
▪ Scilab is an open source scientific software package
which can be used as a programming language.
▪ It can be used for numerical computations; providing a
powerful open computing environment for
engineering and scientific applications.
▪ It is a collection of collection of numerical algorithms
covering many aspects of scientific computing
problems.
▪ Since 1994 it has been distributed freely along with
the
▪ source code via the Internet.
▪ It is currently used in educational and industrial
environments around the world.
History
• Scilab was created in 1990 by researchers from
INRIA (French National Institute for Research in
Computer Science and Control) and École
nationale des ponts et chaussées (ENPC).
• Scilab Consortium was formed in May 2003 to
broaden contributions and promote Scilab as
worldwide reference software in academia and
industry.
• In July 2008, the Scilab Consortium joined the
Digiteo Foundation
Major 3 Components
• Optimization
• Statistics
Getting started with SCILAB
• Using the console in interactive mode
Supports high level programming languages SCILAB software is programmed with C, C++
(C, C++ and Java) and more than 60 and Fortran.
toolboxes
Scripts will be saved with the extension “.m” The file saved is with extension “.sci”
STARTING SCILAB
Using SCILAB as a Calculator
• As an example of a simple calculation, you can just
type the expression to evaluate. For Example, let’s
suppose you want to calculate the expression,
1+2x3. You type it at the prompt (-->) command as
follows.
--> -4/inf
Undefined variable: inf
--> -4/%inf
ans =
0.
Overwriting Variable
Error Messages
• If we enter an expression incorrectly, SCILAB will
return an error message. For Example, in the
following expression, we left out the multiplication
sign ‘*’,
Making Corrections
• To make corrections, we can, of course retype
the expressions. But if the expression is
lengthy, we make more mistakes by typing a
second time.
• A previously typed command can be recalled
with the up-arrow (↑) key. When the
command is displayed at the command
prompt, it can be modified if needed and
executed.
Programming in SCILAB
• A SCILAB script file (Called an M-file) is a text
file that contains one or more MATLAB
commands and, optionally, comments.
• The file is saved with the extension ".sce".
• When the filename (without the extension) is
issued as a command in MATLAB, the file is
opened, read, and the commands are
executed as if input from the keyboard.
For Ex; --> exec Histogram.sce
Image Processing with SCILAB
• There are various applications of image processing, e. g.
detection of surface defects in industrial quality control,
detection of anatomical landmarks in surgery, counting cells in
bio-technology and classification of regions in remote sensing.
Images are generated by optical cameras, ultrasound, x-ray
machines and other imaging devices.
• When processing an image with a computer, it must be digitized
or created in a digital for-mat. There are some basic methods to
distinguish between objects and background and to describe
regions in digital images.
• Scientists, engineers and medical doctors who intend to analyze
images usually know how their images were generated and how
the objects of interest look like. However, these objects must be
described mathematically when they are to be detected
automatically with a computer.
Characteristic Properties of Images
• A 2D digital image consists of a finite number of points aligned as rows and
columns. A point of a digital image is called “pixel”. “Pixel” means “picture
element”. At each pixel there can be a scalar gray value or a vector of color
components or gray values. In Scilab, there are the following types of images:
• Gray value images, also called “gray scale” images or “intensity images”: A gray
value image is a matrix of gray values. In Scilab a gray value image is a 2D array.
A gray value is usually an integer scalar between 0 and 255 or a real number
between zero and one.
• Pseudo color images, also called “indexed images”: Each pixel of a pseudo color
image corresponds to an item in a list of colors. A list of colors is called “color
map”. A color map is a matrix. The rows of this matrix correspond to color
vectors and the columns correspond to color channels.
• Color images: At each pixel of a color image there is a vector of color
components, e. g. red – green – blue. Mathematically a color image can be
described as a triple of matrices. Each matrix corresponds to a color channel. In
Scilab, color images are represented as 3D arrays. The first dimension
corresponds to the rows, the second dimension corresponds to the columns and
the third dimension corresponds to the color channel.
Characteristic Properties of Images
• Logical images, also called “binary images”: A logical image is a
matrix of Boolean values. When a logical image is visualized, false
is displayed in black and true is displayed in white. Logical images
can be generated comparing each pixel of a gray value image to a
threshold. Pixels with gray values at least as high as the threshold
are mapped to true whereas pixels with gray values lower than the
threshold get mapped to false.
• The whole image is very bright so there are a lot of pixels with gray
levels >= 200.
• There are few pixels with a gray value lower than 100. The two
peaks in the range between 0 and 255 correspond to the white tea
cup segments and the background.
• The low peaks between 100 and 150 correspond to the
comparatively dark blue and red areas.
AFFINE Transformation
Image Rotation:
• Performing image rotation is straight forward with
IPCV, as the function “imrotate” was implemented for
the ease of use
First, read the image from the demo folder.
–> S = imread(fullpath(getIPCVpath()+
“/images/lena.png”));
–> imshow(S);
Next, rotate the image.
–> S2 = imrotate(S,45);
–> imshow(S2);
AFFINE Transformation
Image Scaling:
• Image scaling with Affine Transform is
equivalent with ”imresize” function in IPCV
module, which is much simple to use.
• When scale parameter is specified, the width
and height of the image is resized in the same
scale.