M=load_corr('kornew.mat')

n=size(M,2);



for j=1:n

   A(2*j-1,1)=M(1,j);

   A(2*j-1,2)=M(2,j);

   A(2*j-1,3)=1;

   A(2*j-1,4)=0;

	A(2*j-1,5)=0;

	A(2*j-1,6)=0;

	A(2*j-1,7)=-M(3,j)*M(1,j);

	A(2*j-1,8)=-M(3,j)*M(2,j);

	A(2*j-1,9)=-M(3,j);

   

   A(2*j,1)=0;

   A(2*j,2)=0;

   A(2*j,3)=0;

   A(2*j,4)=M(1,j);

	A(2*j,5)=M(2,j);

	A(2*j,6)=1;

	A(2*j,7)=-M(4,j)*M(1,j);

	A(2*j,8)=-M(4,j)*M(2,j);

	A(2*j,9)=-M(4,j);

   

end



[U,S,V]=svd(A)

T=V(:,end)'

H=reshape(T,3,3)'





im1=imread('panorama1.jpg');

im2=imread('panorama2.jpg');

siz1=size(im1);

siz2=size(im2);



xpos=100;

ypos=1;



im3=zeros(2*siz2(1),2*siz2(2),3);



roh1=H*[1,1,1]';

roh2=H*[1,siz1(1),1]';

roh3=H*[siz1(2),siz1(1),1]';

roh4=H*[siz1(2),1,1]';



roh1=roh1./roh1(3)

roh2=roh2./roh2(3)

roh3=roh3./roh3(3)

roh4=roh4./roh4(3)



IAAH=inv(H);

im3(xpos:siz2(1)+xpos-1,ypos:siz2(2)+ypos-1,:)=im2(:,:,:);



for i=(roh1(1)+20):roh4(1)

   for j=0:roh3(2)

      pom=IAAH*[i;j;1];

      pomx = round(pom(1)/pom(3));

      pomy = round(pom(2)/pom(3));

      if (pomx<=siz1(2) & pomx>=1 & pomy>=1 & pomy<=siz1(1))

         im3(round(j)+xpos,round(i)+ypos,:)=im1(pomy, pomx,:);

      end

   end

end





im3=im3./255;







