原创
RGB转为HSI的MATLAB程序 rgb2hsi
2011-6-16 14:52
11573
6
6
分类:
处理器与DSP
从数字图像处理(matlab)上直接COPY下来的。
function hsi = rgb2hsi(rgb)
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;
%combin all three results into an hsi image
hsi = cat(3,H,S,I);
文章评论(0条评论)
登录后参与讨论