Вы находитесь на странице: 1из 90

..

MATLAB

-
,
200200 , 200203
-



2010
528.7:004
217

: , , ..
, , ..

..
217 matlab []:
2 . . 2 / .. . : , 2010. 83 .

ISBN 978-5-87693-400-0 (. 2)
ISBN 978-5-87693-398-0


- , (4 ,
), (3 ),
(6 , ) ,
200200 , 200203
- .


Image Processing ToolBoxes.

: , , ..

528.7:004

ISBN 978-5-87693-400-0 (. 2)
ISBN 978-5-87693-398-0


(), 2010

1.
................................................................................................ 4
2. ..... 12
3. 19
4. .... 27
5. ,
.............................................................................................. 35
6. .................. 41
7. ............................ 50
8. ................................. 55
9.
.......................................................................................... 60
10. ............................... 70
11.
................................................................................................... 79
12.
..................................................................................................................... 85

..................................................................................................................... 90
1.

, ()
MatLab,
.
1.

:

, ;
,
.

( pixel, picture
element ), .
,
, :
V = ( r d) / 8,
; r ; d (/
).
:
(black and white)
: 0 1 ( );
( intensity,
grayscale) -

;
(indexed)
(colormap),
();
(truecolor, rgb) ,

.

, double
uint8, , . 1.1.
1.1
double uint8
0 1 0 1


[0, 1] [0, 255]


[1, ], [0, 255], 0
1



[0, 1] [0, 255]


. ( )
I r c: I(r, c).
,

R, G, B.

I r, c
: 1 R, 2 G,
3 B, , I(r, c, 1)
.

.

.
double,

R, G, B.
,
uint8,
. 1.1.


. 1.1
:
I ; X ; RGB ; BW
;
S ; D
.

() ,

.
MatLab
Image Processing Toolboxes (IPT).

imfinfo

info = imfinfo(< >)
info
< >; ,
, , 'c:\mmm\Earth.bmp'.
, MatLab
, . 1.2.
1.2

'bmp' Windows Bitmap (BMP)
'tif 'tiff Tag Image File Format (TIFF)
'jpg' 'jpeg' Joint Photographic Experts Group (JPEG)


info.
. 9 ,
, ,
. 1.3.

1.3 info

, ,
Filename

FileModDate
FileSize
Format

FormatVersion

Width
Height
BitDepth
: 'truecolor' 'RGB'
; 'grayscale'
ColorType
; 'indexed'

TIFF HDF .
info .

1. ,
c:
>> f = imfinfo(c:\Image\Athena.bmp).
imread

D = imread(< >) < >
D, (< >)
, , , 'c:\mmm\Athena.bmp'.
[X, map] = imread(< >) < >
X m.

uint8.

2. Handshak.bmp.
>> [X,map] = imread('c:\Image\Handshak.bmp');
imwrite

imwrite(S, < >) < >
, S.
imwrite(X, map, < >) <
> X ma.

imshow

imshow(S) .
imshow(I,n) I, n = 256.
imshow(I,[low high])
.
imshow(X,map) X, ma .
imshow (< >) .
imshow(I,[low high])
I, . ,
/ low, , / high
. low high.
[], low = = min(I(:)), high =
max(I(:)).

, :
>> imshow(X,map).

subplot
subimage:

subimage(S) ,
.
subimage(X,map) X
m.


()
:
double ;
double 8 ;
uint8 ,
[0, 255].

double
im2double.

D = im2double(S) ,
S double
[0,1].
XD = im2double(XS,'indexed') XS
double.
mat2gray S
double D. D
0 () 1 ().

D = mat2gray(S)
uint8
im2uint8.

D = im2uint8 (S) ,
S uint8;
[0, 255].
XD = im2uint8 (XS, 'indexed') XS
uint8.


:
I = rgb2gray(RGB)
;
I = ind2gray(X,map)
;
[X map] = gray2ind(I,n)
, n 64;
RGB = ind2rgb(X,map)
;
[X map] = rgb2ind(RGB)
.

3. ,
'Handshak.bmp' Image,
.
>> [X,map] = imread('c:\Image\Handshak.bmp');
>> Xd = im2double(X, 'indexed');
>> I = ind2gray(X,map);
>> figure,subplot(1,2,1),subimage(X,map);
>> subplot(1,2,2),subimage(I).
2.
1. 'butterfly.bmp'.
2. 'butterfly.bmp',
: ) ) .
, , ,
0.2, ,
, 0.8 .
3.
double.
4.
, .
3.
1. ()
?
2. IPT?
3. ,
?
4.
MatLab?
5.
?
6. imshow
?
7. ?
2.

,
, -
.
1.

f (x, y)
x y
(. 2.1).

n2T1
Ly

Lx Lx
0 x n1T1

Ly
. 2.1
x T1,
y T2. , T1 x,
.
,
:
f(n1T1, n2T2) = f(x, y) | x = n1T1, y = n2T2;
f ( n1T1 , n 2 T2 ) f ( n1 , n 2 ) .
,
.
( )
:
Mx = [2Lx / T1], My = [2Ly / T2].
, ,
(picture element). T1, T2
,
.

. w,
T.
:
T < = 2 / w.
.
f (x, y) -
df.
.
:
K = [A / df],
f(, ).

()
.
,

blkproc

D = blkproc(S,[m n],fun,P1,P2)
n D = blkproc(S,[m
n],fun,P1,P2)
D,
m
fun
mn
S.

,

(.
2.2).
. 2.2
.
fun . 2.1.
.
2.1 fun blkproc
fun

myfun,
D = blkproc(S,

[m n],'myfun');

y = myfun(x)
,
D = blkproc(S, [m n], MatLab.
'mean2(x)*ones(size(x))');

P1, P2 . . fun .

( XS double),
( XS uint8).

1. :
1. M- File/New/M-file;
2.

function diskr (I,s)


I1 = blkproc(I, [s(1) s(2)],'mean2(x)*ones(size(x))');
figure,imshow(I1)
str = mat2str(s);
str = strcat('diskret image',str);
title(str);
3. .

quantiz
MatLab
Signal Processing Toolboxes.
.
quantiz .

[indx, kv,ds] = quantiz(sg, prt,cdb),
sg ; prt ; cdb
.
indx :
sg (k)< = prt (1), indx (k) = 0;
prt (1), < sg (k) < = prt (m+1), indx (k) = m;
sg (k) > prt (end), indx (k) = length(prt);

kv
cdb(indx +1). , cdb(1)
, , prt(1);
cdb(m) prt(m1) prt(m);
cdb (end)
, prt (end).
ds ,
.

2. quantiz
Clouds.bmp Image.
>> [S,map] = imread('c:\Image\Clouds.bmp');
>> I = im2double(ind2gray(S,map));
>> [ M N] = size(I);
>> p = 0:0.1:1;
>> [INDX] = quantiz(I(:), p);
>> figure,imshow(I)
>> I1 = reshape(INDX,M,N);
>> figure,imshow(I1,[])

