Matlab & Image processing toolbox Heejune Ahn SeoulTech Last updated Jan.
Outline Why Matlab? Install Matlab Key concepts of Matlab Basic commands To be an Matlab expert
1.Why Matlab TM ? Nice language Quicker to Learn than other languages. Platform-independent De-facto scientific standard Can focus on algorithm not low level details integrated environment (graphics etc) tool boxes Alternatives OpenCV
Install Matlab Install Run “setup.exe” as usual License Individual licenses (use on your Labtop) Multi-user licenses (at class room, already set-up)
Running Matlab and 20 commands workspace (variables) command hisory command windows working directory
Key concepts Working directory pwd cd Search path addpath( ) editpath matlab setup.m file Workspace whos clear save // session.mat file load
Variables Variable Every thing in Matlab is matrix/array. 1-D, 2-D, & multi-Dim Must be a rectangular Initialization A = [1 2; 3 4] implicit vectorization x=1:10, y=sin(pi.*x./2) Indexing A(rows, columns) first element : “1”, not “0” start:step:end e.g) 0:5:100 All elements: “ : ” A(1, 1:2 ) row A(1:2, 2) = A( :, 2) column
More on variable Generating size e.g.) size(A) zeros, ones, eye modification repmat e.g.) A=eye(4); B=repmat(A,1,2); combine: A=[1 2; 3 4], B=[5 6; 7 8], C=[ ] ; D= [A B]; E= [A; B]; F = [A B; C] Image 3-D of x, y, & component A = imread(‘filename’); imshow(A)
Number representation kjkjkjkjkj
Operations Mathemetical Operations scalar operation vs matrix operation scalar: element by element e.g) A=[1:2, 3:4]; B=A; C=A.*B; D=A*B
Relational Element-by-element e.g.
Logical
Flow control If/else switch
Flow control for-loop While-loop Note: implicit vectorization should be prefered in Matlab
Matlab Functions Built-in functions exp, sqrt, log, sin etc M-function files function C=sub_img(A,B); %comments here if size(A) ~= size(B) disp(‘Images are not the same size’) return; else C=imsub(A,B); imshow(C); %Display 8-bit diff image end inputs output
Useful in M-script User Interaction keyboard type pause Input Algorithm find (indexes) A=1:10; i=find(A>5)
Etc 2-D Ploting Plot bar hist Utility help quit print ; (semi-colon) x = 0:pi/100:2*pi; y = sin(x); figure % opens new figure window plot(x,y)