function [ nccMap,anchor ] = shiftAlign(colorImage,disp,anchor,factor)
nccMap=zeros(2*disp+1,2*disp+1,2);
  Updisp=round(1/factor*disp);
  
[height width dim]=size(colorImage);
%uses small portion of image for very large images
 if (width>512)
     
     startH=height/2;
     startW=width/2;
     lastW=512+startW ;
     lastH=512+startH ;
 else
     lastW=width;
     lastH=height;
     Updisp=0;
     startW=1;
     startH=1;
 end
 
 
     
rE=double(edge(colorImage(startH+Updisp+anchor(1,1,1):lastH+Updisp+anchor(1,1,1),startW+Updisp+anchor(1,2,1):lastW+Updisp+anchor(1,2,1),1),'canny'));  
gE=double(edge(colorImage(startH+Updisp+anchor(1,1,2):lastH+Updisp+anchor(1,1,2),startW+Updisp+anchor(1,2,2):lastW+Updisp+anchor(1,2,2),2),'canny')); 

bE=double(edge(colorImage(startH+Updisp+disp:lastH+Updisp-disp,startW+Updisp+disp:lastW+Updisp-disp,3),'canny')); 
 
 
edgeImage=cat(3,rE,gE);
 
 
 
 
 
 
 
 
 for layer =1:1:2
     nccMax=0;
     
 for i=-disp:1:disp 
     for j=-disp :1:disp
       
      temp=edgeImage(1+i+disp:end-disp+i,1+j+disp:end-disp+j,layer);
        ncc= sum(temp(:).*bE(:))/(norm(temp(:))*norm(bE(:))); 
        nccMap(i+disp+1,j+disp+1,layer)=ncc;
         if(ncc>nccMax)
             I=i;
             J=j;
             nccMax=ncc;
         end
        
     end 
 end
 anchor(:,:,layer)=[I J];
 
 end  

end

