%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function 'TwoDimTransformations' creates .avi file which contains translation motion of a 'house'.
%
% Programmer : Nilesh Ghubade (nileshg@temple.edu)
% Date : Sept 2002
% Advisor : Dr.Longin Jan Latecki (latecki@temple.edu )
% Project : Matlab demonstration
% Department : Computer and Information Science Department, Temple University, Philadelphia, PA-19122, USA

% Input arguments:-
% None

% Output : -
% 1) aviFileName = The name of the .avi file containing movie of the translation motion of the sample house.

% Example : -
% 1) [aviFileName] = TwoDimTransformations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [aviFileName] = TwoDimTransformations
houseImg = imread('House.bmp');
totalRows = size(houseImg,1);
totalCols = size(houseImg,2);
framesPerSec = 5; % 'frames per second' parameter for the .avi file.
aviFileName = 'transformations';
aviobj = avifile(aviFileName,'fps',framesPerSec,'COMPRESSION','NONE'); % initialize .avi file object.
%aviobj = avifile(aviFileName,'fps',framesPerSec); % initialize .avi file object.
tempImgFileName = 'temp.bmp';
for count=1:15
    translationRowIncr = 5;
    translationColIncr = 5; 
    newHouseImg(totalRows,totalCols,3) = 0;
    newHouseImg(:,:,:) = 255;

    [imageRows,imageCols] = find(houseImg == 0);
    newHouseImgTranslationRows = imageRows + translationRowIncr;
    newHouseImgTranslationCols = imageCols + translationColIncr;
    for tempCount=1:size(newHouseImgTranslationRows,1)
        newHouseImg(newHouseImgTranslationRows(tempCount),newHouseImgTranslationCols(tempCount)) = 0;
    end

    imwrite(newHouseImg,tempImgFileName,'bmp');
    imgObj = imread(tempImgFileName,'bmp');
    frameObj = im2frame(imgObj);  
    aviobj = addframe(aviobj,frameObj);
    frame(count) = frameObj;
    delete(tempImgFileName);
    houseImg = newHouseImg;
end
movie(frame);
aviobj = close(aviobj);
return;