% This function is used to read frame image of a video and calculate the
% distance function based on intensity histogram. It take the frame
% filename's prefix and the total framenumber as input parameter.

function [featureA] = getHistogramFeature(imageFileNamePrefix, frame_num)

featureA = [];
%   read first frame
fileName = strcat(imageFileNamePrefix,num2str(1),'.bmp');
imA = imread(fileName);
imA = double(imA);
[rowsA,colsA] = size(imA);

%imd = rgb2gray(im);
%[n1, xnum1] = imhist(imd);

for i = 2: frame_num
	fileName = strcat(imageFileNamePrefix,num2str(i),'.bmp');
	imB = imread(fileName);
    imB = double(imB);
    varR = (imB(:,:,1)-imA(:,:,1)).*(imB(:,:,1)-imA(:,:,1));
    varR = sum(sum(varR));
    varG = (imB(:,:,2)-imA(:,:,2)).*(imB(:,:,2)-imA(:,:,2));
    varG = sum(sum(varG));
    varB = (imB(:,:,3)-imA(:,:,3)).*(imB(:,:,3)-imA(:,:,3));
    varB = sum(sum(varB));
    d = sqrt(varR + varG + varB);
    featureA = [featureA; i d];
    imA = imB;
end

return;
