function image = biInterp(images, camX, camY, disp, apature)
%bilinear interpolation code. After implementing apature for this
%assignment, this isnt used anymore (guassian is used with apature).


%so that floor(camera position) != ceil(camera position)
if(camX == round(camX))
   if(camX == 1)
      camX = camX + .00001;
   else
       camX = camX -.00001;
   end
end
if(camY == round(camY))
   if(camY == 1)
      camY = camY + .00001;
   else
       camY = camY -.00001;
   end
end

%get 4 surrounding images
r_ul = max(1, floor(camY));
c_ul = max(1, floor(camX));
image_ul = images{r_ul, c_ul};

r_ur= max(1, floor(camY));
c_ur = max(1, ceil(camX));
image_ur = images{r_ur, c_ur};

r_ll = max(1, ceil(camY));
c_ll = max(1, floor(camX));
image_ll = images{r_ll, c_ll};

r_lr = max(1, ceil(camY));
c_lr = max(1, ceil(camX));
image_lr = images{r_lr, c_lr};

%shift the images for focal distance
disp_ul_x = disp*(c_ul - camX); 
disp_ul_y = disp*(r_ul - camY); 
image_ul = shiftImage(image_ul, disp_ul_x, disp_ul_y);


disp_ur_x = disp*(c_ur - camX); 
disp_ur_y = disp*(r_ur - camY); 
image_ur = shiftImage(image_ur, disp_ur_x, disp_ur_y);

disp_ll_x = disp*(c_ll - camX); 
disp_ll_y = disp*(r_ll - camY);
image_ll = shiftImage(image_ll, disp_ll_x, disp_ll_y);

disp_lr_x = disp*(c_lr - camX); 
disp_lr_y = disp*(r_lr - camY); 
image_lr = shiftImage(image_lr, disp_lr_x, disp_lr_y);


%interpolate
alpha = (c_lr - camX) / (c_lr - c_ll);
beta = (r_ll - camY) / (r_ll - r_ul);
image = alpha*beta*image_ul + (1-alpha)*beta*image_ur + ...
    alpha*(1-beta)*image_ll + (1-alpha)*(1-beta)*image_lr;



end

