function out = gammacon(val,whichway) %Convert rgb to luminance or vive versa using a gamma function %values taken on 12/12/2018 in lab 4 %String argument can be either 'rgb2lum' or 'lum2rgb' a = 3.4590; b = 128.492; g = 1.81; if strcmp('rgb2lum',whichway) out = a+b.*(val.^g); elseif strcmp('lum2rgb',whichway) out = exp(log((val-a)./b)./g); elseif strcmp('rgb2rgb',whichway) out = (a/b)+(val.^g); else disp('Invalid string input!') out = 0; return end return