% hsi22rgb_function
function yy  =hsi22rgb_fun(x)
%x=im2double(x);           
%We can isolate each colour component by the colon operator:
H=x(:,:,1); %  The H component
S=x(:,:,2); %The S component
I=x(:,:,3); % I
% hsi22rgb
H=H*2*pi;
R=zeros(size(x,1),size(x,2));
G=zeros(size(x,1),size(x,2));
B=zeros(size(x,1),size(x,2));
%
idx=find((0<=H) & (H<2*pi/3));
B(idx)=I(idx).*(1-S(idx));
R(idx)=I(idx).*(1+S(idx).*cos(H(idx))./cos(pi/3-H(idx)));
G(idx)=3*I(idx)-(R(idx)+B(idx));
%
idx=find((2*pi/3<=H) & (H<4*pi/3));H1=H-(2*pi/3);
R(idx)=I(idx).*(1-S(idx)); 
G(idx)=I(idx).*(1+S(idx).*cos(H1(idx))./cos(pi/3-H1(idx)));
B(idx)=3*I(idx)-(R(idx)+G(idx));
%
idx=find((4*pi/3<=H) & (H<=2*pi));H2=H-(4*pi/3);
G(idx)=I(idx).*(1-S(idx));
B(idx)=I(idx).*(1+S(idx).*cos(H2(idx))./cos(pi/3-H2(idx)));
R(idx)=3*I(idx)-(G(idx)+B(idx));
%
rgb=cat(3,R,G,B);
yy=max(min(rgb,1),0);
