function [disc] = discrepancy_image_1d(data,params)
% AVERAGE_SMOOTH: Calculates, reshapes and blurs discrepancy
% image.
%
% Code written by Katherine Smith (or maybe Stephen), 2003
%
%    GENERAL
%
%      discrepancy_image_1d(data,params)
%
%    INPUT/S
%
%      -data:
%           Input images.
%
%      -params:
%           The parameters describing the transformations.
%
%           
%    OUTPUT/S
%
%      -disc:
%           Discrepancy image.
%
%    PENDING WORK
%
%      -Add a few more comments to this file.
%      -Find out what each parameters does (see INPUT/S)
%
%    KNOWN BUG/S
%
%      -
%
%    COMMENT/S
%
%      -This function needs to be understood better.
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 25th, 2003
%      -Revision:    0.0.2
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

if(isfield(data,'q0'))
	nknots = size(data.q0,2);
	whichvar = [1:nknots];
	whichfix = [];
	[dummy, prob_im] = eval_nrr_objective_function(data.q1,[],whichvar,whichfix,data.q0(1,:),data.q0(2,:),data,params);
else
	[dummy, prob_im] = eval_nrr_objective_function([],[],[],[],[],[],data,params);
end

% Reshape prob_im
disc = zeros(size(data.ref_image));
disc((data.roi==1)) = prob_im(:);

% Blur
if(isfield(params,'blur'))
	h = ones(round(params.blur));
	disc = filter2(h,disc);
end

% Normalise the image
disc = disc - min(disc(:));
disc = disc/max(disc(:));
