-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge_two_channels.m
More file actions
34 lines (28 loc) · 860 Bytes
/
merge_two_channels.m
File metadata and controls
34 lines (28 loc) · 860 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
function outMap = merge_two_channels(x1, x2, dext, dextz)
% % update the score for each post-synaptic puncta
% dext = 0; % search in XY
% dextz = 0; % search in Z
cc = bwconncomp(x2);
sLst = cc.PixelIdxList; % check each post puncta
postVol = x2;
preVol = x1;
[H1,W1,D1] = size(x1);
outMap = zeros(H1,W1,D1);
for ii=1:numel(sLst)
s0 = sLst{ii};
[h0,w0,d0] = ind2sub([H1,W1,D1],s0);
zPost = mean(postVol(s0));
% find highest pre puncta score
zPre = 0;
for jj=1:numel(h0)
h00 = h0(jj); w00 = w0(jj); d00 = d0(jj);
hrg = max(h00-dext,1):min(h00+dext,H1);
wrg = max(w00-dext,1):min(w00+dext,W1);
drg = max(d00-dextz,1):min(d00+dextz,D1);
preVolCrop = preVol(hrg,wrg,drg);
zPre = max(max(preVolCrop(:)),zPre);
end
% combine scores
outMap(s0) = zPost*zPre;
end
end