Introduction to MATLAB (Basics) Reference from: Azernikov Sergei mesergei@tx.technion.ac.il

Similar documents
AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Chapter 2. Point transformation. Look up Table (LUT) Fundamentals of Image processing

Introduction to Matlab

Digital Image Processing

Beginner s Matlab Tutorial

How long is the vector? >> length(x) >> d=size(x) % What are the entries in the matrix d?

2+2 Just type and press enter and the answer comes up ans = 4

Tutorial Program. 1. Basics

Introduction. Chapter 1

Using MATLAB to Measure the Diameter of an Object within an Image

GUI Input and Output. Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University

Financial Econometrics MFE MATLAB Introduction. Kevin Sheppard University of Oxford

MatLab Basics. Now, press return to see what Matlab has stored as your variable x. You should see:

Appendix: Tutorial Introduction to MATLAB

MATLAB Basics MATLAB numbers and numeric formats

Lesson 3 - Processing a Multi-Layer Yield History. Exercise 3-4

MATLAB MANUAL AND INTRODUCTORY TUTORIALS

Scientific Programming in Python

Armstrong Atlantic State University Engineering Studies MATLAB Marina Image Processing Primer


Chapter 1. Introduction MULTIMEDIA SIGNAL PROCESSING 2005 D. BARBA 1

Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:

Basic Concepts in Matlab

Getting to know your TI-83

Periodontology. Digital Art Guidelines JOURNAL OF. Monochrome Combination Halftones (grayscale or color images with text and/or line art)

Visualization of 2D Domains

MassArt Studio Foundation: Visual Language Digital Media Cookbook, Fall 2013

Photoshop- Image Editing

CD-ROM Appendix E: Matlab

Analysis of System Performance IN2072 Chapter M Matlab Tutorial

PREPARING PHOTOS for PRINTING

CS1112 Spring 2014 Project 4. Objectives. 3 Pixelation for Identity Protection. due Thursday, 3/27, at 11pm

2 Matlab Programming, IO, and strings

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering

Nuclear Science and Technology Division (94) Multigroup Cross Section and Cross Section Covariance Data Visualization with Javapeño

Chapter 4: Explore! Decision-Making Controls

How to resize, rotate, and crop images

How Does My TI-84 Do That

Color Histogram Normalization using Matlab and Applications in CBIR. László Csink, Szabolcs Sergyán Budapest Tech SSIP 05, Szeged

Making TIFF and EPS files from Drawing, Word Processing, PowerPoint and Graphing Programs

Signal Processing First Lab 01: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

Tutorial for Tracker and Supporting Software By David Chandler

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Virtual Mouse Using a Webcam

Adobe Illustrator CS5 Part 1: Introduction to Illustrator

A few useful MATLAB functions

Package png. February 20, 2015

MATLAB. Input and Output

Medical Information Management & Mining. You Chen Jan,15, 2013 You.chen@vanderbilt.edu

Introduction to Modern Data Acquisition with LabVIEW and MATLAB. By Matt Hollingsworth

5: Magnitude 6: Convert to Polar 7: Convert to Rectangular

Digital Image Fundamentals. Selim Aksoy Department of Computer Engineering Bilkent University

Simple Programming in MATLAB. Plotting a graph using MATLAB involves three steps:

Files Used in this Tutorial

DigitalMicrograph 3.4 User s Guide

Tutorial 3: Graphics and Exploratory Data Analysis in R Jason Pienaar and Tom Miller

UNIVERSITY OF CALICUT

A System for Capturing High Resolution Images

521493S Computer Graphics. Exercise 2 & course schedule change

Beginning Matlab Exercises

Otis Photo Lab Inkjet Printing Demo

