Anda di halaman 1dari 25

MATLAB Fundamentals

01074402 IMAGE PROCESSING

. (ksjirasa@hotmail.com)
j @
http://www.kmitl.ac.th/~ksjirasa

King Mongkut's Institute of Technology Ladkrabang

Coordinate Convention

in Many Image Processing

in the Image Processing

Toolbox (MATLAB)
(
)
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Images
g as Matrices
Image Function
f (0, 0)
f (1,
(
0)
)
f ( x, y ) =

f ( M 1, 0)

MATLAB Matrix

f (1,1)
( )
M

L
O

f ( M 1,1) L

f(1 1) f(1
f(1,2)
2)
f(1,1)
f(2,1) f(2,2)
f=
M
M

f(M 1) f(M
f(M,2)
2)
f(M,1)

Department of Computer Engineering

f (0,1)

f(1
f(1,N)
N)
f(2,N)
O
M

L f(M
f(M,N)
N)

f (0, N 1)
f ((1, N 1))

f ( M 1, N 1)

L
L

King Mongkut's Institute of Technology Ladkrabang

Readingg Image
g
imread
imread('filename')

(MATLAB 6.5)
Format
Name

Description

Recognized
Extensions

TIEF

TaggedImageFileFormat

JPEG

JointPhotographicExpertsGroup .jpg,.jpeg

GIF

Graphics InterchangeFormat

.gif

BMP

WindowsBitmap
p

.bmp
p

PNG

PortableNetworkGraphics

.png

XWD

XWindowsDump
p

.xwd

Department of Computer Engineering

.tif,.tiff

King Mongkut's Institute of Technology Ladkrabang

Readingg Image
g

