A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

35
A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU

Transcript of A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Page 1: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

A Brief Introduction to MATLAB

Digital Image Processing 2014 Fall NTU

Page 2: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 3: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 4: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

MATLAB• NTU AppShare (臺大雲端軟體運算銀行 )

– Windows & IE

• https://app.ntu.edu.tw/vdiportal/

Page 5: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

MATLAB interface

Page 6: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

basic operation

Page 7: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

variables• English alphabet, number, underline

– first word must be English alphabet– variable length <= 32 characters

• variables need not be previously declared (default double)

• comments– %

Page 8: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

operators• arithmetic operators

– +, -, *, /, ^

• relational operators– ==, ~=, >, >=, <, <=

• logical operators– &, |, ~

• bitwise operators– bitand, bitor, bitxor

Page 9: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

flow control• conditional control– if-else– switch

• loop control– for– while– continue

Page 10: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

script

• or type “edit filename.m” to create a script from command window

Click to create a new script

Page 11: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 12: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

matrix creation• row vector– R = [7 8 9 10];– R = [7, 8, 9, 10];

• column vector– C = [7; 8; 9; 10];

• build vector fast– start:step:end– linspace(start, end, num);

Page 13: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

extract sub-matrix• A = [1 2 3 4; 5 6 7 8; 9 10 11 12];• B = A(1, 2:4);• C = A(2:3, 2:3);• D = A([1 3], [1 2 3]);

1 2 3 4

5 6 7 8

9 10 11 12

1 2 3 4

1

2

3

Page 14: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Matrix operations• add • Scalar

Page 15: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Matrix operation(Cont’d)• matrix multiplication • array multiplication

Page 16: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 17: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

2-D plotting• Example 1: plot sin(x) and cos(x) over [0, 2]

Page 18: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

subplot• Example 2: create figure with multiple graphs

Page 19: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Axis control• Axis control example:

Page 20: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

histogram• hist(data): histogram plot– data = randn(1000, 3);– hist(data, 20);

Page 21: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 22: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

3-D plotting• Example 1: mesh graph

Page 23: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

3-D plotting (Cont’d)• Example 2: surface graph

Page 24: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

3-D plotting (Cont’d)• Example 3: 3-d curve

Page 25: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 26: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

overview• Basic commands:– img = imread(‘lena.jpg’, ‘jpg’);– imwrite(img, ‘my_lena.jpg’, ‘jpg’);– imfinfo(‘lena.jpg’)– image(img);

Page 27: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Image load and display

Page 28: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

image scale• imresize(img, scale) – resize image

Page 29: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

image rotation• I2 = imrotate(I, 60, ‘nearest’);• I3 = imrotate(I, 60, ‘bilinear’);

Nearest interpolation Bilinear interpolation

Original image

Page 30: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

filter• h1 = fspecial(‘laplacian’);• f1 = filter2(h1, double(f)/255);• h2 = fspecial(‘sobel’);• f2 = filter2(h2, double(f)/255);

laplacian filter sobel filter

original image

Page 31: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

edge detection• f3 = egde(f, ‘sobel’);• f4 = edge(f, ‘canny’);

edge detection by sobel method edge detection by canny method

original image

Page 32: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference

Page 33: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

more about MATLAB• more on, more off: control paged output for

command window• help function_name: help for functions in

command window• lookfor keyword: search for keyword in all

help entries

Page 34: A Brief Introduction to MATLAB Digital Image Processing 2014 Fall NTU.

Outline• MATLAB overview• Matrix• 2-D plotting• 3-D plotting• Image Processing• more about MATLAB• Reference