3. :
1) M- File/New/M-file;
2) :
function kvant (I,p);
[M N] = size(I);
INDX = quantiz(I(:), p);
I1 = reshape(INDX,M,N);
I2 = mat2gray(I1);
figure,imshow(I2);
title('kvant image');
3) .

4. -
:
1) M- File/New/M-file;
2) -:
y = 1;
while y == 1
St = input(' ');
[X,map] = imread(St);
I = im2double (ind2gray(X,map));
figure,imshow(I)
title('gray image');
y1 = 1;
while y1 == 1
M = menu(' , ...
' ','
');
if M == 1
p = input(' ([ma:d:mi]) ');
kvant(I,p);
end
if M == 2
s = input(' ([m n]) ');
diskr(I,s);
end
y1 = input(' ? (1) ');
end
y = input(' (1) ');
end
3) File/Save as .
;
4) - (Command Window)
-.
. 2.3.

. 2.3
2.
1. -
, , ,
.
3.
1. ?
2. ?
3. ?
4. ) quantiz; ) blkproc?
3.

,
, .
1.


.
imcrop

[D,rect] = imcrop (S) ,
.
[Xd,rect] = imcrop (Xs,map) ,
.
D = imcrop (S, rect) rect.
Xd = imcrop (Xs,map, rect) rect.
D = imcrop
.
imcrop(S) S
.

Shift.
rect, , : [Xmin Ymin
w,h], Xmin Ymin ; w
; h .

1. .
>> [S,map] = imread('c:\Image\Athena.bmp');
>> figure,imshow(S,map);
>> [A,rect] = imcrop(S,map); %
>> figure,imshow(A,map);
>> rect

2. , rect
>> rect = [0,0,112.5,68.5]; %
>> P = imcrop(S,map,rect);
>> figure,imshow(P,map)
imresize

D = imresize (S, m, method)
D S, m
0 1. m 1, D S.
,
method :
nearest (
);
bilinear ;
bicubic .

3.
>> [S,map] = imread('c:\Image\Athena.bmp');
>> I = ind2gray(S,map); %
>> imshow(I)
>> figure,imshow(imresize(I,2)), title(nearist)
>> figure,imshow(imresize(I,2,'bilinear')), title('bilinear')
>> figure,imshow(imresize(I,2,'bicubic')), title('bicubic')

4.
>> X1 = imresize(I,0.5);
>> figure,imshow(X1,[]); title(nearist)
>> X2 = imresize(I,0.5,'bilinear');
>> figure,imshow(X2,[]); title('bilinear')
>> X3 = imresize(I,0.5,'bicubic');
>> figure,imshow(X3,[]); title('bicubic')
imrotate

D = imrotate(S, angle, method)
D,
S,
(. imresize). angle .

, .

5. 45
.
>> [D,map] = imread('c:\image\Chip.bmp');
>> figure,subplot(1,3,1),subimage(imrotate(D,45),map)
>> subplot(1,3,2),subimage(imrotate(D,45,'bilinear'),map);
>> subplot(1,3,3),subimage(imrotate(D,45,'bicuic'),map);


,
,
.
:
t11 t12 0
[x y 1] = [ w z 1] T t 21 t 22 0 .
t 31 t 32 0

, , ,
. . 3.1
,
.
3.1



Sx 0 0 X = SX W
0 Sy 0
Y = SY Z
0 0 1
cos( a ) sin( a ) 0 x = w cos(a ) z sin(a )
sin( a ) cos( a ) 0
0 0 1 y = w sin(a ) + z cos(a )


1 0 0 x = w + az
a 1 0
()
0 0 1 y=z


1 b 0 x=w
0 1 0
()
0 0 1 y = bw + z

1 0 0 X = W + SX
0 1 0
Sx Sy 1 Y = Z + SY

IPT
tform-.
maketform.

tform = maketform(transftype, T),
transftype ( ); T
.
.3.2 transftype.
3.2 maketform

/, , .
Affine
,
/ ;
Box

,
Composite

, ,
Custom
-1
, ,
Projective


imtransform.

D = imtransform(I, tform, type, P),
I ; tform tform-
; type ,

. : 'nearest', 'bilinear'
'bicubic'. 'bilinear'. ,
, P = FillValue ,
, :
>> D = imtransform(I, tform, 'FillValue', 0.5);

, checkerboard.

I=checkerboard(N,P,Q),
N , ;
P (2P); Q
(2Q). P Q
,
.

6. ;
.
.
1. - affintr:
function affintr(I,T,type)
tform=maketform(affine,T);
I1 = imtransform(I, tform) ;
figure, imshow(I1)
title(type)
2. :
>> I=checkerboard(40);
>> figure, imshow(I)
3. :
>> T=[3 0 0;0 2 0;0 0 1]; type=resize;
>> affintr(I,T,type);
4. :
>> T=[1 0 0;0 .2 0;0 0 1]; type=Sdvig;
>> affintr(I,T,type);
5. :
>> T = [cos(pi/4) sin(pi/4) 0;-sin(pi/4) cos(pi/4) 0; 0 0 1]; type=Rotate;
>> affintr(I,T,type);
6. ,
:
>> Tscale = [1.5 0 0; 0 2 0; 0 0 1]; %
>> Trot = [cos(pi) sin(pi) 0;-sin(pi) cos(pi) 0; 0 0 1]; %
>> Tshear = [1 0 0; .2 1 0; 0 0 1] ; %
>> T1 = Tscale*Trot*Tshear;
>> tform=maketform('affine',T1); type=All;
>> affintr(I,T1,type);

7. :
>> T = [1 0 0; 0 1 0; 50 50 1];
>> tform=maketform(affine,T);
>> I1 = imtransform(I, tform, 'XData', [1 320], 'YData', [1 320], 'FillValue', 0.5);
>> figure, imshow(I1)


,
:
Ic = I (Y:Ym, X:Xn,);
Iy = I(end:-1:1, :);
Iy = I(:,end:-1:1);
Id = I(1:2:end, l:2:end);

7.
Bigbird.bmp
.
>> [x,map]=imread('c:\image\bigbird.bmp');
>> I=im2double(ind2gray(x,map));
>> figure, imshow(I)
>> Iy = I(:,end:-1:1);
>> figure, imshow(Iy)
>> Id = Iy(:, 1:2:end);
>> figure, imshow(Id)
2.
. 3.3.
. 3.4. . 3.5 (

). . 3.5
. 3.4
( . 3.3, . .).
3.3



1 bike.bmp
2 Blaise.bmp
3 Clouds.bmp
4 Handshak.bmp
5 Technlgy.bmp
6 Saturn.bmp
7 Construc.bmp
8 Bigbird.bmp

