การใช้งานโปรแกรม MATLAB ดร. อำนาจ ขาวเน
BASIC ELEMENTS OF MATLAB MATLAB Desktop MATLAB Editor Help System MATLAB (MATrix LABoratory)
who, whos – current variables in the workspace save – save workspace variables to *.mat file load – load variables from *.mat file clear – clear workspace variables clc clear screen
Data Classes
Basic Operators
MATLAB Array and Matrix Arithmetic Operators
Example of matrix operation
How to input a row or column vector
How to input a matrix a row at a time
How to change entries in a given matrix A
Creating M-files Input M-function name must start with the word function Output
Graphics x = -pi:.1:pi; y = sin(x); plot(x,y) set(gca,'XTick',-pi:pi/2:pi) set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'}) title('Sine Function'); xlabel('Radians'); ylabel('Function Value');
subplot Create axes in tiled positions
Images in Matlab Reading, writing and querying images
Basic display of images
imagesc function The imagesc function scales image data to the full range of the current colormap and displays the image.
Images in MATLAB Binary images : {0,1} Intensity images : [0,1] or uint8, double etc. RGB images : m-by-n-by-3 Indexed images : m-by-3 color map Multidimensional images m-by-n-by-p (p is the number of layers)
Image import and export Read and write images in Matlab >> I=imread('cells.jpg'); >> imshow(I) >> size(I) ans = (RGB image) >> Igrey=rgb2gray(I); >> imshow(Igrey) >> imwrite(lgrey, 'cell_gray.tif', 'tiff') Alternatives to imshow >>imagesc(I) >>imtool(I) >>image(I)
Images and Matrices How to build a matrix (or image)? >> A = [ 1 2 3; 4 5 6; ]; A = >> B = zeros(3,3) B = >> C = ones(3,3) C = >>imshow(A) (imshow(A,[]) to get automatic pixel range)
Images and Matrices Accesing image elements (row, column) >> A(2,1) ans = 4 : can be used to extract a whole column or row >> A(:,2) ans = or a part of a column or row >> A(1:2,2) ans = 2 5 X Y A =
Image Arithmetic Arithmetic operations such as addition, subtraction, multiplication and division can be applied to images in MATLAB – +, -, *, / performs matrix operations >> A+A ans = >> A*A ans = To perform an elementwise operation use. (.*,./,.*,.^ etc) >> A.*A ans = A =
Converting image types
References “Fundamentals of Digital Image Processing A Practical Approach with Examples in Matlab”, by Chris Solomon and Toby Breckon “MATLAB for Image Processing” by Tuo Wang,Feb 12th, 2010 “MATLAB Tutorial” MIT OpenCourseWare Algebra