function s=scoreb(x,y,mu,sigma,beta)
% bayes image scoring function

[m,n]=size(x);
s=zeros(m,n);

% add U(y|x)

% for the class 1's
s=s+sum(sum((1/(2*sigma^2))*((y-mu(2)).^2).*x));

% for the class 0's
s=s+sum(sum((1/(2*sigma^2))*((y-mu(1)).^2).*(1-x)));

% add U(x)
z=zeros(m+2,n+2);
z(2:m+1,2:n+1)=x;
x=z;

s=s+sum(sum(beta(1)*((x(2:end-1,2:end-1)-x(1:end-2,2:end-1)).^2)));
s=s+sum(sum(beta(2)*((x(2:end-1,2:end-1)-x(3:end,2:end-1)).^2)));
s=s+sum(sum(beta(3)*((x(2:end-1,2:end-1)-x(2:end-1,1:end-2)).^2)));
s=s+sum(sum(beta(4)*((x(2:end-1,2:end-1)-x(2:end-1,3:end)).^2)));
     s=sum(sum(s));
