function [courben2, E, t, Memoire_contour, Memoire_fill] = energie_k_lambda2(N, R, l, c, energie, step)

% On appelle les fonctions handles

ed = @edginess;
cons = @byaverage;
n = @norme;
moy = @moyenne;
meansq_r2 = @msd_relier2;
bds = @boundaries;
masart = @m_and_s_artefact;

dim_image = (l-1)*(c-1)
% On calcule pour chaque lambda la vrai mean square deviation
t = 0;
lbd_step = step;

for k = -7:lbd_step:-3
    decompte = -k-3
    t = t + 1;
    g(t) = 10^(k);
    % mais cette fois c'est msd_relier
    [msd,MC,C] = feval(meansq_r2, l, c, N, R, 10^(k));
    Memoire_contour(:,:,t) = MC;
    Memoire_fill(:,:,t) = C;
    z(t) = sum(sum(msd));
    x2(t) = sum(sum(MC));
end

% On etale tout sur n^2
    z_scale = zeros([1 t]);
        o = 1:t;
        z_scale(o) = z(o)*dim_image/max(z);
        
% On fait la somme des energies
    new_E(o) = z_scale(o) + x2(o);
    
% On s'interesse aux derivees de la somme et de la mean square deviation
gd = g(1:length(g)-1);
    df = diff(z_scale(o))./diff(o);
    df2 = diff(new_E(o))./diff(o);

% PLOT
if energie == 'on'
figure, courben2 = semilogx(g',z_scale','--k',g',new_E','k',gd',df2,'k',g',x2,'--k'),title('ENERGIE DE MUMFORD AND SHAH');
else courben2 = 0;
end
% Essayons de prendre la premiere gray_scale
% pour la derivee.
% On cherche les maximuns locaux
    local_max_df = imregionalmax(df2,4);
    
    for e = 1:t-1        
        E(1,e) = double(local_max_df(e));
        E(2,e) = g(e);
        E(3,e) = x2(e)/dim_image;
    end
    
A = E(3,:)'


