基于matlab的HSI转RGB代码
时间: 2023-12-21 21:04:20 浏览: 154
以下是基于Matlab的HSI转RGB的代码:
```matlab
function [R,G,B] = HSItoRGB(H,S,I)
H = H/360;
R = zeros(size(H));
G = zeros(size(H));
B = zeros(size(H));
% RG sector (0 <= H < 120)
idx = find((0 <= H) & (H < 2/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));
% BG sector (120 <= H < 240)
idx = find((2/3 <= H) & (H < 4/3));
R(idx) = I(idx).*(1-S(idx));
G(idx) = I(idx).*(1+(S(idx).*cos(H(idx)-2/3)./cos(pi/3-(H(idx)-2/3))));
B(idx) = 3*I(idx)-(R(idx)+G(idx));
% BR sector (240 <= H < 360)
idx = find((4/3 <= H) & (H <= 1));
G(idx) = I(idx).*(1-S(idx));
B(idx) = I(idx).*(1+(S(idx).*cos(H(idx)-4/3)./cos(pi/3-(H(idx)-4/3))));
R(idx) = 3*I(idx)-(G(idx)+B(idx));
% Scale to [0,1]
R = max(min(R,1),0);
G = max(min(G,1),0);
B = max(min(B,1),0);
end
```
其中,输入参数为 H、S、I,分别表示色调、饱和度和强度。输出参数为 R、G、B,分别表示转换后的红、绿、蓝颜色通道。
阅读全文