function [dist,errormap] = SimpleMetric(im1,im2)
% (c) ZHANG Fan, CUHK, Jan. 21, 2010 

im1 = imread(im1);
im2 = imread(im2);

if ndims(im1) == 3
    im1 = rgb2gray(im1);
    im2 = rgb2gray(im2);
end

im1 = single(im1);
im2 = single(im2);
[row,col,channel] = size(im1);
blocksize = 5;
nsizeh = (blocksize-1)/2;

row = floor(row/blocksize)*blocksize; col = floor(col/blocksize)*blocksize;
im1 = im1(1:row,1:col,:); im2 = im2(1:row,1:col,:);

%% Calculating the blocking index, sI
% you can put the calculation of sI out of the function
sCI = 0:row*blocksize:(col/blocksize-1)*row*blocksize;
sRI = 0:blocksize:(row/blocksize-1)*blocksize;
[sCI,sRI] = meshgrid(sCI,sRI);
centerind = sCI + sRI + nsizeh*row+nsizeh + 1;
bo = BlockOffset(row,blocksize);
[sCI,sRI] = meshgrid(centerind(:),bo(:));
sI = uint32(sCI + sRI);
%clear sCI; clear sRI;
%%

X = im1(sI);
stdX = std(X);
x = mean(X);

X2 = im2(sI);
x2 = mean(X2);
[rr,cc] = size(centerind);
errormap = zeros(rr,cc);

y = 1./(stdX+20);
errormap(:) = (x - x2).^2.*y;
dist = sum(errormap(:))/(numel(errormap)) * var(x)/var(X(:));




