How to convert RGB to hsv?

6 ビュー (過去 30 日間)
Fredrick  Graham
Fredrick Graham 2019 年 6 月 16 日
編集済み: Fredrick Graham 2019 年 6 月 17 日
I have a RGB data with each size like R is 1 x 100 double. how can i convert these RGB to hsv. I find the formula for it from Wikipedia and it available at [here]:
I also found some materials that could answer my questions such as 1 but it is in another language than Matlab.

回答 (3 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 16 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 16 日
For one frame, you can check here, as you mentioned the reference (wiki), I have implmented the same from here
I assumed, you can find R,G,B
Defining hue in terms of RGB
hue_rgb=atan2(sqrt(3)*(G-B),R-G-B)

Walter Roberson
Walter Roberson 2019 年 6 月 16 日
for H = 1:ncols
if T3(H) == 0
hprime(H) = 0;
elseif T1(H) == R(H)
hprime(H) = mod((G(H)-B(H))/C(H), 6);
elseif T1(H) == G(H)
hprime(H) = ((B(H)-R(H))/C(H))+2;
elseif T1(H) == B(H)
hprime(H) = ((R(H)-G(H))/C(H))+4;
else
error('undefined hue at index %d', H);
end
end
  6 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 16 日
What difficulty did you run into with the code that I had already posted to take care of the issue?
T1 = max([R; G; B]);
Fredrick  Graham
Fredrick Graham 2019 年 6 月 16 日
Thanks

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


Image Analyst
Image Analyst 2019 年 6 月 16 日
Why not simply use the built-in rgb2hsv() function:
% load R and G and B data
clear
close all
clc
load('RGB.mat')
subplot(4,1,1)
plot(t,R,'r')
ylim([110, 160]);
xlabel('Time (sec)')
ylabel('Red')
grid on;
subplot(4,1,2)
plot(t,G,'g')
ylim([110, 160]);
xlabel('Time (sec)')
ylabel('Green')
grid on;
subplot(4,1,3)
plot(t,B,'b')
ylim([110, 160]);
xlabel('Time (sec)')
ylabel('Blue')
grid on;
% Convert RGB to HSV:
RGBMatrix = [R; G; B];
% Make MxNx3 array rather than a Mx3 array (where rgb2hsv will think it's a colormap rather than a list of RGB values).
RGBMatrix = repmat(RGBMatrix, [1, 1, 2]);
RGBMatrix = permute(RGBMatrix, [3, 2, 1]);
hsvVec = rgb2hsv(RGBMatrix);
hueVector = hsvVec(1, :, 1);
subplot(4,1,4)
plot(t,hueVector,'b')
xlabel('Time (sec)')
ylabel('Hue')
grid on;

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by