-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calc_MaxCircle.m
85 lines (64 loc) · 2.08 KB
/
Calc_MaxCircle.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
close all;
clear all;
addpath( 'ellipse' );
%% Read Data
for i = 0:19
filePath = [ 'ellipse_flow__t_' num2str( i ) '.mat' ];
filePtsPath = [ 'ellipse_flow__t_' num2str( i ) '_Pts.mat' ];
fileSkelDPath = [ 'ellipse_flow__t_' num2str( i ) '_skel_0topo.mat' ];
% Read Image
bwImg = load( filePath );
bw = bwImg.ellipseImg_p;
% Read Surface points (Parametrized Curve)
pts = load( filePtsPath );
pts = pts.SourcePts_s;
% Read Estimated Skeleton
% skel = load( fileSkelPath );
% skel = skel.skel;
% Read Estimated Skeleton - Single Line
skelD = load( fileSkelDPath );
skelD = skelD.skelD;
% % Display Object Surface and Skeleton
% surf_skel = imfuse( bw, skel, 'blend', 'Scaling', 'joint' );
% figure;
% imshow( surf_skel );
%% Calculate Initial Maximal Inscribed Circle - Closest Distance to Surface
% Calculate Distance Map
distSurf = bwdist( bw );
% Skeleton Position - Line
skelIdx = [];
for r = 1:size( skelD, 1 )
for c = 1:size( skelD, 2 )
if skelD( r, c ) > 0
skelIdx = [ skelIdx; r, c; ];
end
end
end
% Reconstruct Object Surface by Skeleton + Radii Function
recon = zeros( size( bw ) );
for j = 1:size( skelIdx, 1 )
skel_r = skelIdx( j, 1 );
skel_c = skelIdx( j, 2 );
radius = distSurf( skel_r, skel_c );
recon = MidpointCircle( recon, radius, skel_r, skel_c, 1 );
end
reconRGB = double( cat( 3, recon, recon, recon ) );
for r = 1:size( skelD, 1 )
for c = 1:size( skelD, 2 )
if skelD( r, c ) > 0
reconRGB( r, c, 1 ) = 0;
reconRGB( r, c, 2 ) = 1;
reconRGB( r, c, 3 ) = 0;
end
if bw( r, c ) > 0
reconRGB( r, c, 1 ) = 1;
reconRGB( r, c, 2 ) = 0;
reconRGB( r, c, 3 ) = 0;
end
end
end
imwrite( reconRGB, [ 'ellipse/SingleSkel/ellipse_flow__t_' num2str( i ) '_singleSkel.png' ] );
% figure;
% imshow( reconRGB );
% title( [ 'reconstructed : Img ' num2str( i ) ] );
end