function get_novel_view(num1,num2,W,H,fname,test_number,padding,blocksize,max_offset_y,max_offset_x,a,b,c,d)

[Y1 U1 V1] = read_ith_GOP_keyframe(num1,1,W,H,fname) ;
[Y2 U2 V2] = read_ith_GOP_keyframe(num2,1,W,H,fname) ;
orig_height = size(Y1,1) ; 
orig_width = size(Y1,2) ;
%figure ; imagesc(Y1) ; colormap gray ; title('view 1') ;
%figure ; imagesc(Y2) ; colormap gray ; title('view 2') ;

%% pad the images to increase size.
[Y1 U1 V1] = pad_images(Y1,U1,V1,padding) ;
[Y2 U2 V2] = pad_images(Y2,U2,V2,padding) ;

height = size(Y1,1) ; width = size(Y1,2) ;
disparity_vectors_y = zeros(height/blocksize,width/blocksize) ;
disparity_vectors_x = zeros(height/blocksize,width/blocksize) ;
index_y = 0 ; index_x = 0 ;

for block_y = 1 : blocksize : height
    cblock_y = (block_y-1)/2 + 1 ;
    index_y = index_y + 1 ;
    index_x = 0 ;
    for block_x = 1 : blocksize : width
        cblock_x = (block_x-1)/2 + 1 ;
        index_x = index_x + 1 ;
        min_ssd = inf ;
        best_offset_y = 0 ; best_offset_x = 0 ;
        for offset_y = -max_offset_y : 1 : max_offset_y
            for offset_x = -max_offset_x : 1 : max_offset_x
%                a=-1 ; b=1 ; c=-1 ; d=1 ; % proportion between a and b should be the same as the proportion between c and d
                vecy_view1  =  a*offset_y ;
                vecy_view2  =  b*offset_y ;
                vecx_view1  =  c*offset_x ;
                vecx_view2  =  d*offset_x ;
                [block_view1_Y validY] = get_pred_block_qpel(block_y,block_x,blocksize,vecy_view1,vecx_view1,Y1,1) ;
                [block_view1_U validU] = get_pred_block_qpel(block_y,block_x,blocksize,vecy_view1,vecx_view1,U1,2) ;
                [block_view1_V validV] = get_pred_block_qpel(block_y,block_x,blocksize,vecy_view1,vecx_view1,V1,3) ;
                if validY==0 | validU==0 | validV==0
                    continue ;
                end
                [block_view2_Y validY] = get_pred_block_qpel(block_y,block_x,blocksize,vecy_view2,vecx_view2,Y2,1) ;
                [block_view2_U validU] = get_pred_block_qpel(block_y,block_x,blocksize,vecy_view2,vecx_view2,U2,2) ;
                [block_view2_V validV] = get_pred_block_qpel(block_y,block_x,blocksize,vecy_view2,vecx_view2,V2,3) ;
                if validY==0 | validU==0 | validV==0
                    continue ;
                end
                block_view1_Y = block_view1_Y(:) ; block_view1_U = block_view1_U(:) ; block_view1_V = block_view1_V(:) ;
                block_view2_Y = block_view2_Y(:) ; block_view2_U = block_view2_U(:) ; block_view2_V = block_view2_V(:) ;
                block_view1 = [block_view1_Y ; block_view1_U ; block_view1_V] ;
                block_view2 = [block_view2_Y ; block_view2_U ; block_view2_V] ;
                ssd = block_view1 - block_view2 ;
                ssd = ssd.*ssd ;
                ssd = sum(ssd(:)) ;
                if ssd <= min_ssd
                    min_ssd = ssd ;
                    best_offset_y = offset_y ;
                    best_offset_x = offset_x ;
                end
            end
        end
        disparity_vectors_y(index_y,index_x) = best_offset_y ;
        disparity_vectors_x(index_y,index_x) = best_offset_x ;
        nv_from1_Y(block_y:block_y+blocksize-1,block_x:block_x+blocksize-1) = ... 
            get_pred_block_qpel(block_y,block_x,blocksize,a*best_offset_y,c*best_offset_x,Y1,1) ;
        nv_from1_U(cblock_y:cblock_y+blocksize/2-1,cblock_x:cblock_x+blocksize/2-1) = ... 
            get_pred_block_qpel(block_y,block_x,blocksize,a*best_offset_y,c*best_offset_x,U1,2) ;
        nv_from1_V(cblock_y:cblock_y+blocksize/2-1,cblock_x:cblock_x+blocksize/2-1) = ... 
            get_pred_block_qpel(block_y,block_x,blocksize,a*best_offset_y,c*best_offset_x,V1,3) ;

        nv_from2_Y(block_y:block_y+blocksize-1,block_x:block_x+blocksize-1) = ... 
            get_pred_block_qpel(block_y,block_x,blocksize,b*best_offset_y,d*best_offset_x,Y2,1) ;
        nv_from2_U(cblock_y:cblock_y+blocksize/2-1,cblock_x:cblock_x+blocksize/2-1) = ... 
            get_pred_block_qpel(block_y,block_x,blocksize,b*best_offset_y,d*best_offset_x,U2,2) ;
        nv_from2_V(cblock_y:cblock_y+blocksize/2-1,cblock_x:cblock_x+blocksize/2-1) = ... 
            get_pred_block_qpel(block_y,block_x,blocksize,b*best_offset_y,d*best_offset_x,V2,3) ;

        nv_from1and2_Y = 0.5*nv_from1_Y + 0.5*nv_from2_Y ;
        nv_from1and2_U = 0.5*nv_from1_U + 0.5*nv_from2_U ;
        nv_from1and2_V = 0.5*nv_from1_V + 0.5*nv_from2_V ;
    end
end

[nv_from1_Y nv_from1_U nv_from1_V] = unpad_images(nv_from1_Y,nv_from1_U,nv_from1_V,padding) ;
[nv_from2_Y nv_from2_U nv_from2_V] = unpad_images(nv_from2_Y,nv_from2_U,nv_from2_V,padding) ;
[nv_from1and2_Y nv_from1and2_U nv_from1and2_V] = unpad_images(nv_from1and2_Y,nv_from1and2_U,nv_from1and2_V,padding) ;

%figure ; imagesc(nv_from1_Y) ; colormap gray ;
%figure ; imagesc(nv_from2_Y) ; colormap gray ;
%figure ; imagesc(nv_from1and2_Y) ; colormap gray ;

s = ['save novel_view_' num2str(test_number) ' nv_from1_Y nv_from1_U nv_from1_V ' ...
        'nv_from2_Y nv_from2_U nv_from2_V ' ...
        'nv_from1and2_Y nv_from1and2_U nv_from1and2_V ' ...
        'disparity_vectors_y disparity_vectors_x a b c d -v6 ;'] ;
eval(s) ;
