Photoshop入门学习之色彩转换——RGB & HSI
小标 2018-11-15 来源 : 阅读 3369 评论 0

摘要:本文主要向大家介绍了Photoshop入门学习之色彩转换——RGB & HSI,通过具体的内容向大家展现,希望对大家Photoshop入门学习有所帮助。

本文主要向大家介绍了Photoshop入门学习之色彩转换——RGB & HSI,通过具体的内容向大家展现,希望对大家Photoshop入门学习有所帮助。

<

RGB to HSI

I=(R+G+B)/3;

S=1-3*min(R,G,B)/(R+G+B);

H = cos^(-1)((0.5*((R-G)+(R-B))) / ((R-G)^2 + (R-B)*(G-B))^(0.5))

If S = 0; H =0 ;

If B > G; H=360-H;



HSI to RGB

If  0  <  H <= 120 then 
    B = 1/3(1-S)
    R = 1/3(1+ ((S cos H) / (cos(60 -H))))
    G = 1 -(B+R)
If 120 < H <= 240 then
    H = H  – 120
    R = 1/3(1-S)
    G = 1/3(1+ ((S cos H) / (cos(60 -H))))
    B = 1 -(R+G)
If 240 < H <=360 then
    H = H  – 240
    G = 1/3(1-S)
    B = 1/3(1+ ((S cos H) / (cos(60 -H))))
    R = 1 -(G+B)



算法参考来源: 冈萨雷斯 《数字图像处理》



function  [H,S,I]=RgbToHsi(Image_Input)

Image_Input=double(Image_Input)/255;
R_Input=Image_Input(:,:,1);
G_Input=Image_Input(:,:,2);
B_Input=Image_Input(:,:,3);
I = (R_Input+G_Input+B_Input)/3.0;

[heigth,width]=size(R_Input);
S(1:heigth,1:width)=0;
H(1:heigth,1:width)=0;

for i=1:heigth
    for j=1:width
        temp=[R_Input(i,j),G_Input(i,j),B_Input(i,j)];
        S(i,j)=1-3*min(temp)/sum(temp);
        X=R_Input(i,j);
        Y=G_Input(i,j);
        Z=B_Input(i,j);
        temp_1=((X-Y)+(X-Z)+1e-6)/(2*sqrt((X-Y).^2+(X-Z)*(Y-Z))+1e-6);
        Sigma=acos(temp_1);
        if(Z<=Y)
            H(i,j)=Sigma/(2*pi);
        else
            H(i,j)=(2*pi-Sigma)/(2*pi);
        end
    end
end



function Image_out=HsiToRgb(H,S,I)

H_angle=H*360;
[heigth,width]=size(H);
R(1:heigth,1:width)=0;
G(1:heigth,1:width)=0;
B(1:heigth,1:width)=0;

for i=1:heigth
    for j=1:width
        if(S(i,j)<1e-6)
            R(i,j)=I(i,j);
            G(i,j)=I(i,j);
            B(i,j)=I(i,j);
        else
            if(H_angle(i,j)>=0 && H_angle(i,j)<=120)
                B(i,j)=(1-S(i,j))*I(i,j);
                sigma=(H_angle(i,j)-60)*pi/180;
                temp=tan(sigma)/sqrt(3);
                G(i,j)=(1.5+1.5*temp)*I(i,j)-(0.5+1.5*temp)*B(i,j);
                R(i,j)=3*I(i,j)-G(i,j)-B(i,j);
            else
                if(H_angle(i,j)>=120 && H_angle(i,j)<=240)
                    R(i,j)=(1-S(i,j))*I(i,j);
                    sigma=(H_angle(i,j)-180)*pi/180;
                    temp=tan(sigma)/sqrt(3);
                    B(i,j)=(1.5+1.5*temp)*I(i,j)-(0.5+1.5*temp)*R(i,j);
                    G(i,j)=3*I(i,j)-R(i,j)-B(i,j);
                else
                    G(i,j)=(1-S(i,j))*I(i,j);
                    sigma=(H_angle(i,j)-300)*pi/180;
                    temp=(tan(sigma))/sqrt(3);
                    R(i,j)=(1.5+1.5*temp)*I(i,j)-(0.5+1.5*temp)*G(i,j);
                    B(i,j)=3*I(i,j)-R(i,j)-G(i,j);
                end
            end
        end
    end
end

Image_out(:,:,1)=R;
Image_out(:,:,2)=G;
Image_out(:,:,3)=B;    

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注常用软件Photoshop频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程