0001 function A = vis_velocity_2(SS)
0002 matchedVelocities = [];
0003 for se = 1: length(SS)
0004
0005 matched = extract_match(SS(se).Rich.RMSEx(:,1:3),...
0006 SS(se).Rich.tracks,...
0007 SS(se).GT.tracks);
0008
0009
0010 auVelocities = calc_velocity(matched(:,[2 3 6 7]));
0011 gtVelocities = calc_velocity(matched(:,[1 3 4 5]));
0012
0013 match = match_au_to_ma(auVelocities, gtVelocities, matched(:,1:2));
0014 matchedVelocities = [matchedVelocities; se*ones(size(match,1),1) match];
0015 end
0016
0017
0018
0019 A = sortrows(matchedVelocities,5);
0020 A(:,4) = ppf2mps(A(:,4));
0021 A(:,5) = ppf2mps(A(:,5));
0022 plot(A(:,4),'r');hold on;plot(A(:,5),'g');
0023 xlabel('Cell track segment');
0024 ylabel('Velocity (micron/sec)');
0025 legend('Manual','Automatic','location','NorthWest');
0026
0027
0028
0029
0030 function matchedVelocities = match_au_to_ma(auVelocities, maVelocities, matchChart)
0031 maIds = unique(matchChart(:,1));
0032 matchedVelocities = zeros(length(maIds),4);
0033 for id = 1: length(maIds)
0034 maId = maIds(id);
0035 maVelocity = maVelocities(maVelocities(:,1)==maId,2);
0036 auId = unique(matchChart(matchChart(:,1)==maId,2));
0037 auVelocity = auVelocities(auVelocities(:,1)==auId,2);
0038 matchedVelocities(id,:) = [maId auId maVelocity auVelocity];
0039 end
0040 end
0041
0042 function matched = extract_match(matchChart, auTracks, gtTracks)
0043 gtIds = unique(matchChart(:,1));
0044 matched = [];
0045 for id = 1: length(gtIds)
0046 gtId = gtIds(id);
0047 matchTrack = matchChart(matchChart(:,1)==gtId,:);
0048 auId = unique(matchTrack(:,2));
0049 frIds = matchTrack(:,3);
0050 for fr = 1: length(frIds);
0051 frId = frIds(fr);
0052 gtPosition = gtTracks(gtTracks(:,1)==gtId & gtTracks(:,2)==frId,3:4);
0053 auPosition = auTracks(auTracks(:,1)==auId & auTracks(:,2)==frId,3:4);
0054 matched(end+1,:) = [gtId auId frId gtPosition auPosition];
0055 end
0056 end
0057 end
0058
0059 function velocity = calc_velocity(tracks)
0060 trIds = unique(tracks(:,1));
0061 velocity = zeros(length(trIds),2);
0062 for tr = 1: length(trIds)
0063 trId = trIds(tr);
0064 track = tracks(tracks(:,1)==trId,:);
0065 frIds = unique(track(:,2));
0066 totalDist = 0;
0067 for fr= 1: length(frIds)-1
0068 frId = frIds(fr);
0069 dist = calc_dist(track(track(:,2)==frId,3:4),...
0070 track(track(:,2)==frId+1, 3:4) );
0071 totalDist = totalDist + dist;
0072 end
0073 velocity(tr,:) = [trId totalDist/length(frIds)];
0074 end
0075 end
0076
0077 function dist = calc_dist(p,q)
0078 dist = sqrt( (p(1)-q(1))^2 + (p(2)-q(2))^2);
0079 end
0080
0081 function newVelocity = ppf2mps(velocity)
0082
0083
0084 newVelocity = velocity * 0.8 * 30;
0085 end
0086
0087 end