%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Author: Roland Miezianko (rmiezian@astro.temple.edu)
% Date: Spring 2003
% Instructor: Dr.Longin Jan Latecki
% Course: CIS 750
% Project : Assignment 2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Compute the pixel based distance value for a set of bmp images
% Input params: bmp image prefix and total number of frames
% The bmp image filename will be constructed here Prefix_X

function [PixDiffVals] = GetPixelDiff(imageFileNamePrefix, TotalNumFrames)

% init the output params
PixDiffVals = [];

% read first frame, convert to gray scale
fileName = strcat( imageFileNamePrefix, num2str(1), '.bmp' );
im = imread(fileName);
imd1 = rgb2gray(im);
%[n1, xnum1] = imhist(imd);

% process frames 2 to TotalNumFrames
for i = 2 : TotalNumFrames
    
    % generate filename based on the prefix and frame number
	fileName = strcat( imageFileNamePrefix, num2str(i), '.bmp' );
    % read the rgb file
	im = imread(fileName);
    % conver the rgb image to gray lavel image
	imd2 = rgb2gray(im);
    % compute the histogram of this frame    
	% [n2, xnum2] = imhist(imd);
    
    % compute the dissimilarity value between this and prevoius frames
    var = (double(imd2)-double(imd1)).*(double(imd2)-double(imd1));
    var = sum(sum(var));
    d = sqrt(var);
    
    % store the histogram based dissimilarity values
    PixDiffVals = [PixDiffVals; i d];
    
    % make this frame the prevoius frame before moving forward
    imd1 = imd2;
end

return;
