Working with trajectory data in MATLAB

This notebook shows some examples of loading and working with anTraX results in MATLAB. The notebook can be downloaded from https://github.com/Social-Evolution-and-Behavior/anTraX/blob/master/docs/analysis_matlab.ipynb.

Load data from a tracked experiment

We will use data from dataset J16. Replace the path to the correct path on your system. By default, data from all IDs ('ants') and all movies will be loaded, but it can be changed using the arguments.

In [1]:
expdir = '/Users/asaf/Box Sync/anTraX/datasets2upload/J16';
ex = trhandles(expdir);
ad = antdata(ex, 'movlist', 1, 'antlist', {'GO','PP'});
17:23:32 -I- Loading tracking session from expdir
17:23:33 -I- Reading video information from file
In [2]:
head(ad.data)
ans =

  8x3 table

    f                    GO                                     PP                 
            x           y        or     type       x           y        or     type
    _    ___________________________________    ___________________________________

    1    0.038876    0.063685    NaN     4      0.038876    0.063685    NaN     4  
    2    0.038865    0.063683    NaN     4      0.038865    0.063683    NaN     4  
    3    0.038875    0.063679    NaN     4      0.038875    0.063679    NaN     4  
    4    0.038876    0.063675    NaN     4      0.038876    0.063675    NaN     4  
    5    0.038863    0.063664    NaN     4      0.038863    0.063664    NaN     4  
    6    0.038861    0.063666    NaN     4      0.038861    0.063666    NaN     4  
    7    0.038861    0.063663    NaN     4      0.038861    0.063663    NaN     4  
    8    0.038846    0.063657    NaN     4      0.038846    0.063657    NaN     4  

The 'type' column indicate the type of assigment:

(1) single-animal tracklet assigned by the blob classifier

(2) single-animal tracklet assigned by the propagation algorithm

(3) multi-animal tracklet assigned by the propagation algorithm

(4) soft assigment (tracklet that is the only possible one for that ID, but was not assigned by the propagation)

(5) interpolation of coordinates, not corresponding to an actual blob

(NaN) no coordinates

See the anTraX publication for more details.

Plot the trajectories of two ants, with the background image as background

In [3]:
bg = ex.get_bg(1);
scale = ex.get_param('geometry_rscale');
imshow(bg);
hold on
ants = {'PP', 'GO'};
for i= 1:length(ants)
    ant = ants{i};
    x = ad.data.(ant).x/scale;
    y = ad.data.(ant).y/scale;
    plot(x, y, 'linewidth', 2)
end