size
whose
size(imread('filename'))

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Readingg Image
g
I = imread('LennaGray.BMP');
I = imread(
imread('D:\My
D:\My Documents\MATLAB\LennaGray
Documents\MATLAB\LennaGray.BMP
BMP');
);
I = imread('D:\My Documents\MATLAB\Folder\rgb
Documents\MATLAB\Folder\rgb.jpg');
jpg');
I = imread('.\Folder\rgb.jpg');
I = imread('D:\My Documents\My Pictures\ong\ong.gif');
I = imread('..\My
i
d(' \M Pi
Pictures\ong\ong.gif');
t
\
\
if')
size(I)
[m,n] = size(I);

pwd :
D:\My
\ y
D:\My
D:\My
D:\My

D:\My Documents\MATLAB\
Documents\MATLAB\LennaGray.BMP
\
\
y
Documents\MATLAB\LennaGray.BMP
Documents\MATLAB\Folder\rgb.jpg
Documents\My Pictures\Ong\Ong.gif

whos I
N
Name

Si
Size

Department of Computer Engineering

B
Bytes
t

Cl
Class

Att
Attributes
ib t

King Mongkut's Institute of Technology Ladkrabang

Display
p y Images
g
imshow
imshow(f)
imshow(f,[low high])



pixval
figure

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Writingg Image
g
imwrite
imwrite(I,'filename')
imwrite(I,'filename','quality',q)
imfinfo filename

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Data Classes
Name

Description

double

Doubleprecision,floatingpointnumbersintheapproximaterange
Doubleprecision
floatingpointnumbersintheapproximaterange
10308 to10308 (8 bytesperelement)

uint8

g
g
g
y p
Unsigned8bitintegersintherange[0,255](1byteperelement)

uint16

Unsigned16bitintegersintherange[0,65535](2bytesperelement)

uint32

g
3
g
g [ ,4 949 7 95] (4 y p
Unsigned32bitintegersintherange[0,4294967295](4byteper
element)

int8

Signed8bitintegersintherange[128,127](1byteperelement)

int16

Signed16bitintegersintherange[32768,32667](2bytesperelement)

int32

Signed32bitintegersintherange[2147483648,2147483647](4bytes
perelement)
l
)

single

Singleprecision floatingpointnumberswithvaluesintheapproximate
rang10338 to10338 (4 bytesperelement)

char

Characters (2 bytesperelement)

logical

Valuesare0or1(1 byteperelement)

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Image
g Types
yp
Intensity images
Binary images
Indexed images
RGB images

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Convertingg between Data Classes and Image


g Type
yp
Converting between Data Class
B = data_class_name(A)

Converting between Data Class and type


Name

ConvertsInputto:

ValidInput ImageDataClasses

im2uint8

unit8

logical,unit8,unit16,anddouble

i
im2uint16
i 6

unit16
i 6

l i l i 8 i 6 dd bl
logical,unit8,unit16,anddouble

mat2gray

double(inrange [0,1])

Double

i d bl double
im2double
d bl

l i l it8 it 6 dd bl
logical,unit8,unit16,anddouble

im2bw

unit8,unit16,anddouble

logical

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Arrayy Indexingg
Vector Indexing
>> v = [1 3 5 7 9]
v =
1
3
5
>> v(2)
ans =
3

>> w = v
w =
1
3
5
7
x = linspace(a,b,n)
9

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Arrayy Indexingg
v =
>>
>>
>>
>>
>>
>>
>>
>>

1
3
v(1:3)
v(2:4)
v(3:end)
v(:)
v(1:end)
v(1:2:end)
v(end:-2:1)
v(end: 2:1)
v([1 4 5])

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Arrayy Indexingg
Matrix Indexing
>> A = [1 2 3 4; 5 6 7 8; 9 10 11 12 ;
13 14 15 16]
A =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Arrayy Indexingg
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>

A = [1:4; 5:8; 9:12; 13:16]


A(2, 3)
C3 = A(:,3)
R2 = A(2,:)
T2 = A(1:2, 1:4)
T2 = A(1:2,
A(1:2 :)
A(end, end)
A(end, end-2)
A([2:3]
A([2:3], [3:4])
A(:, 3) = 0

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Arrayy Indexingg
>> A = [1:4; 5:8; 9:12; 13:16]
>> D = logical([1 0 0 0; 0 0 0 1; 0 0
0 0; 0 0 0 0])
>> A(D)
>> T2 = A(1:2,
(
, :)
)
>> v = T2(:)
>> sum(A)
( )
>> sum(A(:)
>> sum(sum(A))
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Arrayy Indexingg
>> I = imread('Fig0206(a)(roseoriginal).tif');
i i l) tif')
>> I1 = I(end:-1:1, :);
>> I2 = I(:, end:-1:1);
>> size(I)
( )
ans =
1024
1024
>> Ic = I(257:768,
(
, 257:768);
);
>> Is = I(1:16:end, 1:16:end);
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Some Important
p
Standard Arrays
y
ones(r,c)
zeros(r,c)
eye(n)
( )
magic(n)
rand(2,4)
numel
round
d
floor
ceil
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Introduction to M-Function Programming


g
g
Function definition line
function [Outputs] = func_name (Inputs)

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Image
g Histogram
g
imhist(I)
bar(Y)
b (X Y)
bar(X,Y)
stem(Y)
stem(x,y)
plot

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

1
.
Copy Fig0206_rose.tif Current

Directory
M-File
File => New => M-File

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

1
Run
clear all;
close all;
g
_rose.tif');
I = imread('Fig0206
imshow(I);
I1 = I+150;
figure;
imshow(I1);
I2 = I(end:-1:1, :);
figure;
i h ( 2)
imshow(I2);
[M,N] = size(I);
I(1:M/2, 1:N/2) = 0;
I(M/2+1:M, N/2+1:N) = 255;
g
;
figure;
imshow(I);
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

1
Run
clear all;
close all;
g
_rose.tif');
I = imread('Fig0206
imshow(I);
I1 = I-150;
I 150;
figure;
imshow(I1);
I2 = I(end:-4:1, :);
figure;
i h ( 2)
imshow(I2);
L = 50
I(1:L, 1:L) = 0;
I(L+1:2*L, L+1:2*L) = 255;
g
;
figure;
imshow(I);
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

2
. 1024 1024

256
31
63
.
.
.
255
Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

3
. Histogram Equalization

pollen.tif Moon_Phobos.tif
Histogram

Histogram Equalization
Hi
E li i

T(r)

Department of Computer Engineering

King Mongkut's Institute of Technology Ladkrabang

Anda mungkin juga menyukai