-
Notifications
You must be signed in to change notification settings - Fork 0
/
Skel_Analysis.m
93 lines (67 loc) · 1.84 KB
/
Skel_Analysis.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
close all;
clear all;
for i = 0:0
filePath = [ 'ellipse_flow__t_' num2str( i ) '.mat' ];
bwImg = load( filePath );
bw = bwImg.ellipseImg_p;
%
% figure;
% imshow( bw );
bwF = imfill( bw );
% figure;
% imshow( bwF );
se = strel('disk', 40 );
bwF_s = imclose( bwF, se );
bwG = imgaussfilt( bwF_s, 5 );
[ Gmag, Gdir ] = imgradient( bwG, 'intermediate' );
Gdir_mask = Gdir;
Gmag_mask = Gmag;
Gdir_mask( bw == 0 ) = 0;
Gmag_mask( bw == 0 ) = 0;
figure;
imshowpair( Gmag_mask, Gdir_mask, 'montage' );
Gdir_s = imgaussfilt( Gdir, 0.3 );
Gdir_mask = Gdir_s;
Gmag_mask = Gmag;
Gdir_mask( bw == 0 ) = 0;
Gmag_mask( bw == 0 ) = 0;
[ x, y ] = meshgrid( 1:size( Gdir_mask, 2 ), 1:size( Gdir_mask, 1 ) );
u = zeros( size( x ) );
v = zeros( size( x ) );
for xx = 1:size( x, 1 )
for yy = 1:size( x, 2 )
x_u = x( xx, yy );
y_u = y( xx, yy );
theta = Gdir_mask( y_u, x_u );
theta = theta / 180 * pi;
u( xx, yy ) = cos( theta );
v( xx, yy ) = sin( theta );
if theta == 0
u( xx, yy ) = 0;
v( xx, yy ) = 0;
end
end
end
figure;
quiver( x, y, u, v );
% figure;
% imshow( bwF_s );
skel = bwmorph( bwF_s, 'skel', Inf );
% figure;
% imshow( skel );
B = bwmorph(skel, 'branchpoints');
E = bwmorph(skel, 'endpoints');
[y,x] = find(E);
B_loc = find(B);
Dmask = false(size(skel));
for k = 1:numel(x)
D = bwdistgeodesic(skel,x(k),y(k));
distanceToBranchPt = min(D(B_loc));
Dmask(D < distanceToBranchPt) =true;
end
skelD = skel - Dmask;
% figure;
% imshow(skelD);
% hold all;
% [y,x] = find(B); plot(x,y,'ro')
end