40 views (last 30 days)

I am trying to estimate the missing points of a matrix of 2D coordinates obtained from the video of a moving object.

the coordinates are Xv and Yv (see attachment and code below). when plotted with they look like this

as you may notice there are several spurious points in the path which make the x,y coordinates to jump abruptly. I have already cleaned the track removing many spurious data points by cycling through the x,y pairs and imposing a threshold for the max euclidean distance between consecutive points (I called it "step"). I filtered out those points having out of range values (those likely to be part of one of those jumps in the upper figure) and i have also applied a condition to further narrow the data range (a series of 20 consecutive points having steps less than my threshold value (10). Still I detect some spurious data points due to the fact that after a long (easy to detect) jump there are often smaller ones which cannot be filtered using the same criteria (see scatter plot below).

what I would like to get is something like this (see image below, the red lines are drawn manually)

At this point I thought one thing I could do could be to use some interpolation to estimate the missing points (of course there will be some mistake, this is just an estimate).

however the data points are not accepted by the function interp1 because of duplicates (same goes for polyfit).

the "best" result I obtained so far was using a smoothing filter (with the rloess method)... which is still far from what I want to get

by smoothing the data I do not solve it either because the spuroius points are still too dense (so even extending the smoothing over a wider sliding window does not help)

this is my code

X= x(2000:2200); % selects a segment of larger coordinate vector

Y= y(2000:2200);

th=15; % threshold for detecting spurious locations

% preset variables

speed=[];

path=[];

spurious = [];

valid = [];

rate1=[];

rate2=[];

for i = 1:length(X)-1

step = [X(i),Y(i);X(i+1),Y(i+1)];

d = pdist(step,'euclidean'); % distance of consecutive points

v = d/(ms(i+1)-ms(i));

rate1=[rate1,(step(2,1)-step(1,1))/(ms(i+1)-ms(i))];

rate2=[rate2,(step(2,2)-step(1,2))/(ms(i+1)-ms(i))];

if d > th

spurious =[spurious,i];

else valid = [valid,i];

end

speed = [speed,v];

path = [path,d];

end

Xr=X; Xr(spurious)=NaN;

Yr=Y; Yr(spurious)=NaN;

Pr= path; Pr(spurious)=NaN;

Sr= speed; Sr(spurious)=NaN;

Xv=X(valid);

Yv=Y(valid);

vpath=ismember(path,path(valid)); % logic vector of valid points

solid= strfind(vpath,[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]); % find solid points, i.e. those belonging to a longer seq of stable events

Xso = X(solid);

Yso = Y(solid);

By using the "solid" coordinates (Xso and Yso from the code above) I get closer to what I want (although in this case the length of the segment will have to be refitted somehow). I am just wondering whether there is a more simple and precise method to achieve a similar result

I would appreciate any advice.

thanks !

darova
on 21 Mar 2020

I manualy cleared points i don't want and interpolated data

result

see attached script

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 0 Comments

Sign in to comment.