0001 function [mergeCells_ splitCells_ splitCells] = collision_prob(tracks,frames)
0002
0003
0004 dtable = Inf(length(tracks),length(tracks));
0005 Pb = zeros(length(tracks),length(tracks));
0006 mergeCells_ = [];
0007 splitCells_ = [];
0008 splitCells = [];
0009 collideSet = [];
0010
0011 for tr=1: length(tracks)
0012
0013 if (strcmp(tracks(tr).Type,'ACTIVE')==1)
0014 for trr = tr+1: length(tracks)
0015 if (strcmp(tracks(trr).Type,'ACTIVE')==1)
0016 dtable(tr,trr) = sqrt((tracks(tr).x_(1) - tracks(trr).x_(1))^2 + (tracks(tr).x_(2) - tracks(trr).x_(2))^2);
0017
0018 if (dtable(tr,trr) < 50) && (strcmp(tracks(trr).Type,'NEW')~=1) && (strcmp(tracks(tr).Type,'NEW')~=1)
0019 im1 = func_Drawline(zeros(1000,1000),round(tracks(tr).x(2)),round(tracks(tr).x(1)),round(tracks(tr).x_(2)),round(tracks(tr).x_(1)),1);
0020 im2 = func_Drawline(zeros(1000,1000),round(tracks(trr).x(2)),round(tracks(trr).x(1)),round(tracks(trr).x_(2)),round(tracks(trr).x_(1)),1);
0021
0022 im1 = bwdist(im1);
0023 im2 = bwdist(im2);
0024
0025 d1= exp(-im1.^2./42);
0026 d2= exp(-im2.^2./42);
0027
0028 score = d1.*d2;
0029
0030 [tmax ind] = max(score);
0031 [Pb(tr,trr) xc]= max(tmax);
0032 yc = ind(xc);
0033
0034
0035 frame = tracks(tr).Cells(end).Frame;
0036 id = [tracks(tr).Id tracks(trr).Id];
0037 area = tracks(tr).Cells(end).Area + tracks(trr).Cells(end).Area;
0038 shape= (tracks(tr).Cells(end).Shape + tracks(trr).Cells(end).Shape)/2;
0039 mergeCell = WBC(frame,id,yc,xc,area,shape);
0040 mergeCell.Status = [tracks(tr).Cells(end) tracks(trr).Cells(end)];
0041 mergeCells_ = [mergeCells_; mergeCell];
0042 end
0043 end
0044 end
0045 end
0046
0047
0048 if (strcmp(tracks(tr).Type,'COLLIDE')==1) && ~ismember(tracks(tr).Id, collideSet)
0049
0050 collideSet = [collideSet tracks(tr).Id];
0051 trr = searchTrack(tracks,tracks(tr).CoId);
0052 if trr==0
0053 trr = tr;
0054 end
0055 collideSet = [collideSet tracks(trr).Id];
0056 splitCell = WBC(tracks(tr).Cells(end).Frame,[tracks(tr).Id tracks(tr).CoId],0,0,0,0);
0057 col = tracks(tr).Cells(end).Col + tracks(tr).svec(1);
0058 row = tracks(tr).Cells(end).Row + tracks(tr).svec(2);
0059 area = tracks(tr).CoRec(1).Area;
0060 c1 = WBC(0,0,row,col,area,0);
0061
0062 try
0063 col = tracks(trr).Cells(end).Col + tracks(trr).svec(1);
0064 catch
0065 pause();
0066 end
0067 row = tracks(trr).Cells(end).Row + tracks(trr).svec(2);
0068 area = tracks(trr).CoRec(1).Area;
0069 c2 = WBC(0,0,row,col,area,0);
0070 splitCell.Status = [c1 c2];
0071 splitCells_ = [splitCells_; splitCell];
0072
0073
0074 fr = tracks(tr).Cells(end).Frame+1;
0075 frame = frames(fr);
0076 ce_list = [];
0077 for ce = 1:frame.nCells
0078 dtable(tr,ce) = sqrt((tracks(tr).x_(1) - frame.Cells(ce).Col)^2 + (tracks(tr).x_(2) - frame.Cells(ce).Row)^2);
0079 if (dtable(tr,ce) < 100)
0080 ce_list = [ce_list; ce];
0081 end
0082 end
0083
0084 for ce = 1:size(ce_list,1)
0085 for cee = 1:size(ce_list,1)
0086
0087 if (ce~=cee)
0088 id = [frame.Cells(ce_list(ce)).Id frame.Cells(ce_list(cee)).Id];
0089 splitCell = WBC(fr,id,0,0,0,0);
0090 ce1 = ce_list(ce);
0091 ce2 = ce_list(cee);
0092 splitCell.Status = [frame.Cells(ce1) frame.Cells(ce2)];
0093 splitCells = [splitCells; splitCell];
0094 end
0095 end
0096 end
0097 end
0098 end
0099
0100 if isempty(splitCells) || isempty(splitCells_)
0101 splitCells = [];
0102 splitCells_ = [];
0103 end
0104
0105
0106
0107
0108