function [im1,im2,newx,nC]=gimmeWarpedImage(im, warpFunction);
% Creates a number of figures from a given image
%
% Usage:  createCompleteFigures
%
% Arguments:   
%	im		- The original image
% 	warpFunction	- The transformation function
%
% Output :
%	im1		- The original image
%	im2		- The transformed image
%	newx		- The transformation function is around X=0
%       nC  		- Normalization constant (to avoid getting out of bounds)
%
% Author: 
% Konstantinos Bitsakos
% Department of Computer Science 
% University of Maryland, College Park
% kbits@cs.umd.edu
%
% January 2008


sz=size(im);
% Need to have odd number of columns to perform the interpolation correctly
if mod(sz(2),2)
    x1=-floor(sz(2)/2):floor(sz(2)/2)
    im1=double(im);
else
    x1=[-(sz(2)/2)+1:sz(2)/2-1];
    im1=double(im(:,1:sz(2)-1,:));
end

x2=warpFunction(x1);

% Find the normalization constant, so that the indices of the second image
% don't excess those of the first image
nC=min( min(x1)/min(x2), max(x1)/max(x2));
if nC>1 % The second signal is contained by the first signal
    x2N=x2;
    nC=1;
else % We need to stretch the second signal appropriately so that it is contained by the first one
    x2N=nC*x2;
end

for i=1:sz(3)
    im2(:,:,i)=(interp1(x1,double(im1(:,:,i))',x2N))';
end

newx=x1;