3.4



1 ( )
2 ( )
3 D
,
4 1/3
,

5
S
(N) , :
6
a 'nearest'; b bilinear; d 'bicubic'
(N) , :
7
a 'nearest'; b bilinear; d 'bicubic'
(),
8 :
a 'nearest'; b bilinear; d 'bicubic'
(),
9 :
a 'nearest'; b bilinear; d 'bicubic'
(N) , : a 'nearest', b
10
bilinear, d 'bicubic'
. 3.4

11 (Sx, Sy)
12 (, b)
13 (Sx, Sy)
14
15
16

3.5

. 3.4

1 1(4); 2(4); 4, 6(3)a; 8(45)a; 14; 15


2 1(1); 2(1); 7(4)a; 5, 6(4)b; 9(90)a; 14; 16
3 1(3); 2(3); 10(2)a; 8(90)b; 3; 6(3)d; 14; 15
4 2(7); 11(2,4); 14; 16
5 1(2); 2(2); 9(45)a; 9(45)b; 9(45)d; 14; 15
6 1(6); 2(6); 6(3)b; 4; 6(3)b; 9(180); 14; 15
7 1(5); 2(5); 5; 8(60)a; 8(60)b; 8(60)d; 14; 16
8 2(7); 13(20,40); 14; 16
9 2(8); 12(0.6, 0.6); 14, 16
3.
1.
imcrop?
2. ?
3. ?
4. :
5. ) ; ) ; ) ; ) ?
6. ?
7. ?
4.


.
1.

.
, .
,
.

.
Jmax,

, Jmin > 0.
Dj = Jmax Jmin .

.
(X1,Y1) J1 = J(X1,Y1), (X2,Y2) J2 = J(X2,Y2).
J'max = max(J1, J2) J'min = min(J1, J2).
:
J ' max J ' mim .
K=
J ' max

.


(. 4.1).
,
, ,
.

. 4.1
I
MaI NI
: NI = MaxI I.

1.
Construc.bmp
>> [D,map] = imread('c:\ Image\ Construc.bmp);
>> I = ind2gray(D,map);
>> figure,imshow(I);
>> MaxI = max(I(:));
>> NI = MaxII;
>> figure,subplot(1,2,1),subimage(I);
>> subplot(1,2,2),subimage(NI);
,
-
imadjust

ID = imadjust (IS,[low,high],[bottom top],gamma)
ID = imajust(IS,[low,high],[bottom top],gamma)
ID
IS. [low,high]
[bottom top]. , low,
bottom, , high, top. top,
bottom, low, high [0,1].
[],
[0,1].
gamma
. gamma 1,
, .
gamma 1,
, .
gamma 1,
-.
gamma . 4.2.

2.
-.
>> [D,map] = imread('c:\ Image\Technlgy.bmp');
>> I = ind2gray(D,map);
>> figure,imshow(I);
>> I1 = imadjust(I,[0 0.9],[],1);
>> I2 = imadjust(I,[0 0.9],[],0.5);
>> I3 = imadjust(I,[0 0.9],[],2);
>> figure,subplot(1,3,1),subimage(I1);
>> subplot(1,3,2),subimage(I2);
>> subplot(1,3,3),subimage(I3);


top top top

bottom bottom bottom

low high low high low high

. 4.2
brighten

brighten(beta) ;
newmap = brighten(beta) ,
,
;
newmap = brighten(map,beta) ,
map.
, beta
[0, 1], , beta [1, 0].

3. : )
; )
.
>> [D,map] = imread('c:\Image\earth.bmp');
>> map1 = brighten(map,0.5);
>> map2 = brighten(map, 0.8);
>> figure,subplot(1,3,1),subimage(D,map);
>> title('map')
>> subplot(1,3,2),subimage(D,map1);
>> title('map1')
>> subplot(1,3,3),subimage(D,map2);
>> title('map2')

imapprox

[XD, newmap] = imapprox(XS, map, tol,differ_option)
[XD, newmap] = imapprox(XS, map, n,differ_option)
imapprox XD
XS, .
tol
newmap , [0, 1] tol
R, G, B; tol [0, 1].
n (n , 1),
XD newmap n .
n,
, .
differ_option
.
:
'dither' ;
'nodither' .
.
,
, .
,
,
.

4. n =
5, ,
, .
>> [D,map] = imread('c:\Image\Blaise.bmp');
>> [D1,newmap] = imapprox(D,map,5);
>> figure,subplot(1,2,1),subimage(D,map)
>> subplot(1,2,2),subimage(D1,newmap)
>> I = ind2gray(D,map);
>> I1 = ind2gray(D1,newmap);
>> figure,subplot(1,2,1),subimage(I)
>> subplot(1,2,2),subimage(I1)
5.
tol = 0.5
.
>> [D,map] = imread('c:\image\Factory.bmp');
>> figure,imshow(D,map)
>> [D1,nm] = imapprox(D, map, 0.5);
>> figure,imshow(D1,nm)
>> [D11,nm1] = imapprox(D, map, 0.5,'nodither');
>> figure,imshow(D11,nm1)
2.
. 4.1.
. 4.2. . 4.3
(
).
4.1



1 butterfly.bmp
2 Saturn.bmp
3 Clouds.bmp
4 Handshak.bmp
5 Bigbird.bmp
6 Technlgy.bmp
4.2



1 ( )
2 ( )
, [low high] [bottom
3
top] gamma
4 ()
5
6
, (tol):
7 a) c ; b)

,
8 (n): a) c ; b)

, beta
9
[min max] (k)
10
11
,
12
double

13
, double
4.3

. 4.2

1(1); 2(1); 10; 4; 3[0.3 0.7],[], gamma


1
0 2 1; 12
2 2(2); 11; 8( 2 6 2)a,b; 12
3 1(3); 2(3); 9[0.5 0.5] (0.5); 13
4 1(4); 2(4); 7( 0.4 0.8 0.2)a,b; 13
1(5), 2(5), 4; 3[0.2 0.7],[], gamma
5
0.5 1.5 0.5; 6; 12
6 1(6); 2(6); 9[ 1 1] (1); 6; 12
3.
1. ?
2. ?
3.
?
4. brighten?
5.
? ?
5. ,


.
1.


,
() ,
.

( ),
, (
).

, ,
.
imhist

imhist(I,n)
. n .
n = 256 n = 2 .
;
imhist(X,map)
X.
map;
[h, cx] = imhist(I,n)
[h,cx] = imhist(X,map) [h, cx] = imhist()
h cx
( ) (
),
h.

1. .
>> [S,map] = imread('c:\Image\chip.bmp');
>> figure,imshow(S,map);
>> imhist(S, map)

