-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExpandingSegmentation.m
74 lines (48 loc) · 1.24 KB
/
ExpandingSegmentation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
clc;
close all;
clear;
knee=double(imread('knee.png'));
imshow(knee,[]);
title('Select segementation start point');
selected=floor(ginput(1));
selected=[selected(2),selected(1)];
%selected=[277,217];
[Y X]=size(knee);
visited=zeros(Y,X);
segmented=zeros(Y,X);
stacki=zeros(1000,2);
ptr=1;
visited(selected(1),selected(2))=1;
segmented(selected(1),selected(2))=1;
stacki(ptr,:)=[selected(1),selected(2)];
win_size=1;
treshold=4;
while(ptr>0)
w_y=stacki(ptr,1);
w_x=stacki(ptr,2);
stacki(ptr,:)=[0,0];
ptr=ptr-1;
if(Y-win_size>w_y && w_y>win_size && win_size<w_x && w_x<X-win_size)
center=knee(w_y,w_x);
for y=(w_y-win_size):(w_y+win_size)
for x=(w_x-win_size):(w_x+win_size)
if(visited(y,x)==0)
current=knee(y,x);
if(abs(center-current)<=treshold)
ptr=ptr+1;
stacki(ptr,:)=[y,x];
segmented(y,x)=1;
end
visited(y,x)=1;
end
end
end
end
end
figure;
subplot(1,2,1);
imshow(knee,[]);
title('Orginal');
subplot(1,2,2);
imshow(segmented,[]);
title('Segemnted from selected point');