0001 function [report A] = vis_velocity_3(SS)
0002 matchedVelocities = [];
0003 report = zeros(length(SS),9);
0004 ROLLING_VELOCITY = 3;
0005 for se = 1: length(SS)
0006
0007 matched = extract_match(SS(se).Rich.RMSEx(:,1:3),...
0008 SS(se).Rich.tracks,...
0009 SS(se).GT.tracks);
0010
0011
0012 auVelocities = calc_velocity(matched(:,[2 3 6 7]));
0013 gtVelocities = calc_velocity(matched(:,[1 3 4 5]));
0014
0015 match = match_au_to_ma(auVelocities, gtVelocities, matched(:,1:2));
0016
0017 gtRolling = match(match(:,3)>=ROLLING_VELOCITY,:);
0018 gtRollingVelocity = mean(gtRolling(:,3));
0019 gtRollingFraction = size(gtRolling,1)/size(match,1);
0020
0021 gtAdhering = match(match(:,3)<ROLLING_VELOCITY,:);
0022 gtAdheringVelocity = mean(gtAdhering(:,3));
0023 gtAdheringFraction = size(gtAdhering,1)/size(match,1);
0024
0025 auRolling = match(match(:,4)>=ROLLING_VELOCITY,:);
0026 auRollingVelocity = mean(auRolling(:,4));
0027 auRollingFraction = size(auRolling,1)/size(match,1);
0028
0029 auAdhering = match(match(:,4)<ROLLING_VELOCITY,:);
0030 auAdheringVelocity = mean(auAdhering(:,4));
0031 auAdheringFraction = size(auAdhering,1)/size(match,1);
0032
0033 report(se,:) = [se gtRollingVelocity auRollingVelocity...
0034 gtRollingFraction auRollingFraction...
0035 gtAdheringVelocity auAdheringVelocity...
0036 gtAdheringFraction auAdheringFraction ];
0037 matchedVelocities = [matchedVelocities; se*ones(size(match,1),1) match];
0038 end
0039
0040
0041 A = sortrows(matchedVelocities,5);
0042 A(:,4) = ppf2mps(A(:,4));
0043 A(:,5) = ppf2mps(A(:,5));
0044 plot(A(:,4),'r');hold on;plot(A(:,5),'g');
0045 xlabel('Cell track segment');
0046 ylabel('Velocity (pixel / frame)');
0047 legend('Manual','Automatic','location','NorthWest');
0048
0049
0050
0051
0052
0053 function matchedVelocities = match_au_to_ma(auVelocities, maVelocities, matchChart)
0054 maIds = unique(matchChart(:,1));
0055 matchedVelocities = zeros(length(maIds),4);
0056 for id = 1: length(maIds)
0057 maId = maIds(id);
0058 maVelocity = maVelocities(maVelocities(:,1)==maId,2);
0059 auId = unique(matchChart(matchChart(:,1)==maId,2));
0060 auVelocity = auVelocities(auVelocities(:,1)==auId,2);
0061 matchedVelocities(id,:) = [maId auId maVelocity auVelocity];
0062 end
0063 end
0064
0065 function matched = extract_match(matchChart, auTracks, gtTracks)
0066 gtIds = unique(matchChart(:,1));
0067 matched = [];
0068 for id = 1: length(gtIds)
0069 gtId = gtIds(id);
0070 matchTrack = matchChart(matchChart(:,1)==gtId,:);
0071 auId = unique(matchTrack(:,2));
0072 frIds = matchTrack(:,3);
0073 for fr = 1: length(frIds);
0074 frId = frIds(fr);
0075 gtPosition = gtTracks(gtTracks(:,1)==gtId & gtTracks(:,2)==frId,3:4);
0076 auPosition = auTracks(auTracks(:,1)==auId & auTracks(:,2)==frId,3:4);
0077 matched(end+1,:) = [gtId auId frId gtPosition auPosition];
0078 end
0079 end
0080 end
0081
0082 function velocity = calc_velocity(tracks)
0083 trIds = unique(tracks(:,1));
0084 velocity = zeros(length(trIds),2);
0085 for tr = 1: length(trIds)
0086 trId = trIds(tr);
0087 track = tracks(tracks(:,1)==trId,:);
0088 frIds = unique(track(:,2));
0089
0090 firstFr = min(frIds);
0091 lastFr = max(frIds);
0092
0093 totalDist = calc_dist(track(track(:,2)==firstFr,3:4),...
0094 track(track(:,2)==lastFr, 3:4) );
0095
0096
0097 velocity(tr,:) = [trId totalDist/length(frIds)];
0098 end
0099 end
0100
0101 function dist = calc_dist(p,q)
0102 dist = sqrt( (p(1)-q(1))^2 + (p(2)-q(2))^2);
0103 end
0104
0105 function newVelocity = ppf2mps(velocity)
0106
0107
0108 newVelocity = velocity * 1.6 * 20;
0109 end
0110
0111 end