Lab 1 PDF
Lab 1 PDF
By
Fahad Layth Malallah
Lab_1
• Introduction to MATLAB
– Basics & Examples
- CODE
Matrices in MATLAB
• Matrix is the main MATLAB data type
• How to build a matrix?
– A=[1 2 3; 4 5 6; 7 8 9];
– Creates matrix A of size 3 x 3
• Special matrices:
– zeros(n,m), ones(n,m), rand(),
randn()
Basic Operations on Matrices
• All operators in MATLAB are defined on
matrices: +, -, *, /, ^, sqrt,
sin, cos, etc.
• Element-wise operators defined with a
preceding dot: .*, ./, .^
• size(A) – size vector
• sum(A) – columns sums vector
• sum(sum(A)) – sum of all the elements
- CODE
Variable Name in Matlab
• Variable naming rules
- must be unique in the first 63 characters
- must begin with a letter
- may not contain blank spaces or other types of punctuation
- may contain any combination of letters, digits, and
underscores
- are case-sensitive
- should not use Matlab keyword
• Pre-defined variable names
• pi
Logical Operators
• Introduction to MATLAB
– Basics & Examples
Row 1 to 256
row = 256;
col = 256;
img = zeros(row, col);
img(100:105, :) = 0.5;
img(:, 100:105) = 1;
figure;
o
imshow(img);
Column 1 to 256
[256, 256]
Images and Matrices
Binary Image:
row = 256;
col = 256;
img = rand(row,
col);
img = round(img);
figure;
imshow(img);
Image Display
• image - create and display image object
• imshow - display image
• colorbar - display colorbar
• getimage - get image data from axes
• zoom - zoom in and zoom out of 2D plot
Image Conversion
• im2bw - image to binary
• im2double - image to double precision
• im2uint8 - image to 8-bit unsigned integers
• im2uint16 - image to 16-bit unsigned integers
• mat2gray - matrix to intensity image
• rgb2gray - RGB image to grayscale
Image Operations
• RGB image to gray image
• Image resize
• Image crop
• Image rotate
• Image histogram
• Image histogram equalization
• Image DCT/
• Convolution
Outline
• Introduction to MATLAB
– Basics & Examples
• Image Processing with MATLAB
– Basics & Examples
Performance Issues
• The idea: MATLAB is
– very fast on vector and matrix operations
– Correspondingly slow with loops
• Better Style
tic % measure performance using stopwatch timer
Output = (apple + orange)/2;
toc
• Elapsed time is 0.099802 seconds
• Computation is faster!