%Input: 
%File:Avi filename, 
%win_size: window size

%example:
%pix('fox.avi',5,5);
function pix(File, win_size,T_d);
data = aviread(File);
noofframes = size(data,2);
for i = 1:1:noofframes
    directory = '';
    filename = strcat(directory,num2str(i),'.jpg');
    imwrite(data(i).cdata,filename,'jpg');
end
first = strcat(directory,num2str(1),'.jpg');
for i = 2:1:noofframes
    second = strcat(directory,num2str(i),'.jpg');
    pix_diff(i-1, 1) = pixdiffnorm(first, second);    
    first = second;
end
k = 1;
for i = 1:1:(noofframes - (2*win_size) - 1)
    window = pix_diff([i:(i+2*win_size)],1);
    judge =  thresh(window, T_d);
    if judge == 1
        motion(i,:) = pix_diff(((i + 2*win_size) - win_size),1);
    end
end
k = 1;
for i = 1:1:size(pix_diff)
    mat = find(motion == pix_diff(i,1));
    if isempty(mat) == 0
        change(k,2) = pix_diff(i,1);
        change(k,1) = i;
        k = k  + 1;
    end
end
delete *.jpg
figure
plot(pix_diff(:,1))
hold on
plot(change(:,1),change(:,2),'*')
TITLE('Pixel Based Motion Detection')