(!' ) "' # "*# "!(!' +,

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

Linear Algebra Review. Vectors

Data exploration with Microsoft Excel: analysing more than one variable

Gerrit Stols

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

Topography of an Origin Project and Workspace

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

MATLAB Programming. Problem 1: Sequential

NIRCal Software data sheet

Introduction to Imagery and Raster Data in ArcGIS

Open-Ended Problem-Solving Projections

Big Data and Scripting. Plotting in R

The Projection Matrix

Machine Learning and Data Mining. Regression Problem. (adapted from) Prof. Alexander Ihler

ANALYTIC HIERARCHY PROCESS (AHP) TUTORIAL

MATLAB Workshop 14 - Plotting Data in MATLAB

Printing to the Poster Printer

Appendix 4 Simulation software for neuronal network models

Object Recognition and Template Matching

Computer Vision. Image acquisition. 25 August Copyright by NHL Hogeschool and Van de Loosdrecht Machine Vision BV All rights reserved

The Image Deblurring Problem

Lab #8: Introduction to ENVI (Environment for Visualizing Images) Image Processing

Adding a New Printer Barcode in SAP ECC 6.0

Instructions for Creating a Poster for Arts and Humanities Research Day Using PowerPoint

Summary: Transformations. Lecture 14 Parameter Estimation Readings T&V Sec Parameter Estimation: Fitting Geometric Models

ABAQUS/CAE Tutorial: Analysis of an Aluminum Bracket

Mini-project in TSRT04: Cell Phone Coverage

Data analysis and visualization topics

Transcription:

Introduction to MATLAB (Basics) Reference from: Azernikov Sergei mesergei@tx.technion.ac.il

MATLAB Basics Where to get help? 1) In MATLAB s prompt type: help, lookfor,helpwin, helpdesk, demos. 2) On the Web: http://www.mathworks.com/support 2

MATLAB s Workspace who,whos - current variables in workspace save - save workspace variables to *.mat file load - load variables from *.mat file clear all - clear workspace variables 3

Matrices in MATLAB Matrix is a main MATLAB s data type How to build a matrix? A = [ 1 2 3; 4 5 6; 7 8 9 ]; Creates matrix A with size 3x3. Special matrices : zeros(n,m), ones(n,m),eye (n,m) 4

Basic Operations on Matrices All the operators in MATLAB defined on matrices : +, -, *, /, ^, sqrt, sin, cos etc. Element wise operators defined with preceding dot :.*,./,.^. size(a) - size vector sum(a) - columns sums vector sum(sum(a)) - all the elements sum 5

Logical Conditions ==, <, >, (not equal)~=,(not)~ find( condition ) - Returns indexes of A s elements that satisfies the condition. 6

Logical Conditions(cont.) Example: >> A = [1 2; 3 4], I = find(a<4) A = 1 2 3 4 I = 1 2 3 7

Flow Control MATLAB has five flow control constructs: if statements switch statements for loops while loops break statements 8

if IF statement condition. The general form of the IF statement is IF expression statements ELSEIF expression statements ELSE statements END 9

if(cont.) Example: if I == J A(I,J) = 2; elseif abs(i-j) == 1 A(I,J) = -1; else A(I,J) = 0; end 10

switch SWITCH - Switch among several cases based on expression. The general form of the SWITCH statement is: SWITCH switch_expr CASE case_expr, statement,..., statement CASE {case_expr1, case_expr2, case_expr3,...} statement,..., statement... OTHERWISE, statement,..., statement END 11

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). 12

for FOR Repeat statements a specific number of times. The general form of a FOR statement is: FOR variable = expr, statement,..., END 13

for (cont.) Example: FOR I = 1:N, FOR J = 1:N, A(I,J) = 1/(I+J-1); END END 14

while WHILE Repeat statements an indefinite number of times. The general form of a WHILE statement is: WHILE expression END statements 15

while (cont.) Example: E = 0*A; F = E + eye(size(e)); N = 1; while norm(e+f-e,1) > 0, E = E + F; F = A*F/N; N = N + 1; end 16

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. 17

Functions in MATLAB FUNCTION Add new function. New functions may be added to MATLAB's vocabulary if they are expressed in terms of other existing functions. 18

Functions in MATLAB (cont.) Example : The existence of a file on disk called STAT.M with: 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. 19

Visualization and Graphics plot(x,y), plot(x,sin(x)) - plot 1-D function figure, figure(k) - open a new figure hold on, hold off - refreshing mesh(x_ax,y_ax,z_mat) - view surface contour(z_mat) - view z as top. map subplot(3,1,2) - locate several plots in figure axis([xmin xmax ymin ymax]) - change axes title( figure title ) - add title to figure 20

Image Proc. with MATLAB (Please refer to Matlab Demo for more details of Image Processing Tool Box)

What Is the Image Processing Toolbox? 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 Neighborhood and block operations Linear filtering and filter design Transforms Image analysis and enhancement Binary image operations Region of interest operations 22

MATLAB Image Types Indexed images : m-by-3 color map Intensity images : [0,1] or uint8 Binary images : {0,1} RGB images : m-by-n-by-3 23

Indexed Images» [x,map] = imread('trees.tif');» imshow(x,map); 24

Intensity Images» image = ind2gray(x,map);» imshow(image); 25

Binary Images» imshow(edge(image)); 26

RGB Images 27

Image Display image - create and display image object imagesc - scale and display as image imshow - display image colorbar - display colorbar getimage- get image data from axes truesize - adjust display size of image zoom - zoom in and zoom out of 2D plot 28

Some Points to Note 2D Image with intensity values: I(row,col) 2D RGB images I(row,col,color) - Color : Red = 1; Green = 2 ; Blue = 3Displaying images figure, imshow(i)displaying pixel position and intensity information pixval on 29Pixel values are accessed as matrix elements.

Points to Note All arithmetic operations performed on matrices may be performed on images After processing, an image matrix can be written to an output image file with the imwrite function - imwrite(i,map, filename, fmt ) Without the map argument, the image data is supposed to be grayscale or RGB. The format fmt needs to support the particular type of image 30

Image Conversion gray2ind - intensity image to index image im2bw - image to binary im2double - image to double precision im2uint8 - image to 8-bit unsigned integers im2uint16 - image to 16-bit unsigned integers ind2gray - indexed image to intensity image mat2gray - matrix to intensity image rgb2gray - RGB image to grayscale rgb2ind - RGB image to indexed image 31

% Working with Images (example) [I,map]=imread('trees.tif'); figure, imshow(i,map) I2=ind2gray(I,map); figure colormap('gray') imagesc(i2,[0 1]) axis('image') I=imread( moon.jpg'); % read a JPEG image into 3D figure imshow(i) rect=getrect; I2=imcrop(I,rect); I2=rgb2gray(I2); imagesc(i2) % read a TIFF image % display it as indexed image % convert it to grayscale % use gray colormap % scale data to use full colormap % for values between 0 and 1 % make displayed aspect ratio %proportional % to image dimensions %array % select rectangle % crop % convert cropped image to grayscale % scale data to use full colormap 32

% between min and max values in I2 colormap('gray') colorbar pixval truesize truesize(2*size(i2)) I3=imresize(I2,0.5,'bil'); I3=imrotate(I2,45,'bil'); I3=double(I2); % math operations imagesc(i3.^2) imagesc(log(i3)) % turn on color bar % display pixel values interactively % display at resolution of one %screen pixel % per image pixel % display at resolution of two %screen pixels % per image pixel % resize by 50% using bilinear % interpolation % rotate 45 degrees and crop to % original size % convert from uint8 to double, to %allow % display squared image (pixel-wise) % display log of image 33

MATLAB Resources on the Internet http://www.mathworks.com/products/demos/# http://www.math.siu.edu/matlab/tutorials.html http://math.ucsd.edu/~driver/21d -s99/matlab-primer.html http://www-cse.ucsd.edu/~sjb/classes/matlab/matlab.intro.html http://www.mit.edu/~pwb/cssm/ http://www.mathworks.com Interesting and very complete tutorials in: http://www.mathworks.com/academia/student_center/tutorials/la unchpad.html http://www.mathworks.com/matlabcentral/fileexchange 34

Getting started with MATLAB http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/learn_matlab.shtml MATLAB tutorial http://www.math.mtu.edu/~msgocken/intro/intro.html http://amath.colorado.edu/scico/tutorials/matlab/ MATLAB helpdesk http://www.mathworks.com/access/helpdesk/help/helpdesk.shtml MATLAB Primer ftp://ftp.eng.auburn.edu/pub/sjreeves/matlab_primer_40.pdf 35