function e_im  =  ext_im( im, L )

L        =  2^L;
[h  w]   =  size(im);

if mod(h,L)==0
    e_im  =  im;
    return;
end

m1       =  L - mod(h, L);
m2       =  L - mod(w, L);

e_im     =  zeros(m1+h, m2+w);
e_im(1:h,1:w)  =  im;

e_im(h+1:h+m1, 1:w)  =  im(end-1:-1:end-m1, :);
e_im(1:h, w+1:w+m2)  =  im(:, end-1:-1:end-m2);

return;