function [ sPixI,sPixJ] = sPix(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

imageSmall=single(colorImage1(startH :lastH, startW :lastH,:));
 b=imageSmall(:,:,3);
  
   sPixI=zeros(1,3,2);
  sPixJ=zeros(3,1,2);
  tempI=sPixI;
  tempJ=sPixJ;
  
  
 for layer=1:1:2
     nccMax=0;
 for i=-0.75:0.1:0.75
     for j=-0.75:0.1:0.75
         
      tempJ=0*tempJ;
      tempI=0*tempI;
      
      if(i<0)
        tempI(1,3,layer)=-i;
        tempI(1,2,layer)=1+i;
      else
         tempI(1,1,layer)=i;
        tempI(1,2,layer)=1-i;
      end
      
      if(j<0)
        tempJ(3,1,layer)=-j;
        tempJ(2,1,layer)=1+j;
      else
         tempJ(1,1,layer)=j;
        tempJ(2,1,layer)=1-j;
      end
      
      
      
      temp=conv2(conv2(imageSmall(:,:,layer),tempJ(:,:,layer),'same'),    tempI(:,:,layer),'same');
         ncc=sum(temp(:).*b(:))/(norm(temp(:))*norm(b(:))); 
        
         if(ncc>nccMax)
             nccMax=ncc;
             sPixI (:,:,layer)=tempI(:,:,layer);
             sPixJ (:,:,layer)=tempJ(:,:,layer);
          end
     end       
 end
    
   
  end

 
 
 
end

