How to code this formula?

3 ビュー (過去 30 日間)
Alvin Alvin
Alvin Alvin 2019 年 12 月 5 日
コメント済み: Walter Roberson 2019 年 12 月 5 日
code.PNG
Please help me to convert from HSV to RGB with this equation
  8 件のコメント
Alvin Alvin
Alvin Alvin 2019 年 12 月 5 日
can't use logical indexing to code the R' G' B' in vectorized form and Can't use a for loop with if and elseif too
Walter Roberson
Walter Roberson 2019 年 12 月 5 日
Rp = zeros(size(H));
Gp = zeros(size(H));
Bp = zeros(size(H));
for K = 1 : numel(H)
if H(K) < 60
Rp(K) = C(K);
Gp(K) = X(K);
Bp(K) = 0;
elseif H(K) < 120
Rp(K) = X(K);
Gp(K) = C(K);
Bp(K) = 0;
elseif
and so on
end
end
What prevents you from using a for loop with if and elseif ?

サインインしてコメントする。

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 12 月 5 日
function rgb = HSVtoRGB(H,S,V)
n = numel(H);
C = V.*S;
X = C .* (1 - abs(mod(H/60,2) - 1));
A = [C, X, zeros(n,1)];
i = discretize(H,0:60:360);
j = perms(1:3);
j = j([6,4,2,1,3,5],:);
r = repmat((1:n)',1,3);
rgbs = A(sub2ind([n,3],r,j(i,:)));
rgb = 255*(rgbs + V - C);
end

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by