2.
.
>> [S,map] = imread('c:\Image\chip.bmp');
>> I = ind2gray (S,map);
>> figure,imshow(I);
>> figure, imhist(I);
>> [h,cx] = imhist(I);
>> figure,stem(cx,h)
() histeq

.
,
.
.

.

ID = histeq(Is,n)
ID= histeq(Is, hgram)
ID = histeq(Is,n)
Is , ID
, . n
Is,
ID.
n 64,
.
ID = histeq(Is,hgram)
,

hgram.

, .

3.

- twomgauss :
function p= twomgauss(ml, sigl, m2, sig2, A1, A2, k)
% : ml, sigl, m2, sig2, . . -
% ; A1, A2 , k
%
% ( ml, sigl, m2, sig2, A1, A2, k):
% (0.15, 0.05, 0.75, 0.05, 1, 0.07, 0.002)
cl =A1 * (1 /(((2 * pi) ^0.5) * sigl));
kl = 2 * (sigl ^2);
c2 = A2 * (1/(((2*pi)^0.5) * sig2));
k2 = 2 * (sig2 ^2);
z = linspace(0, 1, 256);
p = k + cl * exp(-((z-ml) .^2) ./ kl) + c2 * exp(-((z-m2) .^2) ./ k2);
p = p ./ sum(p(:));
>> p= twomgauss(0.15, 0.05, 0.75, 0.05, 1, 0.07, 0.002);
>> plot(p)

4.
.
>> [D,map] = imread('c:\Image\mona.bmp');
>> newmap = histeq(D,map)
>> figure,imshow(D,map)
>> figure,imshow(D,newmap)
,

, ,
,
.

. , .
mean2

m = mean2(S)
m = mean2(S) S.
mean(S(:)).

std2
std2 .

d = std2(S)
S. std(S(:)).

corr2

k = corr2(A,B) k
A,B. A B .

:
( A ( c, r ) A m ) ( B( c, r ) B m )
k= c r ,
( ( A ( c , r ) A m ) ( B( c, r ) B m )
2 2
c r
Am = mean2(A); Bm = mean2(B) .

xcorr2

c = xcorr2(a,b)
a b.
c = xcorr2(a)
c = xcorr2(a,a).
5.
bike.bmp
.
.
D=imread('c:\Image\bike.bmp');
I=im2double(rgb2gray(D));
c1=xcorr2(I,I);
MaI=max(I(:));
NI=MaI-I;
c2=xcorr2(I,NI);
figure,mesh(c1)
title(autocorr. function)
figure,mesh(c2)
title(corr. function)
2.
:
1. ,
wall.bmp. .
.
2. butterfly.bmp
. 256.
.
.
3.
180 bigbird.bmp.
3.
1. ?
2. ?
3.
?
4. ?
? .
5. ?
6. ?
6.

,
.
1.
imnoise

ID = imnoise(Is, type, params)
imnoise ID
Is.
, type.
params .
, :
1) ID = imnoise(Is, gaussian, m,v) Is
m v. m =
0, v = 0.01;
2) ID = imnoise(Is, salt & pepper, d) Is
() . d
. d = 0.05;
3) ID = imnoise(Is, spekle,v) Is
ID = Is+n*Is, n
v.
v = 0.04.

1. ,
.
>> [S,map] = imread('c:\Image\Mona.bmp');
>> I = ind2gray(S,map);
>> S1 = imnoise(I,'gaussian',0,0.1);
>> S2 = imnoise(I,'salt & pepper');
>> S3 = imnoise(I,'speckle');
>> figure,subplot(1,3,1),subimage(S1);
>> subplot(1,3,2),subimage(S2);
>> subplot(1,3,3),subimage(S3)




,
.
,
.
,
.
, ,
, .
,
.
, .
. , ,
180 .
,
.
, .
conv2

D = conv2(S,h, shape)
S
h. shape,
D, :
1) full ( );
2) same S;
3) valid S
.

filter2

D = filter2(h,S, shape)
S ,
h. , S D
. shape ,
conv2. shape = same.
, , h 180
S.
rot90.

2. ,

1 1 1
h= 1 2 1 .
1 1 1
>> [x,map] = imread('c:\image\mona.bmp');
>> I = ind2gray(x,map);
>> I = im2double(I);
>> h = [1 1 1;1 -2 1;-1 -1 -1];
>> h1 = rot90(h,2);
>> I1 = filter2(h1,I);
>> figure,imshow(I)
>> figure,imshow(I1)
medfilt2

ID = medfilt2(IS,[m,n], padopt)
,
,
m n ( 3 3)
: , ,
.
ID (r,c), r c
, .
padopt
: 'zeros' , 'symmetric',
IS
, 'indexed', IS 1, IS
double, 0 .

3. Athena.bmp,
.
>> [S,map] = imread('c:\Image\Mona.bmp');
>> I = ind2gray(S,map);
>> S = imnoise(I,'salt & pepper');
>> figure,imshow(S,[]);
>> D = medfilt2(S);
>> figure,imshow(D,[]);

freqz2

freqz2(h,n1,n2) .
[H,f1,f2] = freqz2(h,n1,n2) H n1 n2,
, f1 f2,
, h.

4. .
>> h = [1,1,1;1,9,1;1,1,1];
>> figure,freqz2(h);
>> title(1 variant)
>> [H,f1,f2] = freqz2(h);
>> figure,mesh(f1,f2,abs(H))
>> title(2 variant)

fspecial

h = fspecial (type, P1, P2)
h
, type. ,
1, 2.
n ( n , n(1) n(2), n
, n n), sigma
, h;
,
, [0, 1], 0.2.
fspecial:
1) h = fspecial ('gaussian', n,sigma) h
. n 3 3, sigma 0.5;
2) h = fspecial ('sobel')
,
h;
3) h = fspecial ('prewitt')
,
h;
4) h = fspecial ('11ian', ) h .
3 3.
, g(, ) = f(x, ) + c2f(x, ), f(, )
; g(, ) ,
1, , =
1 ; 2f(x, ) = d2f(x, y) / dx2 + d2f(x, y) / dy2
;
5) h = fspecial ('log',n,sigma) h ,
,
, n sigma 5 5
0.5 ;
6) h = fspecial ('average', n) h .
n 3 3;
7) h = fspecial ('unsharp', a) h ,
. : 3 3.

5. ,
.
1. h :
>> h = fspecial('laplacian',0);
2. :
>> [S,map] = imread('c:\Image\Mona.bmp');
>> I = im2double(ind2gray(S,map));
>> figure,imshow(I)
>> I1 = filter2(h,I);
>> figure,imshow(I1)
>> I2 = I I1;
>> figure,imshow(I2)
6. .
1.
>> h = fspecial('sobel');
2.
>> h1 = h';
3. earth.bmp .
>> [X,map] = imread('c:\Image\earth.bmp');
>> I = ind2gray(X,map);
>> figure,imshow(I)
>> F1 = filter2(h,I);
>> figure,imshow(F1)
>> F2 = filter2(h1,I);
>> figure,imshow(F2)
>> F3=F1+F2;
>> figure,imshow(F3)

