%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function 'imposingSmallMatOntoBigMat' superimposes 'small Matrix' onto 'Big Matrix' at given position of left-top corner
% of the small matrix.

% Programmer : Nilesh Ghubade (nileshg@temple.edu)
% Date : Aug 2002
% Advisor : Dr.Longin Jan Latecki (latecki@temple.edu)
% Project : Video Analysis (extracting key frames from a given movie file)
% Department : Computer and Information Science Department, Temple University, Philadelphia, PA-19122, USA

% Input arguments:-
% smallMat = the 'small Matrix' that is to be superimposed onto Big Matrix.
% bigMat = the 'Big Matrix' that is used to encapsulate the small Matrix.
% position = (row,col) of the left-top corner position within the big matrix where small matrix is to be superimposed.

% Output : 'outputMatrix' containing the big matrix having superimposed small matrix at given position.

% Example : [outputMatrix] = imposingSmallMatOntoBigMat(ones(3,3),zeros(100,100),(10,20))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [outputMatrix] = imposingSmallMatOntoBigMat(smallMat,bigMat,position)
errorFlag = 0;
if size(position) ~= 2 
    error('position Matrix should contain row number and col number of left-top corner of small matrix that is to be imposed on big matrix!')
    return;    
end

if ((size(smallMat,1) > size(bigMat,1)) | (size(smallMat,2) > size(bigMat,2)))
    error('dimensions of small matrix should be <= dimensions of big matrix')
    return;
end

if ((position(1) < 1) | (position(2) < 1) | (position(1) > ((size(bigMat,1) - size(smallMat,1))+1)) | (position(2) > ((size(bigMat,2) - size(smallMat,2))+1)))
    disp('left top corner row-col values of the position where small matrix is to be imposed on big matrix does not allow entire small matrix to be superimposed onto big matrix!')
    disp('left top row = ');
    position(1)
    disp('left top column');
    position(2)
    errorFlag = 1;
end

if (errorFlag == 0)
    bigMat(position(1):position(1)+size(smallMat,1)-1,position(2):position(2)+size(smallMat,2)-1)=smallMat;
end
outputMatrix = bigMat;
return;