Fundamentals of Matlab: Improve This With WWW - Csie.ntnu - Edu.tw/ violet/IP93/Chapter01
Fundamentals of Matlab: Improve This With WWW - Csie.ntnu - Edu.tw/ violet/IP93/Chapter01
Fundamentals
of
Matlab
Image Formats
http://en.wikipedia.org/wiki/Image_formats
Displaying Images
f = imread(‘rose.tif’);
imshow(f);
>> f = imread(“Image_Name.extension”);
>> imshow(f)
>> impixelinfo
>> size(f)
ans =
1024 1024
>> whos f
Name Size Bytes Class Attributes
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');
Data Classes
Converting Between
Data Classes
Syntax: B = data_class_name(A)
Example: Suppose
B = double(A)
D = uint8(C)
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
Matrix Indexing
Example:
>> A = [1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
7 8 9
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®
Operators
Example:
f=
1 2
3 4
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