EE 4780 Matlab tutorial Bahadir K Gunturk MATLAB

EE 4780 Matlab tutorial Bahadir K. Gunturk

MATLAB n n n Review your matrix-vector knowledge Matlab help files are helpful to learn it Exercise: f = [1 2; 3 4] g = [1; 1] g = [1 1] g’ z = f * g’ n=0: 10 plot(sin(n)); plot(n, sin(n)); title(‘Sinusoid’); xlabel(‘n’); ylabel(‘Sin(n)’); n=0: 0. 1: 10 plot(n, sin(n)); grid; figure; subplot(2, 1, 1); plot(n, sin(n)); subplot(2, 1, 2); plot(n, cos(n)); Bahadir K. Gunturk 2

MATLAB n Some more built-ins a = zeros(3, 2) b = ones(2, 4) c = rand(3, 3) %Uniform distribution help randn %Normal distribution d 1 = inv(c) d 2 = inv(rand(3, 3)) d 3 = d 1+d 2 d 4 = d 1 -d 2 d 5 = d 1*d 2 d 6 = d 1. *d 3 e = d 6(: ) Bahadir K. Gunturk 3
![MATLAB n Image processing in Matlab x=imread(‘cameraman. tif’); figure; imshow(x); [h, w]=size(x); y=x(0: h/2, MATLAB n Image processing in Matlab x=imread(‘cameraman. tif’); figure; imshow(x); [h, w]=size(x); y=x(0: h/2,](http://slidetodoc.com/presentation_image/7c227438308af49b7754c3e80d9db682/image-4.jpg)
MATLAB n Image processing in Matlab x=imread(‘cameraman. tif’); figure; imshow(x); [h, w]=size(x); y=x(0: h/2, 0: w/2); imwrite(y, ’man. tif’); % To look for a keyword lookfor resize Bahadir K. Gunturk 4
![MATLAB n M-file Save the following as myresize 1. m n function [y]=myresize 1(x) MATLAB n M-file Save the following as myresize 1. m n function [y]=myresize 1(x)](http://slidetodoc.com/presentation_image/7c227438308af49b7754c3e80d9db682/image-5.jpg)
MATLAB n M-file Save the following as myresize 1. m n function [y]=myresize 1(x) % This function downsamples an image by two [h, w]=size(x); for i=1: h/2, for j=1: w/2, y(i, j) = x(2*i, 2*j); end n Compare with myresize 2. m function [y]=myresize 2(x) % This function downsamples an image by two [h, w]=size(x); for i=0: h/2 -1, for j=0: w/2 -1, y(i+1, j+1) = x(2*i+1, 2*j+1); end Bahadir K. Gunturk n Compare with myresize 3. m function [y]=myresize 3(x) % This function downsamples an image by two y = x(1: 2: end, 1: 2: end); n We can add inputs/outputs function [y, height, width]=myresize 4(x, factor) % Inputs: % x is the input image % factor is the downsampling factor % Outputs: % y is the output image % height and width are the size of the output image y = x(1: factor: end, 1: factor: end); [height, width] = size(y); 5
- Slides: 5