6.S093: Visual Recognition through Machine Learning Competition

13
6.S093: Visual Recognition through Machine Learning Competition MATLAB tutorial

description

6.S093: Visual Recognition through Machine Learning Competition. MATLAB tutorial. Getting Started. To get MATLAB student version, go to http://ist.mit.edu/matlab/all/student (or google MIT MATLAB) On Athena (athena.dialup.mit.edu), » add matlab » matlab &. MATLAB. Very easy to learn. - PowerPoint PPT Presentation

Transcript of 6.S093: Visual Recognition through Machine Learning Competition

Page 1: 6.S093: Visual Recognition through Machine Learning Competition

6.S093: Visual Recognition through Machine Learning Competition

MATLAB tutorial

Page 2: 6.S093: Visual Recognition through Machine Learning Competition

Getting Started

• To get MATLAB student version, go tohttp://ist.mit.edu/matlab/all/student(or google MIT MATLAB)

• On Athena (athena.dialup.mit.edu),» add matlab» matlab &

Page 3: 6.S093: Visual Recognition through Machine Learning Competition

MATLAB

• Very easy to learn.• Takes some careful attention for a fast code.• Lots of great documentation– Confused?• » help command• Go to mathworks documentation website

http://www.mathworks.com/help/matlab/

Page 4: 6.S093: Visual Recognition through Machine Learning Competition

First Exercise

• Print [Hello World]• Multiple solutions…– Easy way

» disp ‘Hello World’;– Traditional way (formatting is supported)

» fprintf(‘Hello World\n’);

Page 5: 6.S093: Visual Recognition through Machine Learning Competition

Variable types and assignment

• By default,– Number

» tmp1 = 3; % 8-bytes double– Char

» tmp2 = ‘a’; % 2-bytes char• You need to specify when it is not double.

» tmp3 = single(3); % 4-bytes float» tmp4 = int16(3); % 2-bytes int16» tmp5 = false; % 1-byte logical » whos % lists defined variables

Page 6: 6.S093: Visual Recognition through Machine Learning Competition

Matrix

• MATLAB uses Matrix (rather than array).• Matrix uses (row, column)

» a = [1 2; 3 4];» whos Name Size Bytes Class Attributes a 2x2 32 double» a(2, 1:2)

ans = 3 4

Page 7: 6.S093: Visual Recognition through Machine Learning Competition

Vectorization

• How do you compute a dot product?a = 1:1e8;b = cos(1:1e8); % a vector of cos of 1:1e8c = 0;for i=1:length(a) % for-loop from 1 through length(a)

c = c + a(i) * b(i);end

Page 8: 6.S093: Visual Recognition through Machine Learning Competition

Vectorization

• How do you compute a dot product?

• MATLAB is optimized for matrix/vector operations

– First solution takes: 2.02s– Second solution takes: 0.16s

a = 1:1e8;b = cos(1:1e8); % a vector of cos of 1:1e8c = 0;for i=1:length(a) % for-loop from 1 through length(a)

c = c + a(i) * b(i);end

d = a*b’; % matrix multiplication

Page 9: 6.S093: Visual Recognition through Machine Learning Competition

Image Functions

• Imagesc• imread• rgb2gray• edge• figure• imresize• imrotate• imfilter

Page 10: 6.S093: Visual Recognition through Machine Learning Competition

Other useful functions

• Operation: repmat, bsxfun, find• Data structure: cell array, structure• Matrix operation: inv, eig, svd• Statistical function: hist, rand, randn• Function: nargin, nargout• Debug: keyboard, dbstop if error, dbstack• Performance: tic/toc, profile

Page 11: 6.S093: Visual Recognition through Machine Learning Competition

Image comparison

• Compare these 3 images using the average pixel value difference

– Step1: resize image (imresize)– Step2: subtract im1 from im2 and im3– Step3: take an average of absolute difference

• http://viscomp.csail.mit.edu/resource/matlab/image_compare.m

Page 12: 6.S093: Visual Recognition through Machine Learning Competition

Exercise: Image blurring

• Optimize the provided blurring code

• Our blurring algorithm: for each pixel, assign the average value of neighborhood pixels.

• http://viscomp.csail.mit.edu/resource/matlab/image_blur.m

Page 13: 6.S093: Visual Recognition through Machine Learning Competition

Summary• Great documentation

• Vectorization! = AVOID for-loop!

• Matrix is (row, column) rather than (x, y).– Image has [height] x [width]!

• [1..n] rather than [0..n-1]

• LOTS of optimized functions available