-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackingMSD.m
51 lines (45 loc) · 1.23 KB
/
trackingMSD.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
function [MSD, totalDistance] = trackingMSD(imageObj, track)
MSD = [];
pixels = imageObj.getPrimaryPixels;
physX = pixels.getPhysicalSizeX;
physY = pixels.getPhysicalSizeY;
physZ = pixels.getPhysicalSizeZ;
if isempty(physX)
physX = 1;
else
physX = physX.getValue;
end
if isempty(physY)
physY = 1;
else
physY = physY.getValue;
end
if isempty(physZ)
physZ = 1;
else
physZ = physZ.getValue;
end
%Check for z dimension in the tracking data
zDim = 1;
try
checkZ = track.cmso_z_coord(1);
catch
zDim = 0;
end
[numSegments, ~] = size(track);
segmentDistances = zeros(numSegments-1,1);
for thisSegment = 1:numSegments-1
x1 = track.cmso_x_coord(thisSegment);
x2 = track.cmso_x_coord(thisSegment+1);
y1 = track.cmso_y_coord(thisSegment);
y2 = track.cmso_y_coord(thisSegment+1);
if zDim
z1 = track.cmso_z_coord(thisSegment);
z2 = track.cmso_z_coord(thisSegment+1);
segmentDistances(thisSegment) = sqrt(((x1-x2)*physX)^2 + ((y1-y2)*physY)^2 + ((z1-z2)*physZ)^2);
else
segmentDistances(thisSegment) = sqrt(((x1-x2)*physX)^2 + ((y1-y2)*physY)^2);
end
end
MSD = nanmean(segmentDistances);
totalDistance =nansum(segmentDistances);