色域映射--L,a,b的线性先后压缩

色域映射–l,a,b的线性先后压缩(matlab)

  1. 先对明度L的压缩
C=sqrt(PicA.^2+PicB.^2);
Pc = 1-sqrt(C./(C+5*10^5));
h = size(PicL,1);
w = size(PicL,2);
% 对L通道源色域大于目标色域5%和小于95%的部分不进行处理,对其余部分进行类似线性压缩进目标色域内
for i = 1:h
    for j = 1:w
        if PicL(i,j) >= 0.05*(Lrmax-Lrmin)+Lrmin && PicL(i,j) <= 0.95*(Lrmax-Lrmin)+Lrmin
            PicL(i,j) = PicL(i,j);
        elseif PicL(i,j) < 0.05*(Lrmax-Lrmin)+Lrmin
            PicL(i,j) = Lrmin + (PicL(i,j) - Lomin)/(0.05*(Lrmax-Lrmin)+Lrmin - Lomin)*0.05*(Lrmax-Lrmin);
        else
            PicL(i,j) = 0.95*(Lrmax-Lrmin)+Lrmin + (PicL(i,j) - (0.95*(Lrmax-Lrmin)+Lrmin))/(Lomax - (0.95*(Lrmax-Lrmin)+Lrmin))*0.05*(Lrmax-Lrmin);
        end
    end
end
%做与彩度有关的明度压缩,能够保持高彩度区域颜色的明度只做少量的压缩,消色区明度做线性压缩,使得图像符合人眼视觉特性
PicL = (1-Pc).*PicL+Pc.*(Lrmax-(max(PicL(:))-PicL)/(max(PicL(:))-min(PicL(:)))*(Lrmax-Lrmin));
  1. 再对彩度a、b的压缩
% % 若彩度小于目标边界的95%则不压缩,若大于95%则采用类似线性压缩的方式压缩彩度
C0=sqrt(MachineA.^2+MachineB.^2);
for i = 1:Height
    for j = 1:Width
        if C(i,j) <= 0.95*max(C0(:))
            C(i,j) = C(i,j);
        else
            C(i,j)=0.95*max(C0)+(C(i,j)-0.95*max(C0))*0.1.*max(C0)./(max(C(:))-0.95*max(C0));
            p = PicA(i,j)./PicB(i,j);
            %建立彩度和ab值的对应关系,求出ab(这里是xy)值
            syms x y;
            [x,y]=solve(x/y == p,x^2+y^2 == C(i,j)^2,x,y);
            %xy有正负,按照和源色域ab值的正负号来取xy正负号,并把xy值取整给ab值
            if PicA(i,j) >= 0
                x=x(x>=0);
            else
                x=x(x<0);
            end
            if PicB(i,j) >=0
                y=y(y>=0);
            else
                y=y(y<0);
            end
            PicA(i,j) = round(x);
            PicB(i,j) = round(y);
        end
    end
end

参考CIE推荐的SGCK和最小色差法

你可能感兴趣的:(matlab)