forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathea_centralcomponent.m
More file actions
40 lines (29 loc) · 928 Bytes
/
ea_centralcomponent.m
File metadata and controls
40 lines (29 loc) · 928 Bytes
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
function slicebw=ea_centralcomponent(slicebw,mask,options)
%% determine mask center:
[yy,xx]=find(mask);
maskcenter=[mean(xx),mean(yy)];
stats=ea_conncomp(slicebw);
if stats.NumObjects>1
maxdist=10000;
for i=1:stats.NumObjects
if length(stats.PixelIdxList{i})>10
sliceobj=slicebw;
sliceobj(:)=0;
sliceobj(stats.PixelIdxList{i})=1;
cen=ea_centroid(sliceobj);
dist=ea_pdist([cen.Centroid;maskcenter]);
ea_showdis(['Obj number ',num2str(i),', distance: ',num2str(dist),'.'],options.verbose);
if dist<maxdist
maxdist=dist;
bestobj=i;
ea_showdis(['Using object ',num2str(bestobj),'.'],options.verbose);
end
end
end
if exist('bestobj','var')
slicebw(:)=0;
slicebw(stats.PixelIdxList{bestobj})=1;
else
slicebw=ea_largestcomponent(slicebw);
end
end