function rho=LSS(B12,sRGB) % This is the Least Slope Squared (LSS) algorithm for generating % a "reasonable" reflectance curve from a given sRGB color triplet. % The reflectance spans the wavelength range 380-730 nm in 10 nm increments. % It solves min sum(rho_i+1 - rho_i)^2 s.t. T rho = rgb, % using Lagrangian approach. % B12 is upper-right 36x3 part of inv([D,T';T,zeros(3)]) % sRGB is a three-element vector of target D65-referenced sRGB values in 0-255 range, % rho is a 36x1 vector of reflectance values over wavelengths 380-730 nm, % Written by Scott Allen Burns, 4/25/15. % Licensed under a Creative Commons Attribution-ShareAlike 4.0 International % License (http://creativecommons.org/licenses/by-sa/4.0/). % For more information, see http://www.scottburns.us/subtractive-color-mixture/ % compute target linear rgb values sRGB=sRGB(:)/255; % convert to 0-1 column vector rgb=zeros(3,1); % remove gamma correction to get linear rgb for i=1:3 if sRGB(i)<0.04045 rgb(i)=sRGB(i)/12.92; else rgb(i)=((sRGB(i)+0.055)/1.055)^2.4; end end % matrix multiply rho=B12*rgb;