python版本:

def srgb2lrgb(I0):
    gamma = ((I0 + 0.055) / 1.055)**2.4
    scale = I0 / 12.92
    return np.where (I0 > 0.04045, gamma, scale)
def lrgb2srgb(I1):
    gamma =  1.055*I1**(1/2.4)-0.055
    scale = I1 * 12.92
    return np.where (I1 > 0.0031308, gamma, scale)

matlab版本:


function I = srgb2lrgb(I0)
    I = ((I0+0.055)/1.055).^(2.4);  
    I(I0<=0.04045) = I0(I0<=0.04045)/12.92;
end

function I2 = lrgb2srgb(I1)
    I2 = zeros(size(I1));
    for k = 1:3
        temp = I1(:,:,k);
        I2(:,:,k) = 12.92*temp.*(temp<=0.0031308)+(1.055*temp.^(1/2.4)-0.055).*(temp>0.0031308);
    end
end