function markov = Untitled( I)

    I= zeros(5,5);
    I1= ones(5,5);
   I(2,2) =1;
   res= voisinages(2);
   markov= energieInv(I,I1) ;
end

function res= energie(I,I1, vec)
    %I => image, I1=> image à l'instant t+1 vec=> tableau des vecteurs
    %deplacements supposés.
    vec= energieReg(vec,0.5);
    E= energieInv(I,I1);


end
function res= energieReg(vec, beta)
    [X Y]=size(I);
    res= zeros(X,Y);
    voisins= voisinages(2);
    for i=2:X-1  
        for j=2:Y-1
            for k=1:9
               res(i,j)=res(i,j)+energenergieRegP(vec(i,j) ,vec(i+voisins(1,k),j +voisins(2,k) ));
            end
            res(i,j)=res(i,j)*beta;
        end
    end
end

function res= energieInv(I,I1)
    
    [X Y]=size(I);
    res= zeros(X,Y);
    %on créé la liste des vecteurs de voisinage
    voisins= voisinages(2);
    for i=2:X-1
        for j=2:Y-1
            for k=1:9
               res(i,j)=res(i,j)+energieInvP(I,I1,voisins(:,k), i, j);
            end
       end
    end
end

function res= energieInvP(I,I1,w, i, j)
    %inveriance de la luminance
    res=  (I(i,j) - I1(i+w(1),j+w(2)))^2;
         
end
function res= energieRegP(vec1,vec2)
    %régularité des vecteurs
    vec=  vec1-vec2; 
    res= (  (vec(1)+vec(1))^2 + (vec(2)+vec(2))^2   );     
end

function res= voisinages(n)

    res= zeros(2,9);
    
    for i=1:9
       res(:,i)= voisinage(1,i); 
    end
    
end


function res= voisinage(n,dir)

     vec=[0 0];
    if(dir==1)
        vec= [-1,1];
    elseif(dir==2)
        vec= [0,1];
    elseif(dir==3)
        vec= [1,1];        
    elseif(dir==4)
        vec= [-1,0];           
    elseif(dir==5)
        vec= [0,0];                
    elseif(dir==6)
        vec= [1,0];                    
    elseif(dir==7)
        vec= [-1,-1];                        
    elseif(dir==8)
        vec= [0,-1];                            
    elseif(dir==9)
        vec= [1,-1];
    end
    res= vec* n;
end


function couple = manhattan(I, x, y, d)
    couple=[[x y+d]; [x y-d]];
    for i=1:d
       couple=[couple; [x+i y+d-i]; [x-i y+d-i]; [x+i y-d+i]; [x-i y-d+i]];
    end
end

function I=Pyramide(I, L)
    L=L-1;
    I=imresize(I,(2^(-L)));
    imshow(I);
end

function recuit_par_paliers(T0, alpha, x0, r, U, y)
    T=T0;
    cpt=r;
    x=x0;
    while cpt>=r
        cpt=0;
        T=T*alpha;
        while n<N
            n=n+1;
            L=xsn;
            x=Gibbs(sn, x, U(x,y),T)
            if xsn ~= L
                cpt=cpt+1;
            end
        end
        n=N+1;
        while n>1
            n=n-1;
            L=xsn;
            x=Gibbs(sn, x, U(x,y), T);
            if(xsn ~= L)
                cpt=cpt+1;
            end
        end
    end
end

function ICM(x0, r, U, y)
    cpt=r;
    x=x0;
    while cpt>r
        cpt=0;
        n=0;
        while n<N
            n=n+1;
            L=xsn;
            x=Gibbs_Gele(Sn, x, U(:,y));
            if x~=L
                cpt=cpt+1;
            end
        end
        n=N+1;
        while n>1
            n=n-1;
            L=xsn;
            x=Gibbs_Gele(Sn, x, U(:,y));
            if x ~= L
               cpt=cpt+1;
            end
        end
    end
end

function x=Gibbs_Gele(s, x, U)
    i=0;
    i0=1;
    while i<abs(D)
        i=i+1;
        xsn=min(L);
        if i==1
            Um=min(U);
        end
        if min(U)<Um
            Um=min(U);
            i0=i;
        end
    end
    xs=Li0;
end


function multiresolution(n, x0n, ri, Ui, i, y, H)
    i=0;
    while i<n
        y(i)=[z*oH]*y(i-1);
    end
    i=n+1;
    while i>0
        i=i-1;
        if i==n
            x(i)=x0n;
        else x(i)=D(i+1);
        end
        x(i)=ICM(x(i), ri, Ui, yi);
    end
end