HSV与HSI转换

本文详细介绍了RGB到HSV颜色空间转换的方法,并提供了具体的数学公式。同时对比了HSV和HSI的区别,探讨了在图像处理中如何正确计算并理解HSV各分量的含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

好像HSV和HSI还有点区别   
  下面这个应该是正确的,这是《Video   demistified》上的,权威的说法,呵呵   
  RGB-to-HSV   Conversion:   
  (R,G,B取值范围0--1)   
  M=max(R,G,B)       m=min(R,G,B)   
  r=(M-R)/(M-m)     g=(M-G)/(M-m)       b=(M-B)/(M-m)   
    
  V的计算(取值范围0--1):V=max(R,G,B)   
  S的计算(取值范围0--1):if   M=0   then   S=0   and   H=180度   
                                                    if   M!=0   then   S=(M-m)/M   
  H的计算(取值范围0--360度):if   R=M   then   H=60(b-g)   
                                                            if   G=M   then   H=60(2+r-b)   
                                                            if   B=M   then   H=60(4+g-r)   
                                                            if   H>=360   then   H=H-360   
                                                            if   H<0         then   H=H+360

#####################

根据冈萨雷斯的书:

rgb=im2double(I);%若一副rgb图像的数据类型变为double,则他的取值范围就是[0,1].

H的结果除以360°,色度可归一化为[0,1],  rgb已经是double,归一过了,那么S和I应该都是在[0,1]之间

但是我做出来H 和S 分量的均值都不在[0,1]区间。

请问是怎么回事。有人知道么。

###########################

M=sum(sum(I));

H1=sum(sum(H))/M;

S1=sum(sum(S))/M;

I1=sum(sum(hsiI))/M;

上面这段代码好像不需要,以下是我用过的程序:function hsi=rgb2hsi(rgb)

########################################3

%RGB2HSI Converts an RGB image to HSI

% HSI=RGB2HSI(rgb) converts an RGB image to HSI. The input image is

% assumed to be of size M-by-N-by-3, where the third dimension accounts

% for three image planes:red, green, and blue, in that order. If all RGB

% component images are equal, the HSI conversion is undefined. Ths input

% image can be of class double (with values in the rang[0,1]), uint8, or

% uint16.

% The output image, HSI, is of class double, where:

% hsi(:,:,1)= hue image normalized values to the range [0,1] by

% dividing all angle values by 2*pi.

% hsi(:,:,2)=saturation image, in the range [0,1].

% hsi(:,:,3)=intensity image, in the range [0,1].

%Extract the individual component images.

rgb=im2double(rgb);

r=rgb(:,:,1);

g=rgb(:,:,2);

b=rgb(:,:,3);

%Implement the conversion equations.

num=0.5*((r-g)+(r-b));

den=sqrt((r-g).^2+(r-b).*(g-b));

theta=acos(num./(den+eps));

H=theta;

H(b>g)=2*pi-H(b>g);

H=H/(2*pi);

num=min(min(r,g),b);

den=r+g+b;

den(den==0)=eps;

S=1-3.*num./den;

H(S==0)=0;

I=(r+g+b)/3;

%Combine all three results into an hsi image.

hsi=cat(3,H,S,I);

##############################3

感谢楼上兄弟。

M=sum(sum(I));

H1=sum(sum(H))/M;

S1=sum(sum(S))/M;

I1=sum(sum(hsiI))/M;

这些代码目的是我用来求HSI分量值的均值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值