I have tracks of particles, obtained after tracking them on an image sequence (20 particles, 3500 frames). I need to get a distribution of velocities vectors angles of these particles. Positions of the particles on each frame are stored in matrices tracksX
and tracksY
, 3500x20 double each. Here is the code I'm using:
speedX = diff(tracksX);
speedY = diff(tracksY);
angles = atand(speedY./speedX);
anglesh = angles(:);
figure(1); hist(anglesh,360);
However, I am getting a strange symmetrical pattern on the histogram, with a huge peak in a [-0.5, 0] bin and zero angles in [0, 0.5] bin. I don't have enough rep to add an image, so here is a link to it Weird distribution figure
Could it happen because of some rounding that Matlab performs? How to fix it? The particles movement is somewhat random with a tendency to move in X direction, corresponding to 0° - 20° bins, so I highly doubt this pattern could appear from the initial data.
Let me guess: positions are in pixels, and the particles do not move very many pixels between time points?
What you're seeing are a bunch of discretization artifacts.
Depending on your data, you might be able to perform some fitting of particle positions to estimate sub-pixel localization (though you should be careful to set it up correctly to avoid pixel-locking), or you could use artificially larger time steps (e.g. take differences between 1st-4th, 2nd-5th, 3rd-6th time points to make the histogram) to make this look a bit more sensible.