function [ morphed ] = viewMorph( im1,im2,im1p,im2p,im1s,im2s,F)

[H1,H2] = computeH1H2(F);

im1pw = H1*[im1p';ones(1,size(im1p,1))];
im1sw = H1*[im1s';ones(1,size(im1s,1))];
im1pw = im1pw ./ [im1pw(3,:);im1pw(3,:);im1pw(3,:)];
im1sw = im1sw ./ [im1sw(3,:);im1sw(3,:);im1sw(3,:)];
im2pw = H2*[im2p';ones(1,size(im2p,1))];
im2sw = H2*[im2s';ones(1,size(im2s,1))];
im2pw = im2pw ./ [im2pw(3,:);im2pw(3,:);im2pw(3,:)];
im2sw = im2sw ./ [im2sw(3,:);im2sw(3,:);im2sw(3,:)];

im1 = im2double(im1);
im2 = im2double(im2);
[im1w,im1d] = warpImage(im1,H1);
[im2w,im2d] = warpImage(im2,H2);

im1d
im2d

if ( im1d(2) < im2d(2) )
    extray = im2d(2) - im1d(2);
    im2w = [zeros(extray,size(im2w,2),3);im2w];
elseif ( im2d(2) < im1d(2) )
    extray = im1d(2) - im2d(2);
    im1w = [zeros(extray,size(im1w,2),3);im1w];
end


imwrite(im1w,'im1w.jpg');
imwrite(im2w,'im2w.jpg');

im1pw = im1pw(1:2,:);
im2pw = im2pw(1:2,:);
im1sw = im1sw(1:2,:);
im2sw = im2sw(1:2,:);
im1pw = im1pw - repmat(im1d',1,size(im1pw,2));
im2pw = im2pw - repmat(im1d',1,size(im2pw,2));
im1pw = im1pw';
im2pw = im2pw';
im1sw = im1sw';
im2sw = im2sw';

newF = fundamental(im1pw,im2pw)

% imshow(im1w);
% figure,imshow(im2w);

corners1 = [1 size(im1w,2)-1 size(im1w,2) 1;1 1 size(im1w,1) size(im1w,1)];
corners2 = [1 size(im2w,2)-1 size(im2w,2) 1;1 1 size(im2w,1) size(im2w,1)];
im1pw = [im1pw;corners1'];
im2pw = [im2pw;corners2'];

% corners1 = [1 size(im1,2)-1 size(im1,2) 1;1 1 size(im1,1) size(im1,1)];
% corners2 = [1 size(im2,2)-1 size(im2,2) 1;1 1 size(im2,1) size(im2,1)];
% im1p = [im1p;corners1'];
% im2p = [im2p;corners2'];

points_avg = im1p*0.5 + im2p*0.5;
tri = delaunay(points_avg(:,1),points_avg(:,2));

n=30;
for i=1/n:1/n:1-1/n
    i
    morphed = morph(im1w,im2w,im1pw,im2pw,tri,i,i);
    if(floor(i*n) < 10)
        imwrite(morphed,sprintf('movie/morph0%d.jpg',floor(i*n)),'jpg','Quality',100);
    else
        imwrite(morphed,sprintf('movie/morph%d.jpg',floor(i*n)),'jpg','Quality',100);
    end
end


% figure,imshow(morphed);
