function[im2] = HwarpTwo2One(H, im1, im0)
% backward warp of im1 to im0
[nrows, ncols] = size(im0);
[ydim, xdim] = size(im0);

% corner coordinates
ulc =project(H*[1,1,1]'); % upper left corner
llc = project(H*[nrows,1,1]'); % lower left corner
urc = project(H*[1,ncols,1]'); % upper right corner
lrc = project(H*[nrows,ncols,1]'); % lower right corner

% compute the new meshgrid  - when aligning to the left
rowmin = min([ulc(1),llc(1),urc(1),lrc(1)]);
rowmax = max([ulc(1),llc(1),urc(1),lrc(1) nrows]);
colmin = min([ulc(2),urc(2),llc(2),lrc(2)]);
colmax = max([ulc(2),urc(2),llc(2),lrc(2) ncols]);

% generate coordinates in the new image  
range_x = rowmin:rowmax;
range_y = colmin:colmax;
[x2, y2] = meshgrid(range_y,range_x); % original image 

[colsNew, rowsNew] = size(x2);
xx = reshape(x2,[1,colsNew*rowsNew]);
yy = reshape(y2,[1,colsNew*rowsNew]);
gg = [yy; xx; ones(1,colsNew*rowsNew)];
ww = H \ gg;

wx = ww(1,:)./ww(3,:); 
wy = ww(2,:)./ww(3,:); 
xi = reshape(wx,[colsNew,rowsNew]);
yi = reshape(wy,[colsNew,rowsNew]);

% do backward warping
im2 = interp2(double(im1),yi,xi,'*bilinear'); 

% fill in the rest with im0 - no blending
im2(28:28+nrows-1,262:262+ncols-1) = im0;

%imtemp = zeros(size(im2));
%imtemp(28:28+nrows-1,262:262+ncols-1) = im0;
%im2(find(isnan(im2))) = 0;
%im2 = (imtemp+im2) /2;