fsamp2

h = fsamp2(f1,f2,H)
h ,
H ,
f1 f2.

7.
, .
1. :
>>[f1,f2] = freqspace(15,'meshgrid');
2. - ,
:
>> dist = abs(f1)+abs(f2);
>> H = dist/max(dist(:));
3. :
>> figure,mesh(f1,f2,H),colormap(cool(32));
4. :
>> h = fsamp2(f1,f2,H,[5 5]);
5. :
>> figure,colormap(cool(32)),freqz2(h);
6. :
>> [i,map] = imread('c:\Image\athena.bmp');
>> figure,imshow(i,map);
7. :
>> i1 = mat2gray(filter2(h,im2double(i)));
>> figure,imshow(i1);
8. :
>> i2 = imadjust(i1,[0 0.5],[]);
>> figure,imshow(i2);

2.7.
ftrans2

h = ftrans2(b)
h ,

b.
t. :

1 2 1
1
t = 2 4 2.
8
1 2 1

h = ftrans2(b,t) .

8.
(),
:
1. 14- 0.2:
>> b = fir1(14,0.2); %
>> freqz(b,1,256)
2. :
>> h = ftrans2(b);
>> figure,freqz2(h)
3.
:

>> [S,map] = imread('c:\Image\Athena.bmp');


>> I = ind2gray(S,map);
>> I = im2double(I);
>> figure,imshow(I)
>> I1 = filter2(h,I);
>> figure,imshow(I1)
>> I2 = mat2gray(I1);
>> figure,imshow(I2)
nlfilter

D = nlfilter(S,[m n],fun,P1,P2, )
D = nlfilter(S,[m n],fun,P1,P2, )
. ,
[m n] ,
, fun. P1,P2 , fun.

9.
fun
,
.
, ,

,

. 'AverageWithTh'
m- .
1. m- :
File/New/m-file
2. :
function R = AverageWithTh(x,Th); %
[r c] = size(x);
n = r*c;
r = floor((r+1)/2); c = floor((c+1)/2);
s = sum(x(:))/n;
if (abs(x(r,c)s))>Th
R = s;
else
R = x(r,c);
end;
end;
3. .
4.
.
5. ,
, :
>> [X,map] = imread('c:\Image\Mona.bmp');
>> I = im2double(ind2gray(X,map));
>> figure,imshow(I)
>> I1 = imnoise(I,'salt & pepper');
>> figure,imshow(I1)
>> I2 = nlfilter(I1,[3 3],'AverageWithTh',0.2);
>> figure,imshow(I2)
2.
.
1. Earth.bmp,
, , ,

.
.
2. Bigbird.bmp:
) :
- -
1 1 1 1 1 1 1 1 1 1 1 1
1 2 1 1 2 1 1 2 1 1 2 1
1 1 1 1 1 1 1 1 1 1 1 1

- -
1 1 1 1 1 1 1 1 1 1 1 1
1 2 1 1 2 1 1 2 1 1 2 1
1 1 1 1 1 1 1 1 1 1 1 1
, ,

;
) :
0 1 0 1 1 1 1 2 1
1 4 1 1 8 1 2 4 2
0 1 0 1 1 1 1 2 1
.
3. Technlgy.bmp, ,
. .

.
4. 'Bike.bmp', ,
.
,
.
.
5. ,
, .
6. (
'butterfly.bmp' : a) (0.01);
) v = 0.5 , m = 0.5.
3.
1.
fspecial?
2. ?
3. ?
4.
?
5.
imnoise?
6. freqz2?
7.
?
8.
?
7.
,
.
1.

, .
,
. . 1
.

. 7.1
f(v,v)
(v,v)
h(,): z(x,y) = f(v,v)h(x,y) n(x,y),
, g(x, y)
,
n(x, y).


r(x, y), J:
J = [f ( x , y) g ( x , y ) r ( x , y ) ]2 .
J
f(x, y)
,

:
Wg ( u , v) R ( u , v) = Wgf ( u , v) ,
Wg ( u , v ) ; R ( u , v )
; Wgf ( u , v ) -
g f .

Wgf ( u , v )
R (u , v) = .
Wg ( u , v )
:
H* ( u , v)
R ( u , v) = ,
2 Wn ( u , v )
H( u , v) +
Wf ( u , v )
H ( u , v ) ; ()*
; Wf ( u , v ), Wn ( u , v )
.
.

(/), , .

, .


x 2 + y2
h ( x , y ) = exp ,

2 2


[ ]
H ( u , v ) = exp 2 2 ( u 2 + v 2 ) ,
.

1. ,
, :
[X,map] = imread('c:\Image\Athena.bmp');
I = im2double(ind2gray(X,map));
figure,imshow(I)
title('original image')
[f11,f22] = freqspace([15 15],'meshgrid');
a = 1;
H = exp(a^2.*(f11.^2+f22.^2));
h = fsamp2(f11,f22,H,[5,5]);
Id = conv2(I,h,'same');
figure,imshow(Id)
title('defect image')
k = 1e4;
[HT,f1,f2] = freqz2(h,[5 5]);
HV = conj(HT)./(abs(HT).^2+k);
hv = fsamp2(HV);
Ir = conv2(Id,hv,'same');
figure,imshow(Ir)
title('restore image')
IPT , ,
deconvwnr.

Ir = deconvwnr(Id, h, k),
Id ; h
; k
. / k = 0
(. . ).
Athena.bmp

:
>> Ir = deconvwnr(Id, h, k);


.

^
f ( x , y ) = L[g ( x , y ) ]
( L ),
. -

:
1/ 2

1
H p (u, v) = .
H( u , v) + n
2 W ( u , v )
Wf ( u , v )
2.
1. construc.bmp,
, .
2. -
,
,
,
/ .
3.
1. ?
2. ?
3.
?
4. ,
?
8.
,
.
1.

{ }
a i , j , t b0 b1
. ,
:
a i, j t
{a i, j } = bb0, a i, j > t
.
1,
t c
.
, .
,
.

.

( ).
(I > threshold), ,
(I < threshold) .

, ,
,
.
.
1.
(
).
2. .
: G1 G2. G1 ,
, G2 ,
.
3. S1 S2 G1 G2.
4. = 1 / 2 (S1 + S2).

2- 4-,
.

1. Athena.bmp
.
>>[X,map]=imread('c:\image\Athena.bmp');
>> I=im2double( ind2gray(X,map));
>> figure,imshow(I)
>> T = 0.5*(min(I(:)) + max(I(:)));
>> done = false;
>> while ~done
g=I>= T;
Tnext = 0.5*(double(min(I(g))) + double(max(I(~g))));
done = abs(T - Tnext) < 0.5;
T = Tnext;
end
>> bw = I> T;
>> figure, imshow(bw)
graythresh
IPT, .

