gammacon.m 515 B

123456789101112131415161718192021222324
  1. function out = gammacon(val,whichway)
  2. %Convert rgb to luminance or vive versa using a gamma function
  3. %values taken on 12/12/2018 in lab 4
  4. %String argument can be either 'rgb2lum' or 'lum2rgb'
  5. a = 3.4590;
  6. b = 128.492;
  7. g = 1.81;
  8. if strcmp('rgb2lum',whichway)
  9. out = a+b.*(val.^g);
  10. elseif strcmp('lum2rgb',whichway)
  11. out = exp(log((val-a)./b)./g);
  12. elseif strcmp('rgb2rgb',whichway)
  13. out = (a/b)+(val.^g);
  14. else
  15. disp('Invalid string input!')
  16. out = 0;
  17. return
  18. end
  19. return