PS 图像调整算法——饱和度调整

算法参考自 阿发伯 的博客.

http://blog.csdn.net/maozefa


饱和度调整

图像的饱和度调整有很多方法,最简单的就是判断每个象素的R、G、B值是否大于或小于128,大于加上调整值,小于则减去调整值;也可将象素RGB转换为HSV或者HSL,然后调整其S部分,从而达到线性调整图象饱和度的目的。这几种方法我都测试过,效果均不太好,简单的就不说了,利用HSV和HSL调整饱和度,其调节范围很窄,饱和度没达到,难看的色斑却出现了。而Photoshop的饱和度调整调节范围大多了,效果也好多了。

Photoshop的色相/饱和度的调整还是转换为HSL颜色模式进行的,只是饱和度的增减调节却是“独立”于SHL模式的另外一套算法,如果不是需要HSL的S和L部分进行饱和度的上下限控制,它也和明度调整一样,可以独立进行!

%%%% Increment, 饱和度调整增量(-100,100)

Increment=-20/100;

rgbMax=max(R,G,B);

rgbMin=min(R,G,B);

Delta=(rgbMax-rgbMin)/255;

if(Delta==0)

    continue;

end

value=(rgbMax + rgbMin)/255;

L=value/2;

if(L<0.5)

     S=Delta/value;

else

     S =Delta/(2 - value);

end

 if (Increment>=0)     //如果饱和度增量大于0

      if((Increment+S)>=1)

          alpha=S;

      else

          alpha=1-Increment;

      end

      alpha=1/alpha-1;

      R_new = R+(R- L * 255) * alpha;

      G_new =G+(G - L * 255) *alpha;

      B_new = B+(B - L * 255) *alpha;

 else     // 饱和度增量小于0

      alpha=Increment;

      R_new = L*255 + (R- L * 255) *(1+alpha);

      G_new = L*255 +(G- L * 255) * (1+alpha);

      B_new = L*255 +(B- L * 255) * (1+alpha);

 end


Program:

%%%  程序实现图像的饱和度调整

clc;
clear all;
close all;
Image=imread('4.jpg');
Image=double(Image);
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
I=0.299*R+0.587*G+0.114*B;
[row, col] = size(R);
R_new=R;
G_new=G;
B_new=B;
%%%% Increment, 饱和度调整增量(-100,100)
Increment=50/100;

for i=1:row
    for j=1:col
        rgbMax=max(R(i,j),max(G(i,j),B(i,j)));
        rgbMin=min(R(i,j),min(G(i,j),B(i,j)));
        Delta=(rgbMax-rgbMin)/255;
        if(Delta==0)
            continue;
        end
        value = (rgbMax + rgbMin)/255;
        L=value/2;
        
        if(L<0.5)
            S=Delta/value;
        else
            S =Delta/(2 - value);
        end
        
        if (Increment>=0)
            if((Increment+S)>=1)
                alpha=S;
            else
                alpha=1-Increment;
            end
          alpha=1/alpha-1;
          R_new(i,j) = R(i,j) + (R(i,j) - L * 255) * alpha;
          G_new(i,j) = G(i,j) + (G(i,j) - L * 255) * alpha;
          B_new(i,j) = B(i,j) + (B(i,j) - L * 255) * alpha;
        else
          alpha=Increment;
          R_new(i,j) = L*255 + (R(i,j) - L * 255) * (1+alpha);
          G_new(i,j) = L*255 + (G(i,j) - L * 255) * (1+alpha);
          B_new(i,j) = L*255 + (B(i,j) - L * 255) * (1+alpha); 
        end
    end
end     
Image_new(:,:,1)=R_new;
Image_new(:,:,2)=G_new;
Image_new(:,:,3)=B_new;
imshow(Image/255);
figure, imshow(Image_new/255);
        

原图:


        

效果图:饱和度增加 50%



  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值