function [newI,newI2]=draw_faces2(Results,Guess,Irgb,Correct_size,noface)
%This function creates two images. In one it just draws green boxes around
%the faces. Or red boxes if there are no faces. In the other one it draws 
%in addition the raw guesses.

%Calculate the average template size.
T=mean(Correct_size);
newI=Irgb;

%If there are faces draw boxes in green, if not in red.
if (noface==1)
    c1=1;
    c0=2;
else
    c1=2;
    c0=1;
end

%The square is bigger because the templates do not show the whole head and
%it looks nicer.
sY2=round(T/2*1.4);
sX2=round(3*T/8*1.3);
N=size(Results,1);

%For each coordinate change the values for each side of the rectangle
for k=1:N
    x=round(Results(k,3));
    y=round(Results(k,2));
    newI((y-sY2):(y+sY2),(x-sX2)-1:(x-sX2)+1,c0)=zeros(size(newI((y-sY2):(y+sY2),(x-sX2)-1:(x-sX2)+1,1)));   
    newI((y-sY2):(y+sY2),(x-sX2)-1:(x-sX2)+1,c1)=255.*ones(size(newI((y-sY2):(y+sY2),(x-sX2)-1:(x-sX2)+1,2)));
    newI((y-sY2):(y+sY2),(x-sX2)-1:(x-sX2)+1,3)=zeros(size(newI((y-sY2):(y+sY2),(x-sX2)-1:(x-sX2)+1,3)));
    
    newI((y-sY2):(y+sY2),(x+sX2)-1:(x+sX2)+1,c0)=zeros(size(newI((y-sY2):(y+sY2),(x+sX2)-1:(x+sX2)+1,1)));   
    newI((y-sY2):(y+sY2),(x+sX2)-1:(x+sX2)+1,c1)=255.*ones(size(newI((y-sY2):(y+sY2),(x+sX2)-1:(x+sX2)+1,2)));
    newI((y-sY2):(y+sY2),(x+sX2)-1:(x+sX2)+1,3)=zeros(size(newI((y-sY2):(y+sY2),(x+sX2)-1:(x+sX2)+1,3)));
    
    newI((y-sY2)-1:(y-sY2)+1,(x-sX2):(x+sX2),c0)=zeros(size(newI((y-sY2)-1:(y-sY2)+1,(x-sX2):(x+sX2),1)));   
    newI((y-sY2)-1:(y-sY2)+1,(x-sX2):(x+sX2),c1)=255.*ones(size(newI((y-sY2)-1:(y-sY2)+1,(x-sX2):(x+sX2),2)));
    newI((y-sY2)-1:(y-sY2)+1,(x-sX2):(x+sX2),3)=zeros(size(newI((y-sY2)-1:(y-sY2)+1,(x-sX2):(x+sX2),3)));
    
    newI((y+sY2)-1:(y+sY2)+1,(x-sX2):(x+sX2),c0)=zeros(size(newI((y+sY2)-1:(y+sY2)+1,(x-sX2):(x+sX2),1)));   
    newI((y+sY2)-1:(y+sY2)+1,(x-sX2):(x+sX2),c1)=255.*ones(size(newI((y+sY2)-1:(y+sY2)+1,(x-sX2):(x+sX2),2)));
    newI((y+sY2)-1:(y+sY2)+1,(x-sX2):(x+sX2),3)=zeros(size(newI((y+sY2)-1:(y+sY2)+1,(x-sX2):(x+sX2),3)));
end

newI2=newI;

for k=1:N
    x=round(Results(k,3));
    y=round(Results(k,2));
    newI2((y-2):(y+2),(x-2):(x+2),1)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),1)));   
    newI2((y-2):(y+2),(x-2):(x+2),3)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),3)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
    
    newI2((y-2):(y+2),(x-2):(x+2),1)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),1)));   
    newI2((y-2):(y+2),(x-2):(x+2),3)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),3)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
    
    newI2((y-2):(y+2),(x-2):(x+2),1)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),1)));   
    newI2((y-2):(y+2),(x-2):(x+2),3)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),3)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
    
    newI2((y-2):(y+2),(x-2):(x+2),1)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),1)));   
    newI2((y-2):(y+2),(x-2):(x+2),3)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),3)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
end

N2=size(Guess,1);

for k=1:N2
    x=round(Guess(k,3));
    y=round(Guess(k,2));
    newI2((y-2):(y+2),(x-2):(x+2),3)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),3)));   
    newI2((y-2):(y+2),(x-2):(x+2),1)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),1)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
    
    newI2((y-2):(y+2),(x-2):(x+2),3)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),3)));   
    newI2((y-2):(y+2),(x-2):(x+2),1)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),1)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
    
    newI2((y-2):(y+2),(x-2):(x+2),3)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),3)));   
    newI2((y-2):(y+2),(x-2):(x+2),1)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),1)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
    
    newI2((y-2):(y+2),(x-2):(x+2),3)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),3)));   
    newI2((y-2):(y+2),(x-2):(x+2),1)=255.*ones(size(newI((y-2):(y+2),(x-2):(x+2),1)));
    newI2((y-2):(y+2),(x-2):(x+2),2)=zeros(size(newI((y-2):(y+2),(x-2):(x+2),2)));
end