forked from sc65/CellTracker60X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircles2cells.m
54 lines (39 loc) · 1.11 KB
/
circles2cells.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 cellCenters=circles2cells(centers,radii)
ratio_cutoff = 2.0; %SC
cc=centers;
rr=radii';
ncirc=length(rr);
dists = ipdm(cc);
dist_ratios = dists./rr(ones(ncirc,1),:);
counted = zeros(ncirc,1);
q=1;
inds = find(dist_ratios < ratio_cutoff);
[px, py]=ind2sub(size(dist_ratios),inds);
qq=1;
while sum(counted) < ncirc
q=find(counted==0,1,'first');
groups{qq}=q;
[indstoadd, locp]=ismember(groups{qq},px);
locp = locp(locp>0);
while sum(indstoadd) > 0
groups{qq}=unique([groups{qq}, py(locp)']);
counted(py(locp))=1;
px(locp)=[]; py(locp)=[];
[indstoadd, locp]=ismember(groups{qq},px);
locp = locp(locp>0);
end
[indstoadd, locp]=ismember(groups{qq},py);
locp = locp(locp > 0);
while sum(indstoadd) > 0
groups{qq}=unique([groups{qq}, px(locp)']);
counted(px(locp))=1;
px(locp)=[]; py(locp)=[];
[indstoadd, locp]=ismember(groups{qq},py);
locp = locp(locp>0);
end
qq=qq+1;
end
cellCenters = zeros(length(groups),2);
for ii=1:length(groups)
cellCenters(ii,:)=mean(cc(groups{ii},:),1);
end