Skip to content

Instantly share code, notes, and snippets.

@jordanwesthoff
Last active August 29, 2015 14:17
Show Gist options
  • Save jordanwesthoff/ceb3844a383f85c97e6a to your computer and use it in GitHub Desktop.
Save jordanwesthoff/ceb3844a383f85c97e6a to your computer and use it in GitHub Desktop.
MATLAB based Lift, Gamma, Gain LUT slope generator for 10-bit imaging
% Idiot proof snippet of code to generate a scale of 0-max 10 bit values in MATLAB.
col_1 = [0:1:1023];
Ten_bit_vals= [col_1 col_1];
display(Ten_bit_vals)
% MATLAB bumper script to run the dependency 'lift_gamma_gain.m'
% This script is used to emulate the mathematical effects of the
% lift, gamma and gain color correction method and the graphical
% effect it has on a 1D LUT for color correction. This script requires
% two dependencies, `lift_gamma_gain.m` and `10_bit_vals.txt`.
% 10_bit_vals.txt is simply a dual column text file with numbers
% ranged 0-1023 in each column.
% Jordan Westhoff, RIT 2014
figure;
lift = 0;
gamma = 1;
gain = 1;
lift_gamma_gain(lift,gamma, gain);
while 1:6
lgg = menu('Modify LIFT, GAMMA or GAIN', 'Increase Lift', 'Decrease Lift',...
'Increase Gamma', 'Decrease Gamma', 'Increase Gain', 'Decrease Gain', 'Terminate');
if lgg == 1;
lift = lift+10;
close
figure;
lift_gamma_gain(lift,gamma, gain);
end
if lgg == 2;
lift = lift-10;
close
figure;
lift_gamma_gain(lift,gamma, gain);
end
if lgg == 3;
gamma = (gamma+0.1);
close
figure;
lift_gamma_gain(lift,gamma, gain);
end
if lgg == 4;
gamma = (gamma-0.1);
close
figure;
lift_gamma_gain(lift,gamma, gain);
end
if lgg == 5;
gain = (gain+.02);
close
figure;
lift_gamma_gain(lift,gamma, gain);
end
if lgg == 6;
gain = (gain-.02);
close
figure;
lift_gamma_gain(lift,gamma, gain);
end
if lgg == 7
break
end
end
function lift_gamma_gain(lift, gamma, gain, scale)
% Jordan Westhoff, 2014
% USAGE
% Insert a variable 1 in the fourth place of the input
%
% This script is used to emulate the mathematical effects of the
% lift, gamma and gain color correction method and the graphical
% effect it has on a 1D LUT for color correction.
% TEST
% lift = 0
% gamma = 2.2
% gain = 1
% This is the calculator for lift, gamma, gain
% For lift, increment in values of 1
% For gamma, increment in values of .2
% For gain, increment in values of 1
% OUT = GAIN * (( IN ^ GAMMA) + OFFSET )
% can also be
% OUT = GAIN*((IN + LIFT)^GAMMA)
unity = load('10_bit_vals.txt');
in = (unity(:,2));
in = in / (max(in));
lift = lift / 1024;
gam_1 = (in .^ gamma);
gam_2 = (gam_1 + lift);
gam_3 = gain * gam_2;
OUT = gam_3;
if nargin == 3;
in = in;
OUT = OUT;
high = 1.00;
OUT(OUT>high) = high;
low = 0.00;
OUT(OUT<low) = low;
else nargin == 4;
in = in * 1024;
OUT = OUT * 1024;
high = 1024;
OUT(OUT>high) = high;
low = 0.00;
OUT(OUT<low) = low;
end
plot(in, in, 'b-');
hold on;
plot(in, OUT, 'r-');
title('Lift, Gamma, Gain - Primary Color Correcter');
legend('Unity LUT', 'Corrected LUT');
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment