Matlab NotesGregory D. HagerComputer Vision (CS 461)Matlab Basics• Starting, stopping, help, demos, math, & variables• Matrix definition and indexing> > A = [ 1 2 3 ; 4 5 6 ; 7 8 9 ] or1 2 34 5 67 8 9> > A(3,2)> > A(3,:)> > A(3,1:2) = [ 0 0 ]> > A’> > A(2,:) = A(:,1)’> > size(A)Matlab Built-Ins• for! if! while! switch "" execution control• who! whos! clear "" variable listing and removing• save! load #file$ "" saving or restoring a workspace• diary #file$ "" start recording to a file• path! addpath "" display or add to search path• close! close all! clc "" close windows, clear console• double vs. uint% "" data casting functions• zeros&x!y!…' -- creates an all-zero x by y … matrixdiary off ; diary onused for basic memory allocationImages in Matlab (& Functions)Images in Matlab are really matrices. The image toolboxis a special set of functions for representing matrices.Images are either stored as uint (typically 0 to 255) oras doubles (typically ranging from 0 to 1). Take care to normalize images to this range (some functions dothis automatically).Color images are three-dimensional matrices indexed asrow, column, image-bandImages in Matlab (& Functions) Built-in functions:A (imread&#filename$! #type$' "" pull from fileimwrite&A! #filename$! #type$' "" write to fileimagesc&A' "" display imageimshow(A) --- better way to display’tif’’jpg’’bmp’’png’’hdf’’pcx’’xwd’single-quoted stringsTypesImage MatrixMatlab matrix AA(1:10,1:10,:)The large “M”A(200, 50:300, 3)The spam’s locationsize(A)Matlab Built-InsSee the CS153 reference page for more matlab links.• F ( fft)&A' "" Fourier transform: F is A’s frequencies• A ( ifft)&F' "" inverse Fourier: A is F’s image• F) ( fftshift&F' "" places the coordinate system at center• diary #file$ "" start recording to a file• keyboard "" give control back to user until return• double vs. uint% "" data casting functions• zeros&x!y!…' -- creates an all-zero x by y … matrixdiary off ; diary onused for basic memory
View Full Document