function [ newImage,indcoords ] = warper( originalImage,warpMap )
% ECE 602: Project 
% Hassan Nahas
%This function warps an image from one frame to another using its warp

    newImage = zeros(size(originalImage(:,:,1)));
    
    x_coords = warpMap(:,:,2);
    x_coords = x_coords(:);
    y_coords = warpMap(:,:,1);
    y_coords = y_coords(:);
    
    coords = [x_coords / 64.0 - 10.0 ,y_coords / 64.0 - 10.0 ];
    coords(coords(:,1) == 0,:) = 1;
    coords(coords(:,2) == 0,:) = 1;
    indcoords = sub2ind(size(originalImage(:,:,1)),coords(:,1),coords(:,2));
     
    allcoords = 1:(size(originalImage(:,:,1),1)*size(originalImage(:,:,1),2));
    newImage(allcoords) = originalImage(indcoords);
%     newImage(warpMap(:,:,3)) = originalImage(warpMap(:,:,2));
end

