1 / 13

6.S093: Visual Recognition through Machine Learning Competition

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.

piera
Download Presentation

6.S093: Visual Recognition through Machine Learning Competition

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 &

  3. MATLAB • Very easy to learn. • Takes some careful attention for a fast code. • Lots of great documentation • Confused? • » help command • Go to mathworks documentation websitehttp://www.mathworks.com/help/matlab/

  4. First Exercise • Print [Hello World] • Multiple solutions… • Easy way» disp ‘Hello World’; • Traditional way (formatting is supported)» fprintf(‘Hello World\n’);

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

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

  7. Vectorization • How do you compute a dot product? • a = 1:1e8; • b = cos(1:1e8); % a vector of cos of 1:1e8 • c = 0; • for i=1:length(a) % for-loop from 1 through length(a) • c = c + a(i) * b(i); • end

  8. 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:1e8 • c = 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

  9. Image Functions • Imagesc • imread • rgb2gray • edge • figure • imresize • imrotate • imfilter

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

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

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

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

More Related