-
Notifications
You must be signed in to change notification settings - Fork 6
/
FindContour.m
34 lines (30 loc) · 927 Bytes
/
FindContour.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
function [objectContour] = FindContour(object)
%%% This code is written by BAMI LAB %%%
% Find binary's contour
% input :
% lung = binary image
%
% output :
% contour = cell array of lung's contour
bw = bwboundaries(object, 'noholes');
obj = regionprops(logical(object));
[~, sidx] = sort([obj.Area], 'descend');
count = size(bw, 1);
if count == 0
contour = [];
else
contour = cell(count,1);
for i=1:count
contourLine = fliplr(bw{sidx(i)});
contourOverlap = contourLine(1, :);
for cc = 2:size(contourLine, 1)
if sum(contourOverlap(:, 1) == contourLine(cc, 1) & contourOverlap(:, 2) == contourLine(cc, 2)) > 0
continue;
else
contourOverlap(end+1, :) = contourLine(cc, :);
end
end
contour{i} = contourOverlap;
end
end
objectContour = contour;