function[xa,ya,xb,yb]=multiScaleAlign(ref,a,b,maxLag,scaleMax)
xa=0;
ya=0;
xb=0;
yb=0;
imMAX=400;

for idx=scaleMax:-1:1
    factor=1/(2.^idx);
    
 
    
    
        REF=imresize(ref,factor,'bilinear');
        A=imresize(a,factor,'bilinear');
        B=imresize(b,factor,'bilinear');
        
        if(idx~=scaleMax)
           [h ,w]=size(REF);
           h=floor(h/3);
           w=floor(w/3);
       
           if(h>imMAX && w>imMAX)
            lastH=h+imMAX;
               lastW=w+imMAX;
               
           else 
               lastH=h+h;
                 lastW=w+w;
           end   
          [A,B]=shiftImages(A,B,xa,ya,xb,yb);
          REF=REF(h: lastH,w:lastW);
          A=A(h:lastH,w:lastW);
          B=B(h:lastH,w:lastW);
%           figure, imshow(uint16(cat(3,REF,A,REF)));
           
        end
     [XA,YA,XB,YB]=alignImages(REF,A,B,maxLag);
     
     xa=(XA+xa)*2;
     ya=(YA+ya)*2;
     xb=(XB+xb)*2;
     yb=(YB+yb)*2;
     
     
     
     
end


end