diff --git "a/Homework_6/problem6_1/2015200920\354\204\235\355\230\270\354\260\275.txt" "b/Homework_6/problem6_1/2015200920\354\204\235\355\230\270\354\260\275.txt" new file mode 100644 index 0000000..e69de29 diff --git a/Homework_6/problem6_1/ImageL_00300.png b/Homework_6/problem6_1/ImageL_00300.png new file mode 100755 index 0000000..5d0a3d3 Binary files /dev/null and b/Homework_6/problem6_1/ImageL_00300.png differ diff --git a/Homework_6/problem6_1/ImageR_00300.png b/Homework_6/problem6_1/ImageR_00300.png new file mode 100755 index 0000000..54c5f14 Binary files /dev/null and b/Homework_6/problem6_1/ImageR_00300.png differ diff --git a/Homework_6/problem6_1/rectification.py b/Homework_6/problem6_1/rectification.py new file mode 100644 index 0000000..29fdaa2 --- /dev/null +++ b/Homework_6/problem6_1/rectification.py @@ -0,0 +1,121 @@ +#2015200920 SeokHochang +from numpy import * +import sys +import math +from scipy import misc +import itertools as iter +import numpy as np +def rectification(Img1,Img2,K1,K2,E) : + + + width_im1 = shape(Img1)[1]; + height_im1 = shape(Img1)[0]; + + width_im2 = shape(Img2)[1]; + height_im2 = shape(Img2)[0]; + + + if( not ( shape(K1)==(3,3) and shape(K2)==(3,3) and shape(E)==(3,4) )): + print 'wrong input' + sys.exit(); + + coordinates = list(iter.product(xrange(width_im1) , xrange(height_im1))); + zeros_=matrix(zeros((3,width_im1*height_im1))); + + zeros_[0:2,:]=matrix(transpose(coordinates)); + zeros_[2,:]=1; + im1_coord=zeros_.astype(double); + im2_coord=zeros_.astype(double); + + im1_imgvec=np.linalg.inv(K1).dot(im1_coord); + im2_imgvec=np.linalg.inv(K2).dot(im2_coord); + + R=matrix(E[:,0:3]); + R=R.astype(double); + T=matrix(E[:,3]); + T=T.astype(double); + + e1=K1.dot(T); + e1=e1/e1[2,0]; + + e2=-K2.dot(transpose(R)).dot(T); + e2=e2/e2[2,0]; + + c=transpose(matrix(K1[:,2])); + + t_=transpose(T); + v0=t_; + v1=cross(v0,c); + v2=cross(v1,v0); + + H1=matrix('0. 0. 0.; 0. 0. 0.; 0. 0. 0.'); + + H1[:,0]=transpose(v0)/np.linalg.norm(v0); + H1[:,2]=transpose(v1)/np.linalg.norm(v1); + H1[:,1]=transpose(v2)/np.linalg.norm(v2); + + H2=H1*transpose(R); + +# inverse warping + coord= matrix('0;0;1'); + Img1_warp = matrix(zeros((720,1280))); + for i in range(1280*720): + x = i%1280; + y = i/1280; + coord[0,0]=x; + coord[1,0]=y; + + tmp=np.linalg.inv(H1).dot(coord); + if (x>0 and x<1280 and y>0 and y<720): + Img1_warp[y,x] =interp(tmp[0,:],tmp[1,:],Img1); + + + coord= matrix('0;0;1'); + Img2_warp = matrix(zeros((720,1280))); + for i in range(1280*720): + x = i%1280; + y = i/1280; + coord[0,0]=x; + coord[1,0]=y; + + tmp=np.linalg.inv(H2).dot(coord); + if (x>0 and x<1280 and y>0 and y<720): + Img2_warp[y,x] =interp(tmp[0,:],tmp[1,:],Img2); + + + return Img1_warp,Img2_warp; + +def interp(x,y,Img): + x1= np.floor(x).astype(int); + x2= x1+1; + y1= np.floor(y).astype(int); + y2= y1+1; + width = shape(Img)[1]; + height = shape(Img)[0]; + + if x1>=0 and x1=0 and y1