0% found this document useful (0 votes)
52 views

Fundamentals of Matlab: Improve This With WWW - Csie.ntnu - Edu.tw/ violet/IP93/Chapter01

Uploaded by

Luttapi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Fundamentals of Matlab: Improve This With WWW - Csie.ntnu - Edu.tw/ violet/IP93/Chapter01

Uploaded by

Luttapi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Digital Image Processing Using MATLAB®

Fundamentals
of
Matlab

Improve this with www.csie.ntnu.edu.tw/~violet/IP93/Chapter01.ppt


© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Image Formats

http://en.wikipedia.org/wiki/Image_formats

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

More Image Formats

• PPM(Portable Pixelmap) • PGM(Portable Graymap)

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Displaying Images

f = imread(‘rose.tif’);
imshow(f);

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Displaying Images Info.


Try this:

>> f = imread(“Image_Name.extension”);
>> imshow(f)
>> impixelinfo

>> size(f)
ans =
1024 1024

>> [M,N] = size(f);

>> whos f
Name Size Bytes Class Attributes

r 1024x1024 1048576 uint8


© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Displaying Images Info.

imfinfo (bubbles.jpg)

ans =

Filename: 'bubble.jpg'
FileModDate: '14-Jan-2008 17:08:08'
FileSize: 7904
Format: 'jpg'
FormatVersion: ‘' Try this
Width: 720 >> K imfinfo('bubbles.jpg');
Height: 688 >> K.FileSize
BitDepth: 8
ColorType: 'grayscale' ans =
FormatSignature: ‘'
NumberOfSamples: 1
CodingMethod: 'Huffman'
7904
CodingProcess: 'Sequential'
Comment:
© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins
{} www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Writing Images

Syntax:
variable=imread(“Image_name.extension’);
Imwrite(variable,”Name.ext”);
Try This:
Step1:Read
>> b = imread(‘bubbles.tif’);
Step2:Write
>> imwrite(b,'bubbles.png');
>> imwrite(b,'bubbles.jpg');
>> imwrite(b,'bubbles', 'jpg');

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Data Classes

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Converting Between
Data Classes

Syntax: B = data_class_name(A)

Example: Suppose

A is an array of class uint8


C is an array of class double

B = double(A)
D = uint8(C)

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®
Converting Between
Image Classes & Types

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®
Converting Between
Image Classes & Types

Example: Consider the following 2 X 2 image f of class double:


Try This:
>> f = [-0.5 0.5; 0.75 1.5]
f=
-0.5 0.5
0.75 1.5

>> g = im2uint8(f) >> h = uint8([25 50; 128 200]);


>> g = im2double(h);
g= g=
0 128 0.0980 0.1961
191 255 0.4706 0.7843
© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Array Indexing
Example:

>> v = [1 3 5 7 9]
v=
1 3 5 7 9
>> v(2) “2nd index”
ans =
3
>> v(2:4) “2nd to 4th index”
ans =
3 5 7

Guess the output of: v(3:end) v(1:2:end) v(end:-2:1)


© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Matrix Indexing
Example:

>> A = [1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
7 8 9

>> A(2, 3) Try this:


ans = C3 = A(:, 3)
6 C3 =
3
>> R2 = A(2, :) 6
R2 = 9
4 5 6
Guess the output of: A(1:2, 1:3) A(end, end-2) A(:, 3)
© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Standard Arrays
>> A = 5*ones(3, 3)
A=
5 5 5
5 5 5
5 5 5
>> magic(3)
ans =
8 1 6
3 5 7
4 9 2
>> B = rand(2, 4)
B=
0.2311 0.4860 0.7621 0.0185
0.6068 0.8913 0.4565 0.8214
© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Operators
Example:

f=
1 2
3 4

>> v = f(:) “All column in to one column”


v=
1
3
2
4
© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Arithmetic Operations

Example:
>> imshow(imcomplement(f))
© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com
Digital Image Processing Using MATLAB®

Relational Operators

Example:

>> A = [1 2; 3 4]
A=
1 2
3 4

>> B = [0 2; 3 5;]
B=
0 2
3 5

>> A>=B
ans =
1 1
1 0

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Logical Operators and Functions

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com


Digital Image Processing Using MATLAB®

Flow Control Statements

© 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www.imageprocessingbook.com

You might also like