%test straight line fit against ground truth data

%function whatever(a,b) % slope and intercept
function whatever % takes zero arguments, gives zero arguments

load ground_truth_d1_response_function_data_consolidated.txt
Q=ground_truth_d1_response_functi(:,1);
f=ground_truth_d1_response_functi(:,2);

%if nargin~=2
  [a,b]=linefit(Q,f); % fit straight line, slope a, intercept b, to (x,y) pairs
%end%if

% sort so we can plot as a continuous function:
[Qsort, ind]=sort(Q);
Q=Qsort;
f=f(ind);

q=(cbrt(2)).^Q;

%f_fit = (q.^a./(q.^a+1)).^c; % ac model
%%f_fit = alpha + beta * q.^gamma;
f_fit = a*Q+b;
%%f_fit = 255*f_fit;
%%s=1; f_fit = min(255,f_fit*s); % no saturation for now

plot(Q,f,'+',Q,f_fit);
axis([min(Q),max(Q),0,255])
xlabel('Q (Quantity of light)','FontSize',20) % Q=log_cbrt{2}(q)
ylabel('f (response byte)','FontSize',20)
title('estimated camera response function with ground truth data','FontSize',14)
grid

figure % fit straight line to only some of the data points between -15 and -5
Q=Q(132:213);
f=f(132:213);
[a,b]=linefit(Q,f); % fit straight line, slope a, intercept b, to (x,y) pairs
f_fit = a*Q+b;
plot(Q,f,'+',Q,f_fit);
axis([min(Q),max(Q),0,255])
xlabel('Q (Quantity of light)','FontSize',20) % Q=log_cbrt{2}(q)
ylabel('f (response byte)','FontSize',20)
title('estimated camera response function with ground truth data','FontSize',14)
grid

