AnalyzeDeepLabCutPP.m 960 B

12345678910111213141516171819202122232425262728
  1. function [timestamps,xcoordinates,ycoordinates]=AnalyzeDeepLabCutPP(h5file,videofile,ffmpeg_path)
  2. data=h5read(h5file,'/df_with_missing/table');
  3. headcap_x=data.values_block_0(1,:)';
  4. headcap_y=data.values_block_0(2,:)';
  5. headcap_l=data.values_block_0(3,:)';
  6. %only look at frames where deeplabcut is above a certain likelihood cutoff
  7. likelihood_cutoff=0.95;
  8. xcoord=headcap_x(headcap_l>likelihood_cutoff);
  9. ycoord=headcap_y(headcap_l>likelihood_cutoff);
  10. %get timestamps of frames from video using downloaded function and ffmpeg
  11. ts = videoframets(ffmpeg_path,videofile);
  12. incframetimes=ts(headcap_l>likelihood_cutoff);
  13. %remove outliers
  14. wrongx = isoutlier(xcoord,'movmedian',30);%,'samplepoints',incframetimes);
  15. wrongy = isoutlier(ycoord,'movmedian',30);%,'samplepoints',incframetimes);
  16. timestamps=incframetimes(wrongx==0 & wrongy==0);
  17. xcoordinates=xcoord((wrongx==0 & wrongy==0));
  18. ycoordinates=ycoord((wrongx==0 & wrongy==0));
  19. end