% gamma correction data from right projector in SN255 11 October 2006

% input to framebuffer
i = [0 50 100 150 200 255]
% output recorded by spot photometer
EV = [6.7 7.3 8.6 9.7 10.6 11.3]
% convert to a linear unit 
Lux = 2.5 * 2.^EV
% subtract off the ambient light
x = i(2:end)
y = Lux(2:end) - Lux(1)
% I don't care about Lux, but rather a mapping from min to max
y = 255 * y / max(y)
% fit a line to log(y) versus log(x)
% y = k*x.^g so log(y) = log(k) + g*log(x)
c = polyfit(log(x), log(y), 1)
g = c(1)
k = exp(c(2))
% plot original data and fit
figure; plot(x, y, 0:255, k*(0:255).^g)
% compute correction table
t = ((1/k)*(0:255)).^(1/g);
% scale so we can get to max intensity
t = 255 * t / max(t)
% plot the correction
figure; plot(0:255, t);

