|
a |
|
b/combinedDeepLearningActiveContour/functions/mask2phi.m |
|
|
1 |
%-- converts a mask to a Signed Distance Function (SDF) |
|
|
2 |
|
|
|
3 |
function phi = mask2phi(mask,m_cnt,I) |
|
|
4 |
|
|
|
5 |
if nargin==3 |
|
|
6 |
[x_max, y_max]=size(I); |
|
|
7 |
M=size(mask,1); |
|
|
8 |
|
|
|
9 |
mask2=zeros(x_max,y_max); |
|
|
10 |
|
|
|
11 |
% coordinates of the top and bottom corners |
|
|
12 |
m_cnt_y=m_cnt(1); |
|
|
13 |
m_cnt_x=m_cnt(2); |
|
|
14 |
|
|
|
15 |
% top left corner |
|
|
16 |
x1=m_cnt_x-M/2; |
|
|
17 |
y1=m_cnt_y-M/2; |
|
|
18 |
|
|
|
19 |
% bottom right corner |
|
|
20 |
x4=m_cnt_x+M/2-1; |
|
|
21 |
y4=m_cnt_y+M/2-1; |
|
|
22 |
|
|
|
23 |
mask2(y1:y4,x1:x4)=mask; |
|
|
24 |
mask=mask2; |
|
|
25 |
end |
|
|
26 |
phi=bwdist(mask)-bwdist(1-mask)+im2double(mask)-.5; |
|
|
27 |
|
|
|
28 |
end |