-
Notifications
You must be signed in to change notification settings - Fork 1
/
calcSilh.m
52 lines (46 loc) · 1.3 KB
/
calcSilh.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
function [silh]=calcSilh(a,level,aabb)
% Description: An update of Dr. Matt Kay's getsilh.m file. This code is a
% simplification of his function. It identifies the largest connected
% component based on the user input threshold. It also performs
% morphological opening and closing to soften the region.
%
% Inputs:
% a = the image of the heart
% level = the threshold
% aabb = whether the region of interest is above (1) or below (0) the
% threshold
%
% Outputs:
% silh = the binary image resulting from thresholding and morphological
% opening and closing
%
% Author: Christopher Gloschat
% Date: June 21, 2016
%
% Mofidication Log:
%
%
%% Code %%
% Create binary image based on threshold method
if aabb
bw1=a>level;
else
bw1=a<level;
end
% Find largest connected component
CC = bwconncomp(bw1);
biggestCC = zeros(1,length(CC.PixelIdxList));
for n = 1:length(CC.PixelIdxList)
biggestCC(n) = length(CC.PixelIdxList{n});
end
[~,I] = sort(biggestCC,'descend');
biggestCC = CC.PixelIdxList{I(1)};
% Create binary image largest CC
bw1 = zeros(size(a));
bw1(biggestCC) = 1;
% Perform morphological opening (get rid of spurs) and closing (get rid
% of invaginations and holes)
SE = strel('disk',6,0);
bw1 = imopen(bw1,SE);
silh = imclose(bw1,SE);
end