T = graythresh(S),
S ; T
[0 1].

2. bike.bmp
graythresh.
>> rgb = imread(c:\Image\bike.bmp);
>> I= im2double(rgb2gray(rgb));
>> figure,imshow(I)
>> T = graythresh(I);
>> Bw=I > T;
>> figure, imshow(Bw)

3.
, Technlgy.bmp.
>> [X,map] = imread('C:\Image\Earth.bmp' );
>> I = ind2gray(X,map);
>> figure,imshow(I)
>> T=graythresh(I);
>> BW = A < T;
>> figure,imshow(BW)
MatLab
im2bw.

BW = im2bw(I, threshold)
BW = im2bw(X, map, threshold)
BW = im2bw(RGB, threshold)
im2bw ,
threshold.
. threshold
[0,1]. threshold = 0.5.
graythresh.

4.
Technlgy.bmp:
a) :
>> [X,map] = imread('c:\Image\Technlgy.bmp');
>> figure,imshow(X,map)
>> BW = im2bw(X,map);
>> figure,imshow(BW)
) graythresh:
>> [X,map] = imread('c:\Image\Technlgy.bmp');
>> I = im2double(ind2gray(X,map));
>> figure,imshow(I)
>> T = graythresh(I);
>> BW = im2bw(I,T);
>> figure,imshow(BW)

- .

.

.

.
.
.
2.
1. Construc.bmp
.
2. Construc.bmp.
3. Athena.bmp
3.
1. ?
2. ?
3.
MatLab?
9.

,
,
.
1.
,
.
,
.
MatLab , , 1,
, , 0, .

(, )
: ( + 1, ), ( 1, ), (, + 1), (, 1).
x1, x3, x5, x7,
, N4():
x4 x3 x2
x5 x1
x6 x7 x8

(, ),

, (, ) .

( + 1, + 1), ( + 1, 1), ( 1, + 1), ( 1, 1)
ND().
-,
N8(). ND() N8()
, (, ) .

,
, 1
.
,
, 1
.
.

.
. .

( )
( 1),
Z2 ( ).

MatLab:
OR (|)
Z = {z : z X or z Y} = X Y ;
AND (&)
Z = {z : z X , z Y} = X \ Y ;
NOT (~) Z = ZC = {z : z X};
DIFFERENCE (X & ~Y) X Y
Z = {z : z X , z Y} = X \ Y .
MatLab, ,
. 9.1.
9.1 MatLab
MatLab


XY &Y AND
XY X|Y OR
~
X NOT
X\Y X & ~Y DIFFERENCE

Z ,

^
Z = {z : z = X , z Z}.
( ) Z x = (x1, x2)
(Z)x
( Z) X = {z : z = z + x , z Z}.

, .
,
1 2, .
strel
strel
.

se = strel(shape, parameters),
se ; shape ,
; parameters ,
.
. 9.2
.
9.2

strel

R
se = strel('diamond',

R)

R
se = strel('disk', R)

LEN , DEG
se = strel('line', LEN,

DEG)
( )
:
OFFSET
se = strel('pair', ,

OFFSET)

OFFSET
MN
se = strel('rectangle', .

MN) MN(1) , MN(2)

NH00D ,
se = strel(NHOOD)

strel strel-
. getsequence.

decomp = getsequence(se)
,
decomp.

.
.
.

.

X B

Y = XB = {x : ( B) x X = },
.
X B ,
X.
imerode IPT.

D = imerode(S, se),
S ; se
, .
1. erode.bmp.
.
,
,
, ,
.
>> [x,map] = imread('c:\image\erode.bmp');
>> I=im2double(ind2gray(x,map));
>> figure,imshow(I)
>> T=graythresh(I);
>> BW = I>T;
>> figure,imshow(I)
>> se = ones(15);
>> se(15,15) = 0;
>> se(15,1) = 0;
>> se(1,15) = 0;
>> se(1,1) = 0;
>> BW1 = imerode(BW,se);
>> figure,imshow(BW1)
>> se = ones(18);
>> se(18,18) = 0;
>> se(18,1) = 0;
>> se(1,18) = 0;
>> se(1,1) = 0;
>> BW1 = imerode(BW,se);
>> figure,imshow(BW1)
>> se = ones(60);
>> se(60,60) = 0;
>> se(60,1) = 0;
>> se(1,60) = 0;
>> se(1,1) = 0;
>> BW1 = imerode(BW,se);
>> figure,imshow(BW1)


, , (dilatation),
:
^
Y = X B = {x : ( B) x X }.
imdilate IPT.

D = imdilate (S, se),
S , se
, .
2. TextRoman.bmp.
>> I = imread('c:\Image\TextRoman.bmp');
>> bw = I>150;
>> figure,imshow(bw)
>> se = [0 1 0;1 1 1;0 1 0];
>> bw1 = imdilate(bw,se);
>> figure,imshow(bw1)

,

. ,
r ,
2r.
, h,
,
, .

3. cgc.bmp,
30
r = 15.
>> f1 = imread('c:\Image\cgc.bmp');
>> I=im2double(rgb2gray(f1));
>> T=graythresh(I);
>> bw=I<T;
>> figure,imshow(bw)
>> title('original')
>> r=15;
>> se = strel('disk', r)
>> bw1 = imerode(bw,se);
>> figure,imshow(bw1)
>> title('rezult')


.


, :
Y = X B = (X B) B.
.
, :
Y = X B =(X B) B.
imopen
imclose .

D = imopen(S, se)
D = imclose(S, se),
S ; se
, .

4. Ex4.bmp,
.
>> [x,map]= imread('C:\Image\Ex4.bmp');
>> figure,imshow(x,map)
>> I=im2double(ind2gray(x,map));
>> T=graythresh(I);
>> bw=im2bw(I,T);
>> figure,imshow(bw), title('bw')
>> R=18, se = strel('disk', R);
>> bwo=imopen(bw,se);
>> figure,imshow(bwo)
>> r=int2str(R);
>> s=cat(2,'bwo-',r)
>> title(s)
>> R=5;
>> se = strel('disk', R);
>> bwcl=imclose(bwo,se);
>> figure,imshow(bwcl)
>> r=int2str(R);
>> s=cat(2,'bwcl-',r)
>> title(s)



. ,
, . ,
, () .
g (mask), f (marker), g f
.
1. hi f.
2. = ones(3).
3. : h i+k = (h k B) g , hi+k = hk.

f g, . . f g.
imreconstruct IPT .

