function [E,Edata,Ereg]=Energy_Total(f,r,c,sigma,RegTerm,u)
K=size(r,3);
[M N]=size(f);
C=repmat(c,[M N 1]);
SIGMA=repmat(sigma,[M N 1])+eps;
R=repmat(r,[M N 1])+eps;
F=repmat(f,[1 1 K]);
E1=((F-C).^2./(2*SIGMA)-log(R)+log(sqrt(SIGMA))+log(u+eps)).*u;
E2=RegTerm.*u;
Edata=sum(E1(:));
Ereg=sum(E2(:));
E=Edata+Ereg;