function Irot=rotation(I,theta)

// On déclare le cadre dans lequel s'effectue la rotation
    [m,n] = size(I); 
    xc = (n-1)/2 ; yc = (m-1)/2; 
    D = sqrt(m^2+n^2)/2; 
    MM = ceil(D-m/2); NN = ceil(D-n/2); 
    mm = m+2*MM; nn = n + 2*NN;   
    Irot = zeros(mm,nn); 
// On remplit la matrice Irot 
    for j=1:mm
        for k=1:nn
            x = - NN + k-1; y = - MM + j-1; 
            X = xc + cos(theta)*(x-xc)-sin(theta)*(y-yc); 
            Y = yc + sin(theta)*(x-xc)+ cos(theta)*(y-yc); 
            if max(X*(X-n+1),Y*(Y-(m-1))) > 0 then 
                Irot(j,k) = 0 ;     
            else
                t = X - floor(X); s = Y - floor(Y); 
                idXinf = floor(X)+1; idXsup = ceil(X)+1; 
                idYinf = floor(Y)+1; idYsup = ceil(Y)+1;  
                Iaux1=(1-t)*I(idYinf,idXinf)+t*I(idYinf,idXsup); 
                Iaux2=(1-t)*I(idYsup,idXinf)+t*I(idYsup,idXsup);
                Irot(j,k) = (1-s)*Iaux1 + s*Iaux2; 
            end
        end
    end    
endfunction
