function im1=xsubpix_shift(im,Xj,Xi),

Xj=-Xj;
Xi=-Xi;

I=floor(Xi);
J=floor(Xj);

xi = Xi - I;
xj = Xj - J;


for ki=1:size(im,1),
    for kj=1:size(im,2),
        if (ki+I>1) && (ki+I+1<size(im,1)) && (kj+J>1) && (kj+J+1<size(im,2)),
            im1(ki,kj) = (1-xi)*(1-xj)*im(ki+I,  kj+J)   + ...
                         xi*(1-xj)*    im(ki+I+1,kj+J)   + ...
                         xj*(1-xi)*    im(ki+I,  kj+J+1) + ...
                         xi*xj*        im(ki+I+1,kj+J+1);
        else
            im1(ki,kj)=im(ki,kj);
        end
    end
end
         