out = imreconstruct(marker, mask),
marker -; mask -.
5. TextRoman.bmp ,
.
>> I = imread('c:\Image\TextRoman.bmp');
>> I=im2double(I);
>> T=graythresh(I);
>> bw=I>T;
>> figure,imshow(bw)
>> title('original')
>> bwr = imopen(bw, ones(3, 1));
>> figure,imshow(bwr)
>> title('razmikanie')
>> bwR = imreconstruct(bwr, bw);
>> figure,imshow(bwR)
>> title('Rezult')

bwmorph

, bwmorph.

BWD = bwmorph(BWS, operation, n)
bwmorph BWD
BWS n (
n = 1).
. 9.3.
.
,
, ,
.
,
,
, 0.
1,
, , 1.
bwmorph
3 3 :
1 1 1
1 1 1 .

1 1 1

.
9.3 bwmorph



.
erode

. ,
dilate

.
open . ,

.
close .
,
.
tophat

.
bothat

.
skel
,
.
thin

.
shrink

thicken

6.
.
, . 10
. BW2.
BW2 ( ).
BW1 & BW2
.
>> R = imread('c:\Image\cgc.bmp');
>> I = im2double(rgb2gray(R));
>> T=graythresh(I);
>> BW1 = I<T;
>> figure,imshow(BW1)
>> BW2 = bwmorph(BW1,'erode',10);
>> figure,imshow(BW2)
>> title('erode')
>> BW3 = bwmorph(BW2,'thicken',inf);
>> figure,imshow(BW3)
>> title('thicken')
>> BW4 = BW1&BW3;
>> figure,imshow(BW4)
>> title('Rezult')
2.
1. ,
, h.
, : a)
h = [0 3]; ) h = [3 0].
strel 'pair'.
2. Cgc.bmp,
100.
3.
1. ?
2.
?
3. ?
4.
?
5. ?
6. IPT ,
, ?
10.
, ,
,
.
1.

() .
.
() ,
.
, , .
: , .

, , , .




. ,

,
(,
). regiongrow,
.

[g, NR, SI, TI] = regiongrow(f, S, T),
f , S (
f) . S , 1
, 0
. S , ,
. ,
( , f) . ,
f.
.

1. regiongrow.
function [g, NR, SI, TI] = regiongrow(f, S, T)
if numel(S) == 1
SI = f == S;
S1 = S
else
SI = bwmorph(S, 'shrink', Inf);
J = find(SI);
S1 = f(J);
end
TI = false(size(f));
for K = 1:length(S1)
seedvalue = S1(K);
S = abs(f - seedvalue) <= T;
TI = TI | S;
end
[g, NR] = bwlabel(imreconstruct(SI, TI));

2.
, Finance.bmp,
regiongrow.
[x,map] = imread('c:\image\Finance.bmp');
I = im2double(ind2gray(x,map));
figure,imshow(I)
S = 0.9783; T = 0.0651; % (
)
[g, NR, SI, TI] = regiongrow(I, S, T);
figure,imshow(TI)
. MatLab,
, .

,
.

qtdecomp

A = qtdecomp(I,threshold,mindim)
qtdecomp
. qtdecomp 4
.
. ,
4 , . . ,
. ,
qtdecomp ,
. A = qtdecomp(I,threshold,mindim)
I
( sparse MatLab).
A(r,c),
I, ,
. ,

threshold. mindim .
-
qtgetblk

[vals, idx] = qtgetblk(I, A, dim)
vals dim,
I
qtdecomp. ,
- .
, vals, idx.
dim,
vals .
qtsetblk

ID = qtsetblk(IS, A, dim, vals)
ID,
dim,
qtdecomp, vals.
, -
.
.
qtdecomp qtgetblk
qtsetblk 8 8 .
uint8. ,
, 10
. .
.
, ,
50. ,
, , 1, ,
, 0.

3.
.
:
>> I = [ 10 11 10 15 20 25 47 51
11 14 17 13 27 29 52 55
12 13 11 10 24 47 56 60
13 14 11 13 49 54 74 77
15 16 43 48 79 82 87 86
17 18 45 50 85 80 80 84
29 51 50 59 80 83 83 85
59 61 58 61 81 85 86 88 ];

: 2 2;
, ,
10 .
>> A = qtdecomp(I,10,2);

full.
>> M = full(A)
M=
40002020
00000000
00002020
00000000
20204000
00000000
20200000
00000000

2 4 4 (
8 2 2).
: 8, 4, 2.
>> dim = 8;
>> while dim> = 2
% blocks dim.
[blocks,idx] = qtgetblk(I,A,dim);
[x y n] = size(blocks);
% -,
if n>0
% dim
for j = 1:n
% 50
if (mean2(blocks(:,:,j))<50)
% 1,
blocks(:,:,j) = ones(dim,dim);
else
% 0.
blocks(:,:,j) = zeros(dim,dim);
end;
end % end for
% dim
I = qtsetblk(I,A,dim,blocks);
end; % end if
dim = dim/2;
end % end while % 1
% I
>> I
I=
11111100
11111100
11111100
11111100
11110000
11110000
00000000
00000000

4.
cotton3.bmp
rgb = imread('c:\Image\cotton3.bmp');
I = im2double(rgb2gray(rgb));
figure,imshow(I)
T=graythresh(I);
A = qtdecomp(I,0.1,2);
dim = 8;
while dim >= 2
[blocks,idx] = qtgetblk(I,A,dim);
[x y n] = size(blocks);
if n>0
for j = 1:n
if (mean2(blocks(:,:,j))<T)
blocks(:,:,j) = ones(dim,dim);
else
blocks(:,:,j) = zeros(dim,dim);
end
end
I1 = qtsetblk(I,A,dim,blocks);
end
dim = dim/2;
end
figure,imshow(I1)

roicolor

BW = roicolor(S,low,high)
BW = roicolor(S,v)
roicolor
:
BW(r, c) 1, S(r, c)
S(r, c)
[low, high] v.
BW(r, c) 0.

5. chip.bmp,
.
>> [x,map]=imread('C:\Image\chip.bmp');
>> figure,imhist(x,map),title('histogramma')
>> figure,imshow(x,map),
>> bw=roicolor(x,9,12);
>> figure,imshow(bw),title('9 - 12')
>> x1=immultiply(bw,x);
>> figure,imshow(x1,map),title('9 - 12')
>> bw=roicolor(x,3,8);
>> figure,imshow(bw),title('3 - 8')
>> x1=immultiply(bw,x);
>> figure,imshow(x1,map),title('3 - 8')

:
0 A B < Ai, j < A H
A i , j
Bi , j =
A i , j A H A i , j A B
0 A B < A i, j < A H
Bi , j = ,
K A H A i , j A B
;
.
impixel.

P = impixel(S,c,r)
impixel ,
c r
.

