% Replay annotation of a movie from 2d coordinate data from SPAN 1.3 'annotation.m'
clear all
close all
clc
% Ask the user for a directory and change working directory
cd('D:\')
% Ask the user for a file name, and set the filename variable
[filename_movie, pathname_movie] = uigetfile({'*.avi','AVI movie'},'Pick a movie clip');
% Ask the user for a directory and change working directory (this has to be where the data is stored)
cd('D:\')
% Ask the user for a file name, and set the filename variable
[filename_data, pathname_data] = uigetfile({'*.mat','Data file'},'Pick a data file');
load(filename_data, '*')
% Open figure
figure
% Creates axes where to draw
ha(1) = subplot(5,4,[1 2 3 5 6 7 9 10 11 13 14 15]);
ha(2) = subplot(5,4,[4 8 12 16]);
ha(3) = subplot(5,4,17:19);
ha(4) = subplot(5,4,20);
N = size(Idata,1);
Npts = ((size(Idata,2))-1)/3;
S = ['+.ox'];
color = ['bgrcmyw'];
% Makes it into a long filename (path + file name)
filename_movie = fullfile(pathname_movie,filename_movie);
% Load the frames of the movie in a 'movie' variable
movie = aviread(filename_movie);
for i = 1:N
axes(ha(1));cla
imagesc(movie(i).cdata)
axis image
title(sprintf('Image : %d / %d ',i,N))
hold on
x = [];
y = [];
for j = 1:Npts
if Idata(i,2+(j-1)*3) == 1
s = 1;
elseif Idata(i,2+(j-1)*3) == 2
s = 2;
elseif Idata(i,2+(j-1)*3) == 3
s = 3;
end
x = [x 3+(j-1)*3];
y = [y 4+(j-1)*3];
plot(Idata(i,3+(j-1)*3),Idata(i,4+(j-1)*3),sprintf('%s %s',S(s),color(j)))
end
axes(ha(2));cla
plot(Idata(1:i,x(:)),repmat([1:i]',[1,Npts]))
set(ha(2),'Ylim',[0 N],'YDir','reverse')
axes(ha(3));cla
plot(Idata(1:i,y(:)))
set(ha(3),'Xlim',[0 N],'YDir','reverse')
axes(ha(4));cla
plot(Idata(1:i,x(:)),Idata(1:i,y(:)))
set(ha(4),'YDir','reverse','YTick',[])
drawnow
% pause
pause(.2)
end