function [angRot ] = rotate(colorImage1,dsampleFlag)
[height, width,dim]=size(colorImage1);
%uses small portion of image for very large images
if (dsampleFlag==1)
    startH=height/2;
     startW=width/2;
     lastW=512+startW ;
     lastH=512+startH ;
 else
     lastW=width;
     lastH=height;
     startW=1;
     startH=1;
 end
    
rE=double(edge(colorImage1( startH :lastH, startW :lastW,1),'canny'));  
gE=double(edge(colorImage1( startH :lastH,startW :lastW,2),'canny')); 

bE=double(edge(colorImage1( startH:lastH,startW :lastW,3),'canny')); 
 
 
edgeImage=cat(3,rE,gE);

angRot=zeros(1,2);    
 for layer=1:2
          nccMax=0;
     for angle=-1:0.1:1
 temp=imrotate(edgeImage( :,:,layer),angle,'nearest','crop');
 
 ncc=sum(temp(:).*bE(:))/(norm(temp(:))*norm(bE(:))); 
        
            if(ncc>nccMax)
             angRot(layer)=angle;
             nccMax=ncc;
            end
 
     end
   
 end


end

