% plotf.m
%
% loads response function from picture of test chart and plots it
%
% plots   [black and 11 step greyvalues] 

ff=[]; % accumulate the f values
for k = 100:118
%%%k=117; % frame number
% k=116 returns last f value closer than 3 sigma to 255, so may be distorted
% k=115 seems to be brightest image that's not at risk of distortion
%function plotf(k)
if ((k<100) | (k>118))
  error('must load one of frame 100 to 118')
end%if

f=loadf(k);

q0=.011; % true black
% true black then 11 values of steps:
q=[.011; .021; .048; .079; .126; .185; .264; .358; .472; .622; .733; .893];

%%subplot(211)
%%plot(q,f);
Q=log(q);
Q=log(q)/log(2);
%%subplot(212)
%%plot(Q,f);
ff=[ff f];

end %for k = 100:118

QQ=Q*ones(1,19)+ones(12,1)*(0:18);
Q=log(q)/log(cbrt(2));plot(Q,ff);

% plot them individually:
plot(Q,ff,'o',Q,ff)
axis([-19,0,0,255])   
xlabel('Q (Quantity of light)') % Q=log_cbrt{2}(q)
ylabel('f (response byte)')
title('Ground truths (measured camera response functions)')
print ground_truths_d1_response_functions.eps

% now plot them all lined up:
%Q=log(q)/log(1.2599);plot(Q*ones(1,19)+ones(12,1)*(-18:0),ff)
% even better if we do:
%Q=log(q)/log(1.27);plot(Q*ones(1,19)+ones(12,1)*(-18:0),ff)
% so maybe exposures are a little bit off

%Q=log(q)/log(1.27);plot(Q*ones(1,19)+ones(12,1)*(-18:0),ff,'o')
Q=log(q)/log(1.26);plot(Q*ones(1,19)+ones(12,1)*(-18:0),ff,'o')
axis([-19-18,0,0,255])                                     
xlabel('Q (Quantity of light)') % Q=log_cbrt{2}(q)
ylabel('f (response byte)')  
title('Ground truth (measured camera response function)')
grid
print ground_truth_d1_response_function.eps

% consolidate the data into a single plot
% as (x,y) ordered pairs
x=reshape(Q*ones(1,19)+ones(12,1)*(-18:0),12*19,1);
y=reshape(ff,12*19,1);
% sort so we can plot as a continuous function:
[xsort, ind]=sort(x);
plot(xsort,y(ind));
axis([-19-18,0,0,255])
xlabel('Q (Quantity of light)') % Q=log_cbrt{2}(q)
ylabel('f (response byte)')
title('Ground truth (measured camera response function)')
grid
print ground_truth_d1_response_function_continuous.eps

