Search code examples
matlabroundinghistogramangle

Strange pattern on atand results distribution


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.


Solution

  • 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.

    • Peak at 0 reflecting pixels that are either stationary or move toward the right
    • Peaks at +/- 45 and 90 degrees reflecting particles moving one pixel up/down or along the diagonal.
    • More peaks for moving e.g. 2 to the right, one to the top

    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.