function [Overlay] = drawInliers(image1, inliers)
%Joshua Stough
%COMP 290-89, Pollefeys
%Assignment 2, Computing F
%This function takes one image as read from imread. It 
%produces an image with the inliers highlighted.

I = double(rgb2gray(image1));
I = I/max(max(I));

s = size(I);
Overlay = zeros(s(1),s(2),3);

Overlay(:,:,1) = I;
Overlay(:,:,2) = I;
Overlay(:,:,3) = I;

%for every point correspondence, color the points and the line between
%them.

for pix = inliers
    %draw the image1 point in green.
    if (pix(1) > 0 & pix(2) > 0 & pix(1) <= s(1) & pix(2) <= s(2))
        Overlay(pix(1)-1,pix(2)-1,2) = 1;
        Overlay(pix(1)-1,pix(2),2) = 1;
        Overlay(pix(1)-1,pix(2)+1,2) = 1;
        Overlay(pix(1),pix(2)-1,2) = 1;
        %Overlay(pix(1),pix(2),2) = 1;
        Overlay(pix(1),pix(2)+1,2) = 1;
        Overlay(pix(1)+1,pix(2)-1,2) = 1;
        Overlay(pix(1)+1,pix(2),2) = 1;
        Overlay(pix(1)+1,pix(2)+1,2) = 1;
    end
    
    %draw the image2 point in blue_green.
    if (pix(3) > 0 & pix(4) > 0 & pix(3) <= s(1) & pix(4) <= s(2))
        Overlay(pix(3)-1,pix(4)-1,2) = .7;
        Overlay(pix(3)-1,pix(4),2) = .7;
        Overlay(pix(3)-1,pix(4)+1,2) = .7;
        Overlay(pix(3),pix(4)-1,2) = .7;
        %Overlay(pix(3),pix(4),2) = .7;
        Overlay(pix(3),pix(4)+1,2) = .7;
        Overlay(pix(3)+1,pix(4)-1,2) = .7;
        Overlay(pix(3)+1,pix(4),2) = .7;
        Overlay(pix(3)+1,pix(4)+1,2) = .7;
        
        Overlay(pix(3)-1,pix(4)-1,3) = 1;
        Overlay(pix(3)-1,pix(4),3) = 1;
        Overlay(pix(3)-1,pix(4)+1,3) = 1;
        Overlay(pix(3),pix(4)-1,3) = 1;
        %Overlay(pix(3),pix(4),3) = 1;
        Overlay(pix(3),pix(4)+1,3) = 1;
        Overlay(pix(3)+1,pix(4)-1,3) = 1;
        Overlay(pix(3)+1,pix(4),3) = 1;
        Overlay(pix(3)+1,pix(4)+1,3) = 1;
    end
    
    %draw a green line between the two points.
    numsteps = 2*sqrt(sum((pix(1:2) - pix(3:4)).^2));
    dir = (pix(3:4)- pix(1:2))/numsteps;
    
    cur = pix(1:2) - dir;
    for i = 1:numsteps
        cur = cur + dir;
        Overlay(round(cur(1)),round(cur(2)),2) = 1;
    end
    
end

figure, imshow(Overlay,[0 1],'truesize');