6.
cotton3.bmp.
[img] = imread('c:\Image\cotton3.bmp');
[m,n,k] = size(img)
img = im2double(img);
R = zeros(m,n,3);
z = [0.1,0.8;0.1,0.8; 0.1,0.9];
for y = 1:m
for x = 1:n
b = impixel(img,x,y);
if ((b(1)>= z(1,1))&(b(1)<= z(1,2)))& ((b(2)>= z(2,1))&(b(2)<= z(2,2)))
& ((b(3)>= z(3,1))&(b(3)<= z(3,2)))
R(x,y,1) = b(1); R(x,y,2) = b(2); R(x,y,3) = b(3);
else
R(x,y,1) = 0; R(x,y,2) = 0; R(x,y,3) = 0;
end
end
end
figure, imshow(img)
figure, imshow(R)
2.
1. Clouds.bmp
.
2. Construc.bmp
.
3. bike.bmp,
.
4.
bike.bmp, r 0.2 0.8; g 0.2 0.7; b 0.1 0.7.
3.
1. ?
2. ?
3. ,
?
4. ,
?
5.
?
6. ?
7. impixel?
11.

,
,
.
1.

, : ,
, , , .
MatLab,
,
: , ,
.
bwselect

BWD = bwselect(BWS,n)
BWD = bwselect(BWS,,r,n)
BWD = bwselect(BWS,n) BWS

(, ,
).
. Backspace Delete.

. Enter
.
Enter,
BWD.
BWD = bwselect(BWS,,r,n) BWS
BWD c
c r.
n bwselect
. 4 8 ( n = 8).
bwlabel

[L,num] = bwlabel(BW,n)
bwlabel BW
L. ,
1, , 2 . . ,
0, . num
, BW. n
, .
4 8 ( n = 8).
imfeature

feats = imfeature(L,measurement,n)
,
L bwlabel.
feats.

imfeature
: (. 11.1),
(. 11.2), (. 11.3),
(. 11.4) .
11.1
measurement

'Image'



'FilledImage'

''

'ConvexImage'
,

11.2


measurement
[x y width height], (x y)

'BoundingBox' ; width

; height

, 2;
'ConvexHull'
(x, y)

8 2
'Extreme'

N 2 ;
'PixelList'
(x, y)
11.3
measurement
'Area' :

'FilledArea'
FilledImage
:
'ConvexArea' , .
ConvexImage
11.4
measurement
:
'Solidity' Area
: ConvexArea
:

'Extent' :
Area
width height

'Eccentricity'


: 'Centroid'
; 'EquivDiameter' Area;
'MajorAxisLength' ; 'MinorAxisLength'
; 'Orientation'
; 'EulerNumber' :
L
.

1. ,
cgc.bmp .
:
cgc.bmp ,
, :
rgb = imread ('c:\Image\cgc.bmp');
I=im2double(rgb2gray(rgb));
I=max(I(:))-I;
figure, imshow (I);
raz.txt c:
info = imfinfo ('c:\Image\cgc.bmp');
[F, mes] = fopen ('c:\raz.txt', 'wt');
fprintf (F, '%d %d', info.Width, info.Height);
fclose (F);
,
:
bw = bwselect (I);
figure, imshow (bw);
L num,
'num.txt' :
[L, num] = bwlabel (bw);
[F, mes] = fopen('c:\num.txt', 'wt');
fprintf (F, '%d ', num);
fclose (F);
:
feats = imfeature (L, 'Image','Solidity');
'k1.txt' :
[F, mes] = fopen('c:\k1.txt', 'wt');
for i = 1:num
fprintf (F, '%5.3f ', feats (i).Solidity);
end;
fclose (F);
:
for i = 1:num
figure,imshow(feats(i).Image);
end;
:
for i = 1: 1: num
ch = int2str (i);
ch1 = 'c:\f';
ch2 = '.bmp';
str = strcat (ch1, ch, ch2);
imwrite (feats (i).Image, str);
end;
2.
1. Ex4.bmp,
, ,
, .
3.
1.
bwselect?
2. ?
3. imfeature?
4.
imfeature?
5.
imfeature?
6.
imfeature?
7.
imfeature?
8. imfeature
?
12.


.
1.

1.

Y = fft2(X)
Y = fft2(X,m.n)
Y = fft2(X) ()
Y, ,
X.
Y = fft2(X,m.n) m n,
.
Y m n.
Y double.
:
fft(fft(x).')'.
, .
2.

Y = ifft2(X)
Y = ifft2(X,m,n)
Y = ifft2(X) ,
Y, , X.
Y = ifft2(X,m,n)
m n,
. Y m n.

1. :
,
, I = sin(2*pi*x/8)+sin(2*pi*y/16); :
>> [x,y] = meshgrid(1:32);
>> I = sin(2*pi*x/8)+sin(2*pi*y/16);
>> figure,imshow(mat2gray(I);
>> figure,surf(x,y,I);
>> colormap(gray)
>> shading interp
(
, ,
).
>> h = fft2(I);
>> figure,surf(x,y,abs(h));
>> colormap(gray)
>> shading interp

:
>> h(1:32,1:2) = 0;
>> figure,surf(x,y,abs(h));
>> colormap(gray)
>> shading interp
>> I = ifft2(abs(h));
>> figure,imshow(mat2gray(I));
>> figure,surf(x,y,abs(I));
>> colormap(gray)
>> shading interp



.
, .

, .
-
, ,

,
.

. . 12.1
.

F(u,v) F(u,v)

f(x,y) f(x,y)

S(u,v)

. 12.1
,

1 + ( 1) v + u
S( u , v ) = ,
2
( )

, :
^ 1 N N
f ( x , y) = f ( x , y ) + f ( x + , y + ) .
2 2 2
2.

.
. 'Technlgy.bmp',
. ,
,
( )
.
.
>>[X,map] = imread('C:\Image\Technlgy.bmp');
>> I = ind2gray(X,map);
>> figure,imshow(I)
>> [M N] = size(I);
>> rect = [floor(N/2), floor(M/2), floor(N/2)1, floor(M/2)1];
>> I1 = imcrop(I,rect);
>> IM = zeros(floor(M/2),floor(N/2));
>> IP = [I1,IM];
>> IN = zeros(floor(M/2),N);
>> IR = [IP;IN];
>> figure,imshow(IR)
>> D = I+IR;
>> figure,imshow(D)
2.
1. ,
, 'Athena.bmp',

.
2.
,
, ''Athena.bmp',
.
3.
1.
MatLab?
2. ?
.


1. , .. matlab 5x [] / ..
, .. ; . . .. . .: ,
2000. 416 c.
2. , . matlab [] /
. , . , . ; . . .. . .: ,
2006. 512 .
3. , .. []: . /
.. . : , 2006. 95 .
4. , . [] / ;
. ., . .. . 2- . .: -, 2007.
653 .

Оценить