load(['data' filesep 'watersurface_tv_result']);

dataName = 'watersurface'
moviename = [ dataName,'.avi']; fps = 12;
mov = avifile(moviename,'fps',fps,'compression','none');
[m,n,p] = size(ImData);

F_hat = abs(F_hat) / max(max(abs(F_hat)))>0.1;

start_frame = 450;
end_frame = 610;

for i = start_frame:end_frame
    figure(1); clf;
    subplot(1,3,1);
    imshow(ImData(:,:,i)), axis off, colormap gray; axis off;
    title('Original Image','fontsize',12);
    
   
    subplot(1,3,2);
    imshow(reshape(F_hat(:,i),m,n)), axis off,colormap gray; axis off;
    hold on; %contour(Mask(:,:,i),[0 0],'y','linewidth',5);
    title('TVRPCA Mask','fontsize',12);
    
    subplot(1,3,3);
    %imshow(reshape(B_hat(:,i),m,n)), axis off, colormap gray; axis off;    
    imshow(ImData(:,:,i).*uint8(reshape(F_hat(:,i),m,n))), axis off, colormap gray; axis off;
    title('TVRPCA Foreground','fontsize',12);
    mov = addframe(mov,getframe(1));
end
h = close(mov);